使用Arduino监控服务器机房中的温度

5月下旬在叶卡捷琳堡的周末标志着夏天的开始,周一我们在一个带两个服务器机架的小房间里迎接了39度高温。原因很普遍-其中一台空调机拒绝老年。它花费很少的血液,并且250名员工中几乎没有人感到任何问题。
我想以某种方式,如果不处理这种情况,那么至少要对其进行监视。购买完工设备的选项变慢了,然后取消了价格。但是我想起了Arduino这个神奇的词,如果我想知道发生了什么事,我要一只猫。

Arduino uno和两个屏蔽层(以太网和键盘)聚集在一个三层的饼中:
图片

将ds18b20温度传感器从右上角焊接到键盘屏蔽层,为了放置上层屏蔽层,他必须稍微增加他的腿,焊接与arduino一起的梳状连接器。
图片

这项业务非常成功地从五金商店安装到接线盒中,
图片

用PHP编写了一个脚本来接受GET请求并将数据写入SQL。

一分钟后,将请求发送到服务器,如下所示:


如现场测试所示,必须将传感器从包装箱中取出,否则温度会升高约5度,但可以通过程序考虑该错误。

查看草图
#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/zh-CN394909/


All Articles