|
|
| #define BLINKER_WIFI
|
| #define BLINKER_ESP_SMARTCONFIG
|
| #define BLINKER_MIOT_SENSOR//支持小爱同学
|
| #include <Blinker.h>
|
| char auth[] = "Blinker密钥";
|
| //char ssid[] = "WiFi名称";
|
| //char pswd[] = "密码";
|
|
|
| //BME280
|
|
|
| BlinkerNumber TEMP("num-htn"); // Temperature
|
| BlinkerNumber HUMI("num-ft"); // Humidity
|
| BlinkerNumber PRES("num-hi"); // Pressure
|
| BlinkerNumber ALTI("num-nn"); // Altitude
|
| int tempValue = 0;
|
| int humiValue = 0;
|
| int presValue = 0;
|
| int altiValue = 0;
|
| // DHT11
|
| BlinkerNumber DHTTEMP("dht-temp"); // Temperature
|
| BlinkerNumber DHTHUMI("dht-humi"); // Humidity
|
| int dhtTempValue = 0;
|
| int dhtHumiValue = 0;
|
|
|
|
|
| // RUNTIME
|
| uint32 startTime;
|
| uint32 runTime;
|
| // Download Adafruit-BMP085-Library library here:
|
| // https://github.com/adafruit/Adafruit_BME280_Library
|
| // https://github.com/adafruit/Adafruit_Sensor
|
| #include <Wire.h>
|
| #include <Adafruit_Sensor.h>
|
| #include <Adafruit_BME280.h>
|
|
|
| #define SEALEVELPRESSURE_HPA (1013.25)
|
|
|
| Adafruit_BME280 bme;
|
|
|
| #include <DHT.h>
|
| #define DHTPIN D8
|
| #define DHTTYPE DHT11
|
| DHT dht(DHTPIN, DHTTYPE);
|
|
|
| void dataRead(const String &data)
|
| {
|
| BLINKER_LOG("Blinker readString: ", data);
|
|
|
| Blinker.vibrate();
|
|
|
| uint32_t BlinkerTime = millis();
|
|
|
| Blinker.print("millis", BlinkerTime);
|
| }
|
|
|
| void dataStorage()
|
| {
|
| readSensor();
|
| Blinker.dataStorage("temp", tempValue);
|
| Blinker.dataStorage("humi", humiValue);
|
| Blinker.dataStorage("pres", altiValue);
|
| Blinker.dataStorage("dht-temp", dhtTempValue);
|
| Blinker.dataStorage("dht-humi", dhtHumiValue);
|
| }
|
|
|
| void heartbeat()
|
| {
|
| readSensor();
|
| TEMP.print(tempValue);
|
| HUMI.print(humiValue);
|
| PRES.print(presValue);
|
| ALTI.print(altiValue);
|
| DHTTEMP.print(dhtTempValue);
|
| DHTHUMI.print(dhtHumiValue);
|
| }
|
|
|
| void readSensor()
|
| {
|
| tempValue = bme.readTemperature();
|
| humiValue = bme.readHumidity();
|
| presValue = bme.readPressure();
|
| altiValue = bme.readAltitude(SEALEVELPRESSURE_HPA);
|
|
|
| dhtTempValue = dht.readTemperature();
|
| dhtHumiValue = dht.readHumidity();
|
| if (isnan(dhtTempValue) || isnan(dhtHumiValue))
|
| {
|
| dhtTempValue = 0;
|
| dhtHumiValue = 0;
|
| }
|
| }
|
|
|
| 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(tempValue);
|
| BlinkerMIOT.humi(humiValue);
|
| BlinkerMIOT.pm25(presValue);
|
| BlinkerMIOT.co2(altiValue);
|
| BlinkerMIOT.print();
|
| break;
|
|
|
| default :
|
| BlinkerMIOT.temp(20);
|
| BlinkerMIOT.humi(20);
|
| BlinkerMIOT.pm25(20);
|
| BlinkerMIOT.co2(20);
|
| BlinkerMIOT.print();
|
| break;
|
| }
|
| }
|
|
|
|
|
| void setup()
|
| {
|
| Serial.begin(115200);
|
| BLINKER_DEBUG.stream(Serial);
|
| pinMode(LED_BUILTIN, OUTPUT);
|
| digitalWrite(LED_BUILTIN, LOW);
|
|
|
| Blinker.begin(auth);
|
| //(! bme.begin(BME280地址, &Wire))
|
| if (! bme.begin(0x76, &Wire)) {
|
| Serial.println("Could not find a valid BME280 sensor, check wiring!");
|
| while (1);
|
| }
|
| dht.begin();
|
| readSensor();
|
| Blinker.attachData(dataRead);
|
| Blinker.attachHeartbeat(heartbeat);
|
| Blinker.attachDataStorage(dataStorage);
|
| BlinkerMIOT.attachQuery(miotQuery);
|
| }
|
|
|
|
|
| void loop()
|
| {
|
| Blinker.run();
|
| }
|
[/mw_shl_code]