远程温湿度监控,blinker远程监控,arduino源码- #define BLINKER_WIFI
-
- #include <Blinker.h>
- #include <DHT.h>
-
- char auth[] = "20ce32208396"; //上一步中在app中获取到的Secret Key(新建设备的秘钥)
- char ssid[] = "PIG"; //你的WiFi热点名称
- char pswd[] = "Zq128hw923"; //你的WiFi密码
-
- BlinkerNumber HUMI("humi");
- BlinkerNumber TEMP("temp");
- #define DHTPIN 5 //温湿度接的是GPIO5端口
- #define DHTTYPE DHT11 // DHT 11
- //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
- //#define DHTTYPE DHT21 // DHT 21 (AM2301)
-
- DHT dht(DHTPIN, DHTTYPE);
-
- float humi_read = 0, temp_read = 0;
-
- void heartbeat()
- {
- //反馈温度数据
- HUMI.print(humi_read);
- //设置ui组件图标和颜色
- HUMI.icon("fas fa-thermometer-2");
- HUMI.color("#fddb10");
- //反馈湿度数据
- TEMP.print(temp_read);
- TEMP.icon("fas fa-heart");
- HUMI.color("#fddb01");
- }
- void dataStorage()
- {
- Blinker.dataStorage("temp",temp_read);
- Blinker.dataStorage("humi",humi_read);
- }
-
- void setup()
- {
- Serial.begin(115200);
- pinMode(PIR_sensor,INPUT);
- BLINKER_DEBUG.stream(Serial);
- BLINKER_DEBUG.debugAll();
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
-
- Blinker.begin(auth, ssid, pswd);
- Blinker.attachHeartbeat(heartbeat);
- Blinker.attachDataStorage(dataStorage);
- dht.begin();
- }
-
- void loop()
- {
- Blinker.run();
- float h = dht.readHumidity();
- float t = dht.readTemperature();
-
- if (isnan(h) || isnan(t))
- {
- BLINKER_LOG("Failed to read from DHT sensor!");
- }
- else
- {
- BLINKER_LOG("Humidity: ", h, " %");
- BLINKER_LOG("Temperature: ", t, " *C");
- humi_read = h;
- temp_read = t;
- }
- if (t > 20)
- {
- Blinker.wechat("Title:机房温度","state:temperature high" ,"Message:机房温度过高");
- Blinker.sms("机房温度过高!");
- }
- Blinker.delay(2000);
- }
复制代码
|