From 82caecade1915f66bc0fe9518fbae32b324c8f81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=AF=86=E7=A0=81=E6=BC=8F=E6=B4=9E?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=8C=E6=88=90?= <> Date: Sat, 9 Aug 2025 14:24:13 +0800 Subject: [PATCH] first commit --- wifi-mqtt/dht-blinker.ino | 60 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 wifi-mqtt/dht-blinker.ino diff --git a/wifi-mqtt/dht-blinker.ino b/wifi-mqtt/dht-blinker.ino new file mode 100644 index 0000000..0dbf7fb --- /dev/null +++ b/wifi-mqtt/dht-blinker.ino @@ -0,0 +1,60 @@ +#define BLINKER_WIFI + +#include +#include + +char auth[] = "ecdc2388f56f"; +char ssid[] = "CMCC-AAA"; +char pswd[] = "123456789"; + +BlinkerNumber HUMI("humi"); +BlinkerNumber TEMP("temp"); + +#define DHTPIN D4 + +#define DHTTYPE DHT11 // DHT 11 + +DHT dht(DHTPIN, DHTTYPE); + +float humi_read = 0, temp_read = 0; + +void heartbeat() +{ + HUMI.print(humi_read); + TEMP.print(temp_read); +} + +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.attachHeartbeat(heartbeat); + 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; + } + + Blinker.delay(2000); +}