这两个的差异是?
- #define BLINKER_WIFI
- #define BLINKER_MIOT_SENSOR
- #include <Blinker.h>
- char auth[] = "93******83"; // Blinker APP中添加设备时生成的Secret Key
- char ssid[] = "ty****op"; // WIFI名称
- char pswd[] = "********"; // WIFI密码
- BlinkerNumber HUMI("humi");
- BlinkerNumber TEMP("temp");
- // Download Adafruit DHT-sensor-library library here:
- // https://github.com/adafruit/DHT-sensor-library
- #include <DHT.h>
- #define DHTPIN 2
- #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;
- void miotQuery(int32_t queryCode)
- {
- BLINKER_LOG("MIOT Query codes: ", queryCode);
- switch (queryCode)
- {
- case BLINKER_CMD_QUERY_ALL_NUMBER :
- BLINKER_LOG("MIOT Query All");
- BlinkerMIOT.temp(20);
- BlinkerMIOT.humi(20);
- BlinkerMIOT.pm25(20);
- BlinkerMIOT.co2(20);
- BlinkerMIOT.print();
- break;
- default :
- BlinkerMIOT.temp(20);
- BlinkerMIOT.humi(20);
- BlinkerMIOT.pm25(20);
- BlinkerMIOT.co2(20);
- BlinkerMIOT.print();
- break;
- }
- }
- void dataRead(const String & data)
- {
- BLINKER_LOG("Blinker readString: ", data);
- Blinker.vibrate();
-
- uint32_t BlinkerTime = millis();
-
- Blinker.print("millis", BlinkerTime);
- }
- void heartbeat()
- {
- HUMI.print(humi_read);
- TEMP.print(temp_read);
- }
- void setup()
- {
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
- Blinker.begin(auth, ssid, pswd);
- Blinker.attachData(dataRead);
- BlinkerMIOT.attachQuery(miotQuery);
- 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();
- if (isnan(h) || isnan(t)) {
- BLINKER_LOG("Failed to read from DHT sensor!");
- return;
- }
- float hic = dht.computeHeatIndex(t, h, false);
- humi_read = h;
- temp_read = t;
- BLINKER_LOG("Humidity: ", h, " %");
- BLINKER_LOG("Temperature: ", t, " *C");
- BLINKER_LOG("Heat index: ", hic, " *C");
- }
- }
复制代码 |