|
#define BLINKER_WIFI
#define BLINKER_MIOT_OUTLET
#include <Blinker.h>
char auth[] = "8781567963dd";
char ssid[] = "CMCC";
char pswd[] = "994805995";
BlinkerButton Buttonl{"btn-CMCC"};
bool oState = false;
void buttonl_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 setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(0, OUTPUT);
digitalWrite(0,HIGH);
Blinker.begin(auth, ssid, pswd);
BlinkerMIOT.attachPowerState(miotPowerState);
Buttonl.attach(buttonl_callback);
}
void loop()
{
Blinker.run();
}
|
|