小爱同学控制8266没反应-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2631|回复: 4

[求助] 小爱同学控制8266没反应

[复制链接]
发表于 2020-12-22 01:37 | 显示全部楼层 |阅读模式
小爱同学控制不了,但是blinker正常,代码是blinker官方的例子,中介是阿里云,米家也能正常同步,用的8266 01s的板,但在NodeMcu上也没有反应,完整代码是这样的
  1. #define BLINKER_WIFI
  2. #define BLINKER_MIOT_OUTLET

  3. #include <Blinker.h>

  4. char auth[] = "89e6364771fc";
  5. char ssid[] = "Piopid";
  6. char pswd[] = "";
  7. BlinkerButton Button1("btn-on");
  8. BlinkerButton Button2("btn-off");
  9. bool oState = false;

  10. void miotPowerState(const String & state)
  11. {
  12.     BLINKER_LOG("need set power state: ", state);

  13.     if (state == BLINKER_CMD_ON) {
  14.         digitalWrite(LED_BUILTIN, HIGH);

  15.         BlinkerMIOT.powerState("on");
  16.         BlinkerMIOT.print();

  17.         oState = true;
  18.     }
  19.     else if (state == BLINKER_CMD_OFF) {
  20.         digitalWrite(LED_BUILTIN, LOW);

  21.         BlinkerMIOT.powerState("off");
  22.         BlinkerMIOT.print();

  23.         oState = false;
  24.     }
  25. }

  26. void miotQuery(int32_t queryCode)
  27. {
  28.     BLINKER_LOG("MIOT Query codes: ", queryCode);

  29.     switch (queryCode)
  30.     {
  31.         case BLINKER_CMD_QUERY_ALL_NUMBER :
  32.             BLINKER_LOG("MIOT Query All");
  33.             BlinkerMIOT.powerState(oState ? "on" : "off");
  34.             BlinkerMIOT.print();
  35.             break;
  36.         case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
  37.             BLINKER_LOG("MIOT Query Power State");
  38.             BlinkerMIOT.powerState(oState ? "on" : "off");
  39.             BlinkerMIOT.print();
  40.             break;
  41.         default :
  42.             BlinkerMIOT.powerState(oState ? "on" : "off");
  43.             BlinkerMIOT.print();
  44.             break;
  45.     }
  46. }

  47. void dataRead(const String & data)
  48. {
  49.     BLINKER_LOG("Blinker readString: ", data);

  50.     Blinker.vibrate();
  51.    
  52.     uint32_t BlinkerTime = millis();
  53.    
  54.     Blinker.print("millis", BlinkerTime);
  55. }

  56. void button1_callback(const String & state)     //点灯app内控制按键触发
  57. {
  58.    
  59.     digitalWrite(LED_BUILTIN,LOW);
  60.     BLINKER_LOG("get button state:on", state);
  61. }
  62. void button2_callback(const String & state)     //点灯按键触发
  63. {
  64.    
  65.     digitalWrite(LED_BUILTIN,HIGH);
  66.     BLINKER_LOG("get button state:off", state);
  67. }

  68. void button3_callback(const String & state)     //点灯按键触发
  69. {  
  70.   
  71.     BLINKER_LOG("get button state:on", state);
  72.      Blinker.print(state);
  73.     if(state=="on"){
  74.     digitalWrite(LED_BUILTIN,LOW);
  75.      }else if(state =="off"){
  76.             digitalWrite(LED_BUILTIN,HIGH);
  77.         
  78.     }
  79. }


  80. void setup()
  81. {
  82.     Serial.begin(9600);
  83.     BLINKER_DEBUG.stream(Serial);

  84.     pinMode(LED_BUILTIN, OUTPUT);
  85.     digitalWrite(LED_BUILTIN, LOW);

  86.     Blinker.begin(auth, ssid, pswd);
  87.     Blinker.attachData(dataRead);
  88.    
  89.     BlinkerMIOT.attachPowerState(miotPowerState);
  90.     BlinkerMIOT.attachQuery(miotQuery);
  91.     Button1.attach(button1_callback);  
  92.     Button2.attach(button2_callback);  
  93. }

  94. void loop()
  95. {
  96.     Blinker.run();
  97. }
复制代码
串口监视器是这样的
  1. [3165] Freeheap: 10216
  2. [3168] mDNS responder started
  3. [3169] webSocket_MQTT server started
  4. [3169] ws://03BBF092WPHZRC1BMVS2SN0F.local:81
  5. 0⸮~?⸮4⸮Ҷ⸮⸮OAqE⸮[64]
  6. [65]
  7. __       __                __
  8. /\ \     /\ \    __        /\ \              v0.3.4
  9. \ \ \___ \ \ \  /\_\    ___\ \ \/'\      __   _ __   
  10. \ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
  11.   \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\  __/\ \ \./
  12.    \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\  
  13.     \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/  
  14.     To better use blinker with your IoT project!
  15.     Download latest blinker library here!
  16.     => https://github.com/blinker-iot/blinker-library

  17. [467] Connecting to Piopid
  18. [499] ESP8266_MQTT initialized...
  19. [532]
  20. ===========================================================
  21. ================== Blinker Timer loaded! ==================
  22. Warning!EEPROM address 1536-2431 is used for Blinker Timer!
  23. ============= DON'T USE THESE EEPROM ADDRESS! =============
  24. ===========================================================

  25. [1364] WiFi Connected.
  26. [1364] IP Address:
  27. [1364] 192.168.43.216
  28. [3036] Freeheap: 10216
  29. [3038] mDNS responder started
  30. [3039] webSocket_MQTT server started
  31. [3039] ws://03BBF092WPHZRC1BMVS2SN0F.local:81
  32. [33428] Connecting to MQTT...
  33. [35116] MQTT Connected!
  34. [35116] Freeheap: 10368
  35. [35116] =======================================================
  36. [35116] =========== Blinker Auto Control mode init! ===========
  37. [35171] Warning!EEPROM address 0-1279 is used for Auto Control!
  38. [35238] =========== DON'T USE THESE EEPROM ADDRESS! ===========
  39. [35306] =======================================================
  40. [41256] get button state:ontap
  41. [44367] get button state:offtap
  42. [50115] get button state:ontap
  43. [51562] get button state:ontap
  44. [52851] get button state:offtap
  45. [54159] get button state:ontap
  46. [54936] get button state:offtap
  47. [80096] MQTT Ping!
  48. [110697] MQTT Ping!
  49. [141288] MQTT Ping!
  50. [171889] MQTT Ping!
  51. [172936] get button state:ontap
  52. [205107] MQTT Ping!
  53. [246424] MQTT Ping!
  54. [277041] MQTT Ping!
  55. [307651] MQTT Ping!
  56. [338264] MQTT Ping!
  57. [368882] MQTT Ping!
  58. [399497] MQTT Ping!
  59. [430093] MQTT Ping!
  60. [460694] MQTT Ping!
复制代码


发表于 2020-12-22 08:39 | 显示全部楼层

回帖奖励 +1 金币

Blinker语音设置有没有问题,设置不对小爱会提示设备异常
发表于 2020-12-22 08:42 | 显示全部楼层
程序也不用那么复杂,单键控制,状态反馈给小爱
发表于 2021-1-11 21:30 | 显示全部楼层

回帖奖励 +1 金币

找到原因了吗
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 14:54 , Processed in 0.076223 second(s), 19 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表