├── .DS_Store ├── .gitattributes ├── DHT-sensor-library-master.zip ├── README.md └── blinker_xiaoai_wendu.ino /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baogaichejian/blinker_xiaoai_wendu/9d85d268f6867b2ea4f1d3afb6186370cb2fcc0b/.DS_Store -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /DHT-sensor-library-master.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/baogaichejian/blinker_xiaoai_wendu/9d85d268f6867b2ea4f1d3afb6186370cb2fcc0b/DHT-sensor-library-master.zip -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # blinker_xiaoai_wendu 2 | # blinker_xiaoai_wendu.ino 3 | # 点灯科技控制esp8266 连接DHT11 检测室内温度和湿度,联动小爱同学代码 4 | # DHT-sensor-library-master.zip 是DHT模块需要用的库文件必须安装 5 | 6 | -------------------------------------------------------------------------------- /blinker_xiaoai_wendu.ino: -------------------------------------------------------------------------------- 1 | #define BLINKER_WIFI 2 | #define BLINKER_MIOT_SENSOR //小爱同学定义为传感器设备 3 | 4 | #include 5 | #include 6 | 7 | char auth[] = "**********"; //设备key 8 | char ssid[] = "**********"; //wifi ssid 9 | char pswd[] = "**********"; //wifi 密码 10 | 11 | BlinkerNumber HUMI("humi"); //定义湿度数据键名 12 | BlinkerNumber TEMP("temp"); //定义温度数据键名 13 | 14 | #define DHTPIN 2 //定义DHT11模块连接管脚io2 15 | 16 | #define DHTTYPE DHT11 // 使用DHT 11温度湿度模块 17 | //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 18 | //#define DHTTYPE DHT21 // DHT 21 (AM2301) 19 | 20 | DHT dht(DHTPIN, DHTTYPE); //定义dht 21 | 22 | float humi_read = 0, temp_read = 0; 23 | 24 | void heartbeat() 25 | { 26 | HUMI.print(humi_read); //给blinkerapp回传湿度数据 27 | TEMP.print(temp_read); //给blinkerapp回传温度数据 28 | } 29 | 30 | void miotQuery(int32_t queryCode) //小爱同学语音命令反馈 31 | { 32 | BLINKER_LOG("MIOT Query codes: ", queryCode); 33 | 34 | int humi_read_int=humi_read; //去掉湿度浮点 35 | BlinkerMIOT.humi(humi_read_int); //小爱接收湿度 36 | BlinkerMIOT.temp(temp_read); //小爱接收温度 37 | BlinkerMIOT.print(); 38 | 39 | } 40 | 41 | 42 | void setup() 43 | { 44 | Serial.begin(115200); 45 | BLINKER_DEBUG.stream(Serial); 46 | BLINKER_DEBUG.debugAll(); 47 | 48 | Blinker.begin(auth, ssid, pswd); 49 | Blinker.attachHeartbeat(heartbeat); 50 | dht.begin(); 51 | BlinkerMIOT.attachQuery(miotQuery); 52 | } 53 | 54 | void loop() 55 | { 56 | Blinker.run(); 57 | 58 | float h = dht.readHumidity(); 59 | float t = dht.readTemperature(); 60 | 61 | if (isnan(h) || isnan(t)) 62 | { 63 | BLINKER_LOG("Failed to read from DHT sensor!"); 64 | } 65 | else 66 | { 67 | BLINKER_LOG("Humidity: ", h, " %"); 68 | BLINKER_LOG("Temperature: ", t, " *C"); 69 | humi_read = h; 70 | temp_read = t; 71 | } 72 | 73 | 74 | Blinker.delay(2000); 75 | } 76 | --------------------------------------------------------------------------------