意思就是开关的on off状态也是设备端发送到app的
// 按下按键即会执行该函数,动作
void button_switch_callback(const String & state)
{
if(state == "on") {
digitalWrite(actionPin, HIGH);
Blinker.delay(100);
digitalWrite(actionPin, LOW);
ButtonSwitch.icon("fas fa-toggle-on");
ButtonSwitch.color("#2e8b57");
ButtonSwitch.text("开启","插座开启啦");
ButtonSwitch.print("on");
TextSwitchStatus.print("电视插座已为您开启");
Blinker.wechat("插座已打开", "打开", "电视插座");
} else if(state == "off") {
digitalWrite(resetPin, HIGH);
Blinker.delay(100);
digitalWrite(resetPin, LOW);
ButtonSwitch.icon("fas fa-toggle-off");
ButtonSwitch.color("#CDC9C9");
ButtonSwitch.text("关闭","插座关闭啦");
ButtonSwitch.print("off");
TextSwitchStatus.print("电视插座已为您关闭");
Blinker.wechat("插座已关闭", "关闭", "电视插座");
}
} |