You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
61 lines
1.1 KiB
Arduino
61 lines
1.1 KiB
Arduino
|
4 months ago
|
#define BLINKER_WIFI
|
||
|
|
|
||
|
|
#include <Blinker.h>
|
||
|
|
#include <DHT.h>
|
||
|
|
|
||
|
|
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);
|
||
|
|
}
|