|
本帖最后由 ecstart 于 2019-2-15 16:22 编辑
组合了一个程序,可以工作,就是APP的界面老是显示不在线,点进去操作几下继电器按钮就又上线了,但是主页去刷新也不显示在线,不知道错在哪里了,大神指正下。
点击去操作几下就是显示上线了。
如果不操作就一直离线状态。
#define BLINKER_WIFI
#include <Blinker.h>
char auth[] = "XXXXXXX";
char ssid[] = "XXXXXX";
char pswd[] = "XXXXX";
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerNumber HEAT("heat");
BlinkerNumber Kong("kong");
#define BT_1 "lb"
BlinkerButton BT1(BT_1);
// Download Adafruit DHT-sensor-library library here:
// https://github.com/adafruit/DHT-sensor-library
#include <DHT.h>
#define DHTPIN 2
#define kong A0
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
DHT dht(DHTPIN, DHTTYPE);
void BT1_callback(const String & state) {
if (state == BLINKER_CMD_OFF){
digitalWrite(15, HIGH);
BT1.text("", "已关闭");
BT1.print("off");
}
else if (state == BLINKER_CMD_ON) {
digitalWrite(15, LOW);
BT1.text("", "已打开");
BT1.print("on");
}
}
uint32_t read_time = 0;
float humi_read, temp_read, heat_read, kong_read;
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void heartbeat()
{
HUMI.print(humi_read);
TEMP.print(temp_read);
HEAT.print(heat_read);
Kong.print(kong_read);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
pinMode(kong,INPUT);
pinMode(15, OUTPUT);
digitalWrite(15, HIGH);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Blinker.attachHeartbeat(heartbeat);
BT1.attach(BT1_callback);
dht.begin();
delay(100);
Blinker.notify("!8FC6传感器上线了!");
}
void loop()
{
float h = dht.readHumidity();
float t = dht.readTemperature();
float c = dht.computeHeatIndex(t, h, false);
float k = analogRead(A0);
humi_read = h;
temp_read = t;
heat_read = c;
kong_read = k;
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
BLINKER_LOG("Heat index: ", c, " *C");
BLINKER_LOG("Kong Qi: ", k, " /1024");
Blinker.run();
}
|
|