求助esp8266使用小爱同学 、天猫精灵无法控制,附带源码
#define BLINKER_WIFI#define BLINKER_ESP_SMARTCONFIG
#define BLINKER_ALIGENIE_MULTI_OUTLET
#define BLINKER_MIOT_MULTI_OUTLET
#include <Blinker.h>
#define LED 5
#define LED2 4
char auth[] = "5ee963455d27";//设备密匙
char ssid[] = "H3C_fl";
char pswd[] = "fxb12251314";
// 新建组件对象
BlinkerButton Button1("btn-1"); // APP组件名称
BlinkerButton Button2("btn-2"); // APP组件名称
BlinkerButton Button3("btn-3"); // APP组件名称
BlinkerNumber Number1("num-xxx");// blinker新建组件
bool switch_onoff = 0; //开关标志位
bool switch_onoff_2 = 0;
bool switch_onoff_3 = 0;
bool oState = { false };
//开灯函数1
void ON() {
digitalWrite(LED, HIGH);
Button1.color("#B22222");
Button1.text("点我关灯");
Button1.print();
switch_onoff = 1;
}
//关灯函数1
void OFF() {
digitalWrite(LED, LOW);
Button1.color("#000000");
Button1.text("点我开灯");
Button1.print();
switch_onoff = 0;
}
//开灯函数2
void ON2() {
digitalWrite(LED2, HIGH);
Button2.color("#B22222");
Button2.text("点我关灯");
Button2.print();
switch_onoff_2 = 1;
}
//关灯函数2
void OFF2() {
digitalWrite(LED2, LOW);
Button2.color("#000000");
Button2.text("点我开灯");
Button2.print();
switch_onoff_2 = 0;
}
void heartbeat()//心跳包
{
Number1.print(WiFi.RSSI());//信号强度
if (switch_onoff == 1) {
Button1.color("#B22222");
Button1.text("点我关灯");
Button1.print();
BUILTIN_SWITCH.print("on");
} else {
Button1.color("#000000");
Button1.text("点我开灯");
Button1.print();
BUILTIN_SWITCH.print("off");
}
if (switch_onoff_2 == 1) {
Button2.color("#B22222");
Button2.text("点我关灯");
Button2.print();
BUILTIN_SWITCH.print("on");
} else {
Button2.color("#000000");
Button2.text("点我开灯");
Button2.print();
BUILTIN_SWITCH.print("off");
}
}
// 按下APP按键即会执行该函数
void button1_callback(const String &state) {
switch_onoff = !switch_onoff;
if (switch_onoff) {
ON();
} else {
OFF();
}
BLINKER_LOG("get button state: ", state);
}
// 按下APP按键即会执行该函数2
void button2_callback(const String &state) {
switch_onoff_2 = !switch_onoff_2;
if (switch_onoff_2) {
ON2();
} else {
OFF2();
}
BLINKER_LOG("get button state2: ", state);
}
// 按下APP按键即会执行该函数3
void button3_callback(const String &state) {
switch_onoff_3 = !switch_onoff_3;
if (switch_onoff_3) {
ON();
ON2();
} else {
OFF();
OFF2();
}
BLINKER_LOG("get button state2: ", state);
}
////////阿里精灵
void aligeniePowerState(const String & state, uint8_t num)
{
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
if (state == BLINKER_CMD_ON) {
if (num == 1) {
switch_onoff = 1;
ON();
BlinkerAliGenie.powerState("on", 1);
BlinkerAliGenie.print();
}
else if (num == 2) {
switch_onoff_2 = 1;
ON2();
BlinkerAliGenie.powerState("on", 2);
BlinkerAliGenie.print();
}
else if (num == 0) {
switch_onoff = 1;
switch_onoff_2 = 1;
switch_onoff_3 = 1;
ON();
ON2();
BlinkerAliGenie.powerState("on", 0);
BlinkerAliGenie.print();
}
}
else if (state == BLINKER_CMD_OFF) {
if (num == 1) {
switch_onoff = 0;
OFF();
BlinkerAliGenie.powerState("off", 1);
BlinkerAliGenie.print();
}
else if (num == 2) {
switch_onoff_2 = 0;
OFF2();
BlinkerAliGenie.powerState("off", 2);
BlinkerAliGenie.print();
}
else if (num == 0) {
switch_onoff = 0;
switch_onoff_2 = 0;
switch_onoff_3 = 0;
OFF();
OFF2();
BlinkerAliGenie.powerState("off", 0);
BlinkerAliGenie.print();
}
}
}
/////////
void miotPowerState(const String & state, uint8_t num)
{
BLINKER_LOG("need set outlet: ", num, ", power state: ", state);
if (state == BLINKER_CMD_ON) {
if (num == 1) {
switch_onoff = 1;
ON();
BlinkerMIOT.powerState("on", 1);
BlinkerMIOT.print();
}
else if (num == 2) {
switch_onoff_2 = 1;
ON2();
BlinkerMIOT.powerState("on", 2);
BlinkerMIOT.print();
}
else if (num == 0) {
switch_onoff = 1;
switch_onoff_2 = 1;
switch_onoff_3 = 1;
ON();
ON2();
BlinkerMIOT.powerState("on", 0);
BlinkerMIOT.print();
}
}
else if (state == BLINKER_CMD_OFF) {
if (num == 1) {
switch_onoff = 0;
OFF();
BlinkerMIOT.powerState("off", 1);
BlinkerMIOT.print();
}
else if (num == 2) {
switch_onoff_2 = 0;
OFF2();
BlinkerMIOT.powerState("off", 2);
BlinkerMIOT.print();
}
else if (num == 0) {
switch_onoff = 0;
switch_onoff_2 = 0;
switch_onoff_3 = 0;
OFF();
OFF2();
BlinkerMIOT.powerState("off", 0);
BlinkerMIOT.print();
}
}
}
void miotQuery(int32_t queryCode, uint8_t num)
{
BLINKER_LOG("AliGenie Query outlet: ", num,", codes: ", queryCode);
switch (queryCode)
{
case BLINKER_CMD_QUERY_ALL_NUMBER :
BLINKER_LOG("MIOT Query All");
BlinkerMIOT.powerState(oState ? "on" : "off", num);
BlinkerMIOT.print();
break;
case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
BLINKER_LOG("MIOT Query Power State");
BlinkerMIOT.powerState(oState ? "on" : "off", num);
BlinkerMIOT.print();
break;
default :
BlinkerMIOT.powerState(oState ? "on" : "off", num);
BlinkerMIOT.print();
break;
}
}
void switch_callback(const String &state) {
BLINKER_LOG("get switch state: ", state);
if (state == BLINKER_CMD_ON) {
ON();
ON2();
BUILTIN_SWITCH.print("on");
} else {
OFF();
OFF2();
BUILTIN_SWITCH.print("off");
}
}
void setup() {
// 初始化串口
Serial.begin(115200);
BLINKER_DEBUG.stream(Serial);
// BLINKER_DEBUG.debugAll();
// 初始化IO
pinMode(12, INPUT);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(LED2, OUTPUT);
digitalWrite(LED2, LOW);
// 初始化blinker
Blinker.begin(auth, ssid, pswd);
Button1.attach(button1_callback);
Button2.attach(button2_callback);
Button3.attach(button3_callback);
Blinker.attachHeartbeat(heartbeat);
BlinkerAliGenie.attachPowerState(aligeniePowerState);//天猫精灵开关
BlinkerMIOT.attachPowerState(miotPowerState);
BlinkerMIOT.attachQuery(miotQuery);
BUILTIN_SWITCH.attach(switch_callback);
}
void loop() {
Blinker.run();
}
确保lib和package为最新,并测试例程,如果还是不行,请看调试信息是否有报错 奈何col 发表于 2021-2-2 22:56
确保lib和package为最新,并测试例程,如果还是不行,请看调试信息是否有报错 ...
这里呼叫天猫和小爱没有任何反应
https://github.com/blinker-iot/blinker-library/blob/master/examples/Blinker_AliGenie/AliGenie_MULTI_OUTLET/AliGenie_MULTI_OUTLET.ino 用这个直接写入测试也没有反应 1278945 发表于 2021-2-2 23:48
https://github.com/blinker-iot/blinker-library/blob/master/examples/Blinker_AliGenie/AliGenie_MULTI_ ...
您确定您写入了,用的例程?正常情况,串口也应该有输出 奈何col 发表于 2021-2-3 00:11
您确定您写入了,用的例程?正常情况,串口也应该有输出
确定写入了, app操作可以 。
语音控制不能用我找不出什么原因
1278945 发表于 2021-2-3 00:24
确定写入了, app操作可以 。
语音控制不能用我找不出什么原因
我在blinker的官网发现只有阿里云的设备key才可以使用语音控制,我之前问题和你一样,换了一下设备就可以了 奈何col 发表于 2021-2-2 22:56
确保lib和package为最新,并测试例程,如果还是不行,请看调试信息是否有报错 ...
可能是服务器的问题。语音控制不支持电灯科技的key但是支持阿里云的key 3137234383 发表于 2021-2-3 10:26
可能是服务器的问题。语音控制不支持电灯科技的key但是支持阿里云的key
目前语音助手接入,只有阿里broker支持,这个文档有写明,请阅读文档https://diandeng.tech/doc/voice-assistant
3137234383 发表于 2021-2-3 10:24
我在blinker的官网发现只有阿里云的设备key才可以使用语音控制,我之前问题和你一样,换了一下设备就可以 ...
是阿里云
页:
[1]
2