#define BLINKER_WIFI #include <Blinker.h> char auth[] = "XXXXXXX"; char ssid[] = "XXXXXXX"; char pswd[] = "XXXXX"; BlinkerNumber HUMI("humi"); BlinkerNumber TEMP("temp"); BlinkerNumber HEAT("heat"); BlinkerNumber Kong("kong"); // Download Adafruit DHT-sensor-library library here: // https://github.com/adafruit/DHT-sensor-library #include <DHT.h> #define DHTPIN 2 int kong = A0; #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); uint32_t read_time = 0; float humi_read, temp_read, heat_read, kong_read; void dataRead(const String & data) { BLINKER_LOG("Blinker readString: ", data); Blinker.vibrate(); uint32_t BlinkerTime = millis(); Blinker.print(BlinkerTime); Blinker.print("millis", BlinkerTime); } void heartbeat() { HUMI.print(humi_read); TEMP.print(temp_read); HEAT.print(heat_read); Kong.print(kong_read); } void setup() { Serial.begin(115200); BLINKER_DEBUG.stream(Serial); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); pinMode(kong,INPUT); Blinker.begin(auth, ssid, pswd); Blinker.attachData(dataRead); Blinker.attachHeartbeat(heartbeat); dht.begin(); } void loop() { Blinker.run(); if (read_time == 0 || (millis() - read_time) >= 2000) { read_time = millis(); float h = dht.readHumidity(); float t = dht.readTemperature(); float c = dht.computeHeatIndex(t, h, false); float k = analogRead(A0); if (isnan(h) || isnan(t)) { BLINKER_LOG("Failed to read from DHT sensor!"); return; humi_read = h; temp_read = t; heat_read = c; kong_read = k; BLINKER_LOG("Humidity: ", h, " %"); BLINKER_LOG("Temperature: ", t, " *C"); BLINKER_LOG("Heat index: ", c, " *C"); BLINKER_LOG("Kong Qi: ", k, " /1024"); } } } |