|
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET
#define BLINKER_ALIGENIE_OUTLET
#define BLINKER_DUEROS_OUTLET
#include <Blinker.h>
char auth[] = "3"; //设备key
char ssid[] = "1"; //路由器wifi ssid
char pswd[] = "2"; //路由器wifi 密码
BlinkerButton Button1("anniu"); //按钮键名
bool oState = false;
void button1_callback(const String & state)
{
BLINKER_LOG("get button state: ", state);
digitalWrite(0,LOW);
Blinker.delay(200);
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);
digitalWrite(0, HIGH);
Blinker.begin(auth,ssid, pswd);
BlinkerDuerOS.attachPowerState(duerPowerState);
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerAliGenie.attachPowerState(aligeniePowerState);
Button1.attach(button1_callback);
}
void loop()
{
Blinker.run();
}
|
|