|
- #define BLINKER_WIFI
- #define BLINKER_MIOT_OUTLET
- #include <Blinker.h>
- char auth[] = "Your Device Secret Key";
- char ssid[] = "Your WiFi network SSID or name";
- char pswd[] = "Your WiFi network WPA password or WEP key";
- bool oState = false;
- void miotPowerState(const String & state)
- {
- BLINKER_LOG("need set power state: ", state);
- if (state == BLINKER_CMD_ON) {
- digitalWrite(LED_BUILTIN, HIGH);
- BlinkerMIOT.powerState("on");
- BlinkerMIOT.print();
- oState = true;
- }
- else if (state == BLINKER_CMD_OFF) {
- digitalWrite(LED_BUILTIN, LOW);
- BlinkerMIOT.powerState("off");
- BlinkerMIOT.print();
- oState = false;
- }
- }
- void miotQuery(int32_t queryCode)
- {
- BLINKER_LOG("MIOT Query codes: ", queryCode);
- switch (queryCode)
- {
- case BLINKER_CMD_QUERY_ALL_NUMBER :
- BLINKER_LOG("MIOT Query All");
- BlinkerMIOT.powerState(oState ? "on" : "off");
- BlinkerMIOT.print();
- break;
- case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
- BLINKER_LOG("MIOT Query Power State");
- BlinkerMIOT.powerState(oState ? "on" : "off");
- BlinkerMIOT.print();
- break;
- default :
- BlinkerMIOT.powerState(oState ? "on" : "off");
- BlinkerMIOT.print();
- break;
- }
- }
- void dataRead(const String & data)
- {
- BLINKER_LOG("Blinker readString: ", data);
- Blinker.vibrate();
-
- uint32_t BlinkerTime = millis();
-
- Blinker.print("millis", BlinkerTime);
- }
- void setup()
- {
- Serial.begin(115200);
- BLINKER_DEBUG.stream(Serial);
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
- Blinker.begin(auth, ssid, pswd);
- Blinker.attachData(dataRead);
-
- BlinkerMIOT.attachPowerState(miotPowerState);
- BlinkerMIOT.attachQuery(miotQuery);
- }
- void loop()
- {
- Blinker.run();
- }
复制代码 |
|