小爱同学控制8266没反应
小爱同学控制不了,但是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();
}串口监视器是这样的
Freeheap: 10216
mDNS responder started
webSocket_MQTT server started
ws://03BBF092WPHZRC1BMVS2SN0F.local:81
0⸮~?⸮4⸮Ҷ⸮⸮OAqE⸮
__ __ __
/\ \ /\ \ __ /\ \ v0.3.4
\ \ \___ \ \ \/\_\ ___\ \ \/'\ __ _ __
\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , < /'__`\/\`'__\
\ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\__/\ \ \./
\ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\
\/___/ \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/
To better use blinker with your IoT project!
Download latest blinker library here!
=> https://github.com/blinker-iot/blinker-library
Connecting to Piopid
ESP8266_MQTT initialized...
===========================================================
================== Blinker Timer loaded! ==================
Warning!EEPROM address 1536-2431 is used for Blinker Timer!
============= DON'T USE THESE EEPROM ADDRESS! =============
===========================================================
WiFi Connected.
IP Address:
192.168.43.216
Freeheap: 10216
mDNS responder started
webSocket_MQTT server started
ws://03BBF092WPHZRC1BMVS2SN0F.local:81
Connecting to MQTT...
MQTT Connected!
Freeheap: 10368
=======================================================
=========== Blinker Auto Control mode init! ===========
Warning!EEPROM address 0-1279 is used for Auto Control!
=========== DON'T USE THESE EEPROM ADDRESS! ===========
=======================================================
get button state:ontap
get button state:offtap
get button state:ontap
get button state:ontap
get button state:offtap
get button state:ontap
get button state:offtap
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
get button state:ontap
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
MQTT Ping!
Blinker语音设置有没有问题,设置不对小爱会提示设备异常 程序也不用那么复杂,单键控制,状态反馈给小爱 找到原因了吗
页:
[1]