|
本帖最后由 lslcxlsl 于 2020-10-25 14:04 编辑
我复制的论坛的代码,关联了天猫精灵,但是天猫精灵总是说无法查询
- #define BLINKER_WIFI
- #define BLINKER_ALIGENIE_SENSOR
-
- #include <Blinker.h>
- #include <DHT.h>
-
- char auth[] = "a9135b780e41";
- char ssid[] = "abc";
- char pswd[] = "chenxu123";
-
- BlinkerNumber HUMI("humi"); //DHT11
- BlinkerNumber TEMP11("temp"); //DHT11
- BlinkerNumber TEMP180("temp180"); // Temperature
- BlinkerNumber PRES("pres"); // Pressure
- BlinkerNumber ALTI("alti"); // Altitude
-
- #define DHTPIN D7
- #define DHTTYPE DHT11 // DHT 11
- //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
- //#define DHTTYPE DHT21 // DHT 21 (AM2301)
- #include <Wire.h>
- #include <Adafruit_BMP085.h>
- Adafruit_BMP085 bmp;
-
- DHT dht(DHTPIN, DHTTYPE);
-
- float humi_read = 0,temp180_read = 0, temp_read = 0 , pres_read = 0, alti_read = 0 ;
-
- void heartbeat()
- {
- HUMI.print(humi_read);
- TEMP11.print(temp_read);
- TEMP180.print(bmp.readTemperature());
- PRES.print(bmp.readPressure());
- ALTI.print(bmp.readAltitude());
-
- }
- void dataStorage()
- {
- Blinker.dataStorage("temp", bmp.readTemperature());
- Blinker.dataStorage("humi", humi_read);
- Blinker.dataStorage("pres", bmp.readPressure());
- }
- void aligenieQuery(int32_t queryCode)
- {
- switch (queryCode)
- {
- case BLINKER_CMD_QUERY_ALL_NUMBER :
- BLINKER_LOG("AliGenie Query All");
- BlinkerAliGenie.temp(temp_read);
- BlinkerAliGenie.humi(humi_read);
- BlinkerAliGenie.print();
- break;
- case BLINKER_CMD_QUERY_TEMP_NUMBER :
- BlinkerAliGenie.temp(temp_read);
- BlinkerAliGenie.print();
- break;
- case BLINKER_CMD_QUERY_HUMI_NUMBER :
- BlinkerAliGenie.humi(humi_read);
- BlinkerAliGenie.print();
- break;
- default :
- BlinkerAliGenie.temp(20);
- BlinkerAliGenie.humi(20);
- BlinkerAliGenie.print();
- break;
- }
- }
-
- 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);
- BlinkerAliGenie.attachQuery(aligenieQuery);
- Blinker.attachDataStorage(dataStorage);
- dht.begin();
- if (!bmp.begin()) {
- BLINKER_LOG("Could not find a valid BMP085 sensor, check wiring!");
- while (1) {delay(100);}
- }
- }
-
- 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);
- }
复制代码 |
|