|
下面是代码,blinker官网说20s后为联网会进入待配网状态,但是我APP显示搜索不到设备,
[pre]#include <Wire.h>
#include <DHT.h>
#define BLINKER_WIFI
#include <Blinker.h>
#define ADDRESS_BH1750FVI 0x23 //ADDR="L" for this module
#define ONE_TIME_H_RESOLUTION_MODE 0x20
#define BLINKER_ESP_SMARTCONFIG
byte highByte = 0;
byte lowByte = 0;
char auth[] = "de1d2652e54c";
char ssid[] = ""; //你的WiFi热点名称
char pswd[] = "12345679"; //你的WiFi密码
unsigned int sensorOut = 0;
unsigned int illuminance = 0;
BlinkerButton f5("f5");
BlinkerNumber HUMI("humi");
BlinkerNumber TEMP("temp");
BlinkerNumber SMS ("SMS");
BlinkerNumber sun ("sun");
#define DHTPIN D4
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
float humi_read = 0, temp_read = 0,SMS_read=0,sun_read=0;
//void f5_callback(const String&f5){
//}
void heartbeat()
{
SMS.print(SMS_read);
HUMI.print(humi_read);
TEMP.print(temp_read);
sun.print(sun_read);
}
void dataStorage()
{
Blinker.dataStorage("temp", temp_read);
Blinker.dataStorage("HUMI", humi_read);
Blinker.dataStorage("SMS", SMS_read);
Blinker.dataStorage("sun", sun_read);
}
void wechat_h()
{
Blinker.wechat("温度:",temp_read," *C");
Blinker.wechat("湿度:",humi_read,"%");
Blinker.wechat("光照:",sun_read,"lux");
Blinker.wechat("土壤湿度:",SMS_read);
Blinker.delay(10000);
}
void setup()
{
Wire.begin();
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
BLINKER_DEBUG.debugAll();
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
Blinker.begin(auth, ssid, pswd);
Blinker.attachHeartbeat(heartbeat);
Blinker.attachDataStorage(dataStorage);
dht.begin();
Blinker.attachHeartbeat(wechat_h);
Blinker.wechat("220v高压已上线!!!");
}
void loop()
{
Blinker.run();
Wire.beginTransmission(ADDRESS_BH1750FVI); //"notify" the matching device
Wire.write(ONE_TIME_H_RESOLUTION_MODE); //set operation mode
Wire.endTransmission();
Blinker.delay(180);
Wire.requestFrom(ADDRESS_BH1750FVI, 2); //ask Arduino to read back 2 bytes from the sensor
highByte = Wire.read(); // get the high byte
lowByte = Wire.read(); // get the low byte
sensorOut = (highByte<<8)|lowByte;
illuminance = sensorOut/1.2;
Serial.print(illuminance);
Serial.println(" lux");
float SMS =analogRead(0);
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t))
{
BLINKER_LOG("Failed to read from DHT sensor!");
}
else
{
BLINKER_LOG("sun",illuminance,"lux");
BLINKER_LOG("soil moisture",SMS,"%");
BLINKER_LOG("Humidity: ", h, " %");
BLINKER_LOG("Temperature: ", t, " *C");
humi_read = h;
temp_read = t;
SMS_read=SMS;
sun_read=illuminance;
}
Blinker.delay(2000);
}[/pre]
|
|