小爱同学控制不了,但是blinker正常,代码是blinker官方的例子,中介是阿里云,米家也能正常同步,用的8266 01s的板,但在NodeMcu上也没有反应,完整代码是这样的
- #define BLINKER_WIFI
- #define BLINKER_MIOT_OUTLET
- #include <Blinker.h>
- char auth[] = "89e6364771fc";
- char ssid[] = "Piopid";
- char pswd[] = "";
- BlinkerButton Button1("btn-on");
- BlinkerButton Button2("btn-off");
- 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 button1_callback(const String & state) //点灯app内控制按键触发
- {
-
- digitalWrite(LED_BUILTIN,LOW);
- BLINKER_LOG("get button state:on", state);
- }
- void button2_callback(const String & state) //点灯按键触发
- {
-
- digitalWrite(LED_BUILTIN,HIGH);
- BLINKER_LOG("get button state:off", state);
- }
- void button3_callback(const String & state) //点灯按键触发
- {
-
- BLINKER_LOG("get button state:on", state);
- Blinker.print(state);
- if(state=="on"){
- digitalWrite(LED_BUILTIN,LOW);
- }else if(state =="off"){
- digitalWrite(LED_BUILTIN,HIGH);
-
- }
- }
- void setup()
- {
- Serial.begin(9600);
- 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);
- Button1.attach(button1_callback);
- Button2.attach(button2_callback);
- }
- void loop()
- {
- Blinker.run();
- }
复制代码 串口监视器是这样的
- [3165] Freeheap: 10216
- [3168] mDNS responder started
- [3169] webSocket_MQTT server started
- [3169] ws://03BBF092WPHZRC1BMVS2SN0F.local:81
- 0⸮~?⸮4⸮Ҷ⸮⸮OAqE⸮[64]
- [65]
- __ __ __
- /\ \ /\ \ __ /\ \ v0.3.4
- \ \ \___ \ \ \ /\_\ ___\ \ \/'\ __ _ __
- \ \ '__`\\ \ \ \/\ \ /' _ `\ \ , < /'__`\/\`'__\
- \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\ __/\ \ \./
- \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\
- \/___/ \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/
- To better use blinker with your IoT project!
- Download latest blinker library here!
- => https://github.com/blinker-iot/blinker-library
- [467] Connecting to Piopid
- [499] ESP8266_MQTT initialized...
- [532]
- ===========================================================
- ================== Blinker Timer loaded! ==================
- Warning!EEPROM address 1536-2431 is used for Blinker Timer!
- ============= DON'T USE THESE EEPROM ADDRESS! =============
- ===========================================================
- [1364] WiFi Connected.
- [1364] IP Address:
- [1364] 192.168.43.216
- [3036] Freeheap: 10216
- [3038] mDNS responder started
- [3039] webSocket_MQTT server started
- [3039] ws://03BBF092WPHZRC1BMVS2SN0F.local:81
- [33428] Connecting to MQTT...
- [35116] MQTT Connected!
- [35116] Freeheap: 10368
- [35116] =======================================================
- [35116] =========== Blinker Auto Control mode init! ===========
- [35171] Warning!EEPROM address 0-1279 is used for Auto Control!
- [35238] =========== DON'T USE THESE EEPROM ADDRESS! ===========
- [35306] =======================================================
- [41256] get button state:ontap
- [44367] get button state:offtap
- [50115] get button state:ontap
- [51562] get button state:ontap
- [52851] get button state:offtap
- [54159] get button state:ontap
- [54936] get button state:offtap
- [80096] MQTT Ping!
- [110697] MQTT Ping!
- [141288] MQTT Ping!
- [171889] MQTT Ping!
- [172936] get button state:ontap
- [205107] MQTT Ping!
- [246424] MQTT Ping!
- [277041] MQTT Ping!
- [307651] MQTT Ping!
- [338264] MQTT Ping!
- [368882] MQTT Ping!
- [399497] MQTT Ping!
- [430093] MQTT Ping!
- [460694] MQTT Ping!
复制代码
|