Monitorando a temperatura na sala do servidor usando o Arduino

O fim de semana no final de maio em Ecaterimburgo marcou o início do verão e, na segunda-feira, fomos recebidos com um calor de 39 graus em uma pequena sala com dois racks para servidores. O motivo é comum - um dos condicionadores de ar recusou a velhice. Custou pouco sangue e quase nenhum dos 250 funcionários sentiu algum problema.
Eu queria, de alguma forma, se não gerenciar a situação, pelo menos monitorá-la. A opção de comprar um dispositivo acabado diminuiu a velocidade e depois cancelou o preço. Mas lembrei-me da palavra mágica Arduino. Se me pergunto o que aconteceu, peço um gato.

Arduino uno e dois escudos (ethernet e teclado) reunidos em uma torta de três camadas:
imagem

o sensor de temperatura ds18b20 foi soldado da parte superior direita ao escudo do teclado; para colocar o escudo superior, ele teve que aumentar levemente as pernas, soldando o conector do pente que acompanha o arduino.
imagem

E com muito sucesso esse negócio se encaixou em uma caixa de ligação de uma loja de ferragens.Um
imagem

script foi escrito em PHP para aceitar solicitações GET e gravar dados no SQL.

Depois que um minuto envia uma solicitação ao servidor, fica assim:


Como os testes de campo mostraram, o sensor deve ser retirado da caixa; caso contrário, a temperatura aumenta cerca de 5 graus, mas é possível levar em consideração o erro programaticamente.

Exibir esboço
#include <SPI.h>
#include <Ethernet.h>
#include "LiquidCrystal_1602_RUS.h"
#include <EEPROM.h>
#include <avr/interrupt.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <avr/wdt.h>

LiquidCrystal_1602_RUS lcd(8, 9, 4, 5, 6, 7 );//For LCD Keypad Shield
OneWire ds(15); DallasTemperature sensors(&ds); float temp; 
String readString = String(300); 
String message;

int opros=0; int sends=0; int sendperiod=0; int dog=0;

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
char server[] = "test.domain.ru";    
IPAddress ip(10, 0, 0, 177);
EthernetClient client;

void setup() 
{
  lcd.begin(16, 2);

//    Timer2 
  TCCR2A = 0; 
  TCCR2B = 0<<CS22 | 1<<CS21 | 0<<CS20; 
  TIMSK2 = 1<<TOIE2; 
  sei();
  wdt_enable(WDTO_8S);  
}

ISR(TIMER2_OVF_vect) 
{
   opros++;

//          
    if(opros==7500) 
    {
      sensors.requestTemperatures();
      temp = sensors.getTempCByIndex(0);
       lcd.setCursor(0,0); lcd.print(message); 
       lcd.setCursor(0,1); if(60-sendperiod<10){lcd.print(0);} lcd.print(60-sendperiod);
       lcd.setCursor(9,1); lcd.print(temp);  lcd.print(L"°C");
      opros=0;

//       10             
     if(sends!=0){dog++;} else {dog=0;}
      if(dog<600){wdt_reset();}  
     
//       
      if (sends==0 && sendperiod==0){sends=1;}  
      sendperiod++; if(sendperiod==60){ sendperiod=0;}  
          
    }
   
}

void loop() 
{

//     
if (sends==1) 
{
  message="Connect         ";
  lcd.setCursor(0,0); lcd.print(L"Connect         ");
  sends=2; 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) 
  {
    ; // wait for serial port to connect. Needed for native USB port only
  }  
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // try to congifure using IP address instead of DHCP:
    Ethernet.begin(mac, ip);
  }
  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) 
    {
    Serial.println("connected");
    // Make a HTTP request:
    
    client.print("GET /info/temp.php?t=");
    client.print(temp);
    client.println(" HTTP/1.1");
    client.println("Host: test.domain.ru");
    client.println("Connection: close");
    client.println();
    } 
  else 
    {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
    }
  sends=3;
}  
  
//    
if(sends==3)
 { 
  if (client.available()) 
  {
    
    char c = client.read();
    Serial.print(c);
      if (c != '\n'){readString+= c;}
 }

//    
  if (!client.connected()) 
  {
    Serial.println();
    Serial.println("disconnecting.");
    if(readString.indexOf("z666")>0)
     {message="OK ";message+= readString.substring(readString.indexOf("z666")+5,readString.indexOf("z666")+19);}
     else {message="Send error";}
    readString="";
    client.stop();
    sends=0;
  } 
 }
}

Source: https://habr.com/ru/post/pt394909/


All Articles