用esp8266链接温湿度传感器做室内温湿度监控-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2744|回复: 3

用esp8266链接温湿度传感器做室内温湿度监控

[复制链接]
发表于 2020-2-25 11:12 | 显示全部楼层 |阅读模式
#define BLINKER_WIFI
#define BLINKER_MIOT_SENSOR   //小爱同学定义为传感器设备

#include <Blinker.h>
#include <DHT.h>

char auth[] = "da605e07b78e";    //设备key
char ssid[] = "Xiaomi_79A5";         //wifi ssid
char pswd[] = "19881026,@";     //wifi 密码

BlinkerNumber HUMI("humi");    //定义湿度数据键名
BlinkerNumber TEMP("temp");    //定义温度数据键名

#define DHTPIN 2      //定义DHT11模块连接管脚io2

#define DHTTYPE DHT11   // 使用DHT 11温度湿度模块
//#define DHTTYPE DHT22   // DHT 22  (AM2302), AM2321
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

DHT dht(DHTPIN, DHTTYPE);    //定义dht

float humi_read = 0, temp_read = 0;

void heartbeat()
{
    HUMI.print(humi_read);        //给blinkerapp回传湿度数据
    TEMP.print(temp_read);        //给blinkerapp回传温度数据
}

void miotQuery(int32_t queryCode)      //小爱同学语音命令反馈
{
    BLINKER_LOG("MIOT Query codes: ", queryCode);

            int humi_read_int=humi_read;     //去掉湿度浮点
            BlinkerMIOT.humi(humi_read_int);     //小爱接收湿度
            BlinkerMIOT.temp(temp_read);      //小爱接收温度
            BlinkerMIOT.print();

}


void setup()
{
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);
    BLINKER_DEBUG.debugAll();

    Blinker.begin(auth, ssid, pswd);   
    Blinker.attachHeartbeat(heartbeat);
    dht.begin();
    BlinkerMIOT.attachQuery(miotQuery);
}

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);
}

 楼主| 发表于 2020-2-25 11:13 | 显示全部楼层
"ESP8266mDNS.h" 对应多个库
已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266mDNS
"ESP8266HTTPClient.h" 对应多个库
已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266HTTPClient
"ESP8266httpUpdate.h" 对应多个库
已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266httpUpdate
"DHT.h" 对应多个库
已使用: C:\Users\Administrator\Documents\Arduino\libraries\DHT-sensor-library-master
"Blinker.h" 对应多个库
已使用: C:\Users\Administrator\Documents\Arduino\libraries\src
In file included from C:\Users\Administrator\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.cpp:15:0:

"ESP8266WiFi.h" 对应多个库
C:\Users\Administrator\Documents\Arduino\libraries\DHT-sensor-library-master\DHT_U.h:36:29: fatal error: Adafruit_Sensor.h: No such file or directory

已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WiFi
#include <Adafruit_Sensor.h>

"Ticker.h" 对应多个库
                             ^

已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\Ticker
compilation terminated.

"EEPROM.h" 对应多个库
已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\EEPROM
"ESP8266WebServer.h" 对应多个库
已使用: C:\Users\Administrator\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.2\libraries\ESP8266WebServer
exit status 1
为开发板 Generic ESP8266 Module 编译时出错。
找到无效库在 C:\Users\Administrator\Documents\Arduino\libraries\examples: no headers files (.h) found in C:\Users\Administrator\Documents\Arduino\libraries\examples
找到无效库在 C:\Users\Administrator\Documents\Arduino\libraries\test: no headers files (.h) found in C:\Users\Administrator\Documents\Arduino\libraries\test
找到无效库在 C:\Users\Administrator\Documents\Arduino\libraries\examples: no headers files (.h) found in C:\Users\Administrator\Documents\Arduino\libraries\examples
找到无效库在 C:\Users\Administrator\Documents\Arduino\libraries\test: no headers files (.h) found in C:\Users\Administrator\Documents\Arduino\libraries\test
 楼主| 发表于 2020-2-25 11:14 | 显示全部楼层
为什么总提示出错呢  哪位老师帮帮忙啊
发表于 2020-2-25 20:12 | 显示全部楼层
请问有硬件电路的连接图吗
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 05:38 , Processed in 0.093290 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表