有些情况下,我们需要查看即时数据,比如当前的加热温度。对于这种情况,可以使用 blinker 的“实时数据”功能。启用方法非常简单:在控件界面上勾选“实时数据”即可。
- #define BLINKER_WIFI
-
- #include <Blinker.h>
-
- char auth[] = "你的Key";
- char ssid[] = "你家WIFI名";
- char pswd[] = "你家WIFI密码";
-
- BlinkerNumber HUMI("humi");
- BlinkerNumber TEMP("temp");
-
-
- uint32_t read_time = 0;
-
- float Humidity=0, Temperature=0;
-
- void rtData()
- {
- Blinker.sendRtData("temp", Humidity);
- Blinker.sendRtData("humi", Temperature);
- Blinker.printRtData();
- }
-
- void setup()
- {
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- BLINKER_DEBUG.debugAll();
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
-
- Blinker.begin(auth, ssid, pswd);
- Blinker.attachRTData(rtData);
-
- }
-
- void loop()
- {
-
- Blinker.run();
-
- if (read_time == 0 || (millis() - read_time) >= 2000)
- {
- read_time = millis();
-
- BLINKER_LOG("Humidity: ", Humidity, " %");
- BLINKER_LOG("Temperature: ", Temperature, " *C");
-
- if (Temperature>50.0) {Temperature=0;} else {Temperature=Temperature+0.4;}
- if (Humidity>50.0) {Humidity=0;} else {Humidity=Humidity+0.9;}
- }
- }
复制代码
运行之后可以在 Blinker 上看到温湿度的实时变化:
|