#define BLINKER_WIFI
#define BLINKER_MIOT_SENSOR
#define BLINKER_WITHOUT_SSL
#include <Blinker.h>
char auth[] = "";
char ssid[] = "";
char pswd[] = "";
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerButton b1("b1");
BlinkerButton Button("btn");
#include <DHT.h>
#define DHTPIN 4
int OUT1 = 12;
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
uint32_t read_time = 0;
float humi_read, temp_read;
void button_callback(const String & state) //手机控制LED的亮灭//
{
BLINKER_LOG("get button state: ", state);
digitalWrite(OUT1, !digitalRead(OUT1));
if (digitalRead(OUT1)==HIGH)
{
Button.color("#008000"); //green
Button.text("on");
Button.print("on");
}
else
{
Button.color("#FF0000"); //red
Button.text("off");
Button.print("off");
}
// delay(100);
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("间隔", BlinkerTime/1000);
}
void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
if (digitalRead(OUT1)==HIGH)
{
Button.color("#008000"); //green
Button.text("已开x");
Button.print("on");
}
else
{
Button.color("#FF0000"); //red
Button.text("已关x");
Button.print("off");
}
}
void dataStorage() {
Blinker.dataStorage("temp", temp_read);
Blinker.dataStorage("humi", humi_read);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// BLINKER_DEBUG.debugAll();
pinMode(OUT1, OUTPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, HIGH);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
Button.attach(button_callback);
Blinker.attachDataStorage(dataStorage);
dht.begin();
digitalWrite(OUT1, HIGH);
}
void loop()
{
Blinker.run();
digitalWrite(LED_BUILTIN, HIGH);
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;
}
humi_read = 33.33;
temp_read = 66.666;
digitalWrite(LED_BUILTIN, LOW);
}
} 如果两个wifi,连其中任意一个都行,这个语句怎么写啊?Blinker.begin(auth, ssid, pswd);
判断例子
bool result = Blinker.connect(); //获取连接服务器的状态0失败 1成功
//bool result = Blinker.connected();
if (result == 0 ){
digitalWrite(b1, LOW); //亮灯
}else if (result == 1 ){
digitalWrite(b1, HIGH); //灭灯 这个帖子也不错
esp8266断网后通过软件自动重启的方法
https://www.arduino.cn/forum.php?mod=viewthread&tid=95933&highlight=%E9%87%8D%E5%90%AF
页:
1
[2]