📜 ⬆️ ⬇️

Monitoring the temperature in the server using Arduino

The weekend at the end of May in Yekaterinburg marked the beginning of summer, and on Monday we were greeted by a 39-degree heat in a small room with two server racks. The reason is trivial - one of the air conditioners refused, from old age. It cost a little blood and almost none of the 250 employees felt the problems.
I wanted to somehow, if not control the situation, then at least monitor it. The option to purchase a ready-made device slowed down, and then canceled its price. But I remembered the magic word Arduino, if I’m wondering what happened, I ask for a cat.

Arduino Uno, and two Shield (ethernet and keypad) gathered in a three-layer cake:
image

The ds18b20 temperature sensor is soldered to the top right of the keypad shield, in order to plant the upper shield it was necessary to slightly increase its legs, soldering the connector that came in combination with the Arduino.
image

And very well this business fit into the adjustable box from the hardware store
image
')
In PHP, a script was written for accepting GET queries and writing data to SQL.

Once a minute sends a request to the server, it looks like this:


As the field tests showed, the sensor needs to be carried out of the case, otherwise it will overestimate the temperature by about 5 degrees, but it is possible to take the error into account programmatically.

View Sketch
#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/394909/


All Articles