|
本帖最后由 ksbb4920355 于 2020-3-1 09:28 编辑
ESP8266模块一通电就会自动点亮,如何设置默认为关?
我看过好多人改控制灯,你们改好的模块一送电灯会不会亮?还是在操作后才会亮?
假设某天停电了,又来了电,刚好家里又没有人,模块默认送电后把灯点亮,那灯就会一直亮着没人管,浪费电。
难道没人考虑到这个问题吗?
修改代码可以搞定吗?
#define BLINKER_WIFI
#define BLINKER_ALIGENIE_OUTLET //小爱同学
#include <Blinker.h>
char auth[] = "f-4"; //设备key
char ssid[] = "ksbb4920355@qq.com"; //路由器wifi ssid
char pswd[] = "110"; //路由器wifi 密码
BlinkerButton Button1("dianshi"); //定义按钮键名
bool oState = false;
int counter = 0;
void AliGeniePowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) { //开命令 此处修改为点动模式,适
digitalWrite(0, LOW);
Blinker.delay(200);
digitalWrite(0, HIGH);
BlinkerAliGenie.powerState("on");
BlinkerAliGenie.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) { //小爱同学控制关命令 此处修改为点动模式,适合按钮操作,
digitalWrite(0,LOW);
Blinker.delay(200);
digitalWrite(0, HIGH);
BlinkerAliGenie.powerState("off");
BlinkerAliGenie.print();
oState = false;
}
}
void AliGenieQuery(int32_t queryCode) //小爱同学控制
{
BLINKER_LOG("AliGenie Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("AliGenie Query All");
BlinkerAliGenie.powerState(oState ? "on" : "off");
BlinkerAliGenie.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("AliGenie Query Power State");
BlinkerAliGenie.powerState(oState ? "on" : "off");
BlinkerAliGenie.print();
break;
default :
BlinkerAliGenie.powerState(oState ? "on" : "off");
BlinkerAliGenie.print();
break;
}
}
void dataRead(const String & data) // 如果未绑定的组件被触发,则会执行其中内容
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print("millis", BlinkerTime);
}
void button1_callback(const String & state) //点灯app内控制按键触发
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0,LOW);
Blinker.delay(200);
digitalWrite(0, HIGH);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT); //定义io口为输出
digitalWrite(0, HIGH); //定义io默认为高电平
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
BlinkerAliGenie.attachPowerState(AliGeniePowerState);
BlinkerAliGenie.attachQuery(AliGenieQuery);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
|
-
esp8266
|