|
#include <Blinker.h>
#include <DHT.h>
#define BLINKER_WIFI
#define led 5
#define DHTPIN 13
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
char auth[] = "097e814d5354";
char ssid[] = "young";
char pswd[] = "qweasdzxc";
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerButton Button1("btn-abc");
BlinkerButton Button2("one");
// Download Adafruit DHT-sensor-library library here:
// https://github.com/adafruit/DHT-sensor-library
DHT dht(DHTPIN, DHTTYPE);
uint32_t read_time = 0;
float humi_read, temp_read;
// 按下按键即会执行该函数
void button1_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on")
{
digitalWrite(LED_BUILTIN, LOW);
// 反馈开关状态
Button1.print("on");
}
else if(state=="off")
{
digitalWrite(LED_BUILTIN, HIGH);
// 反馈开关状态
Button1.print("off");
}
BlinkerButton Button1("btn-abc");
// 按下按键即会执行该函数
void button2_callback(const String & state) {
BLINKER_LOG("get button state: ", state);
if (state=="on")
{
digitalWrite(led, HIGH);
// 反馈开关状态
Button2.print("on");
}
else if(state=="off")
{
digitalWrite(led, LOW);
// 反馈开关状态
Button2.print("off");
}
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, HIGH);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
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");
}
}
错误信息
Arduino:1.8.13 (Windows 10), 开发板:"Generic ESP8266 Module, 80 MHz, Flash, Legacy (new can return nullptr), All SSL ciphers (most compatible), dtr (aka nodemcu), 26 MHz, 40MHz, DOUT (compatible), 1MB (FS:64KB OTA:~470KB), 2, nonos-sdk 2.2.1+100 (190703), v2 Lower Memory, Disabled, None, Only Sketch, 115200"
In file included from C:\Users\admin\Desktop\Hello_WiFi\_____\_____.ino:47:0:
C:\Users\admin\Documents\Arduino\libraries\Blinker\src/Blinker.h:215:6: error: #error Please set a mode BLINKER_BLE/BLINKER_WIFI/BLINKER_MQTT ! Please check your mode setting.
#error Please set a mode BLINKER_BLE/BLINKER_WIFI/BLINKER_MQTT ! Please check your mode setting.
^
"Blinker.h" 对应多个库
已使用: C:\Users\admin\Documents\Arduino\libraries\Blinker
未使用:C:\Users\admin\Documents\Arduino\libraries\blinker-library-master
exit status 1
为开发板 Generic ESP8266 Module 编译时出错。
在文件 -> 首选项开启
“编译过程中显示详细输出”选项
这份报告会包含更多信息。
超级奇怪不知道怎么回事
|
-
|