|
本帖最后由 haijun523 于 2020-12-25 08:41 编辑
- #define BLINKER_MIOT_OUTLET
- #define BLINKER_ALIGENIE_OUTLET
- #define BLINKER_DUEROS_OUTLET
- #include <Blinker.h>
- char auth[] = "abdcefg"; //设备key
- char ssid[] = "abcd"; //路由器wifi ssid
- char pswd[] = "abcd"; //路由器wifi 密码
- BlinkerButton Button1("btn-abc"); //定义按钮键名
- bool oState = false;
- void button1_callback(const String & state)
- {
- BLINKER_LOG("get button state: ", state);
- digitalWrite(0,LOW);
- Blinker.delay(200); //点灯app内控制按键触发
- digitalWrite(0, HIGH);
- }
- void miotPowerState(const String & state)
- {
- BLINKER_LOG("need set power state: ", state);
- if (state == BLINKER_CMD_ON) {
- digitalWrite(0, LOW);
- Blinker.delay(200); //小爱同学控制开命令 此处修改为点动模式,适合按钮操作,
- digitalWrite(0, HIGH);
- BlinkerMIOT.powerState("on");
- BlinkerMIOT.print();
- oState = true;
- }
- else if (state == BLINKER_CMD_OFF) {
- digitalWrite(0,LOW);
- Blinker.delay(200); //小爱同学控制关命令 此处修改为点动模式,适合按钮操作
- digitalWrite(0, HIGH);
- BlinkerMIOT.powerState("off");
- BlinkerMIOT.print();
- oState = false;
- }
- }
- 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();
- }
- else if (state == BLINKER_CMD_OFF) {
- digitalWrite(0,LOW);
- Blinker.delay(200); //小爱同学控制关命令 此处修改为点动模式,适合按钮操作
- digitalWrite(0, HIGH);
- BlinkerAliGenie.powerState("off");
- BlinkerAliGenie.print();
- oState = false;
- }
- }
- void duerPowerState(const String & state)
- {
- BLINKER_LOG("need set power state: ", state);
- if (state == BLINKER_CMD_ON) {
- digitalWrite(0, LOW);
- Blinker.delay(200); //小爱同学控制开命令 此处修改为点动模式,适合按钮操作,
- digitalWrite(0, HIGH);
- BlinkerDuerOS.powerState("on");
- BlinkerDuerOS.print();
- }
- else if (state == BLINKER_CMD_OFF) {
- digitalWrite(0,LOW);
- Blinker.delay(200); //小爱同学控制关命令 此处修改为点动模式,适合按钮操作
- digitalWrite(0, HIGH);
- BlinkerDuerOS.powerState("off");
- BlinkerDuerOS.print();
- oState = false;
- }
- }
- void setup()
- {
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- pinMode(0, OUTPUT); //定义io口为输出
- digitalWrite(0, HIGH); //定义io默认为高电平
- Blinker.begin(auth,ssid, pswd);
- BlinkerDuerOS.attachPowerState(duerPowerState);
- BlinkerMIOT.attachPowerState(miotPowerState);
- BlinkerAliGenie.attachPowerState(aligeniePowerState);
- Button1.attach(button1_callback);
- }
- void loop()
- {
- Blinker.run();
- }
复制代码
|
-
|