|
本帖最后由 myself1820 于 2021-3-5 11:27 编辑
问题现象:Blinker APP里能够正常控制开关,但是小度控制开关失败
app版本:2.5.0
android版本:10.0.0
手机型号:Honor 8X
库版本:0.3.4
开发板:ESP-01S
具体情况为:Blinker APP里能够正常控制开关,小度能够发现设备,但是无法控制开关,无论是语音还是在小度APP中控制都显示“控制失败”。
程序代码为:
#define BLINKER_WIFI
#define BLINKER_PRINT Serial
#define BLINKER_DUEROS_OUTLET
#include <Blinker.h>
char auth[] = "xxx";
char ssid[] = "xxx";
char pswd[] = "xxx";
bool oState = false;
const int OUT_PIN = 0;
#define BUTTON_1 "OUTButton"
BlinkerButton Button1(BUTTON_1);
void button1_callback(const String & state)
{
if (state == BLINKER_CMD_BUTTON_TAP)
{
if (oState) {
digitalWrite(OUT_PIN, HIGH);
oState = false;
}
else {
digitalWrite(OUT_PIN, LOW);
oState = true;
}
Button1.print();
}
}
void duerPowerState(const String & state)
{
BLINKER_LOG("need set power state: ", state);
if (state == BLINKER_CMD_ON) {
digitalWrite(OUT_PIN, LOW);
BlinkerDuerOS.powerState("on");
BlinkerDuerOS.print();
oState = true;
}
else if (state == BLINKER_CMD_OFF) {
digitalWrite(OUT_PIN, HIGH);
BlinkerDuerOS.powerState("off");
BlinkerDuerOS.print();
oState = false;
}
}
void duerQuery(int32_t queryCode)
{
BLINKER_LOG("DuerOS Query codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_TIME_NUMBER :
BLINKER_LOG("DuerOS Query time");
BlinkerDuerOS.time(millis());
BlinkerDuerOS.print();
break;
default :
BlinkerDuerOS.time(millis());
BlinkerDuerOS.print();
break;
}
}
void dataRead(const String & data)
{
BLINKER_LOG("Blinker readString: ", data);
Blinker.vibrate();
uint32_t BlinkerTime = millis();
Blinker.print(BlinkerTime);
Blinker.print("millis", BlinkerTime);
}
void setup()
{
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
pinMode(OUT_PIN, OUTPUT);
digitalWrite(OUT_PIN, HIGH);
Blinker.begin(auth, ssid, pswd);
Blinker.attachData(dataRead);
Button1.attach(button1_callback);
BlinkerDuerOS.attachPowerState(duerPowerState);
BlinkerDuerOS.attachQuery(duerQuery);
}
void loop()
{
Blinker.run();
}
|
|