新手求助!blinker同步到米家,但手机里的小爱控制不了ESP8266-Arduino中文社区 - Powered by Discuz! Archiver

Tahngarth 发表于 2020-5-30 02:40

新手求助!blinker同步到米家,但手机里的小爱控制不了ESP8266

搞了两个晚上还是没解决,请大神帮忙看看
我的手机是苹果手机,下了点灯,米家,小爱这3个app
点灯里已经上传好了代码,用里面的设置的按键可以控制灯的开关,
然后米家绑定点灯,同步设备后,小爱可以显示出设备,
最后训练小爱开关灯,结果就是开关不了。起初我用的是板子上的LED,后来有换了D5引脚都不行。都是只能再blinker里控制不能在小爱里控制
不知道是不是编写的问题,我看了好多视频也研究了很久实在不知道问题再哪。请大神帮忙!


#define BLINKER_PRINT Serial //调用串口监视器
#define BLINKER_WIFI         //调用WIFI库
#define BLINKER_MIOT_LIGHT   //调用小米库-灯
#include <Blinker.h>

char auth[] = "正确的密匙";
char ssid[] = "正确的WIFI账号";
char pswd[] = "正确的密码";

bool ledState;

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

uint32_t BlinkerTime = millis();

Blinker.print("millis", BlinkerTime);
}

// 新建组件对象
BlinkerButton Button1("abc");

// 按下按键即会执行该函数
void button1_callback(const String & state) {
    BLINKER_LOG("get button state: ", state);
    digitalWrite(D5, !digitalRead(D5));
}

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

    if (state == BLINKER_CMD_ON) {
      digitalWrite(D5, LOW);
      BlinkerMIOT.powerState("on");
      BlinkerMIOT.print();
      ledState = true;
    }
    else if (state == BLINKER_CMD_OFF) {
      digitalWrite(D5, HIGH);
      BlinkerMIOT.powerState("off");
      BlinkerMIOT.print();
      ledState = false;
    }
}

void miotQuery(int32_t queryCode)
{
BLINKER_LOG("MIOT Query codes: ", queryCode);

switch (queryCode)
{
    case BLINKER_CMD_QUERY_POWERSTATE_NUMBER :
      BLINKER_LOG("MIOT Query Power State");
      BlinkerMIOT.powerState(ledState ? "on" : "off");
      BlinkerMIOT.print();
      break;

    default :
      BlinkerMIOT.powerState(ledState ? "on" : "off");
      BlinkerMIOT.print();
      break;
}
}


void setup() {
    // 初始化串口
    Serial.begin(115200);
    BLINKER_DEBUG.stream(Serial);
    BLINKER_DEBUG.debugAll();

    // 初始化有LED的IO
    pinMode(D5, OUTPUT);
    digitalWrite(D5, HIGH);

    // 初始化blinker
    Blinker.attachData(dataRead);
    Blinker.begin(auth, ssid, pswd);
    Button1.attach(button1_callback);

    //注册语音回调函数
    BlinkerMIOT.attachPowerState(miotPowerState);
    BlinkerMIOT.attachQuery(miotQuery);
}

void loop() {
    Blinker.run();
}

Tahngarth 发表于 2020-5-30 02:43

程序里面有些是可以省略的,但感觉这些都不是关键,之前我是直接用官网给的程序也是不行。:'(:'(

奈何col 发表于 2020-5-30 12:20

看看调试信息,是否正常收到控制指令

Tahngarth 发表于 2020-5-30 12:46


__       __                __
/\ \   /\ \    __      /\ \            v0.3.3
\ \ \___ \ \ \/\_\    ___\ \ \/'\      __   _ __   
\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
\ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\__/\ \ \./
   \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\
    \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/
    To better use blinker with your IoT project!
    Download latest blinker library here!
    => https://github.com/blinker-iot/blinker-library

_aliType:
_duerType:
_miType: &miType=light
_authKey: 590125f169cb
Connecting to Tahngarth-ME
ESP8266_MQTT initialized...

===========================================================
================== Blinker Timer loaded! ==================
Warning!EEPROM address 1536-2431 is used for Blinker Timer!
============= DON'T USE THESE EEPROM ADDRESS! =============
===========================================================

countdown state: false
_cdRunState: 0
_totalTime: 0
_runTime: 0
_action:
loop state: false
_lpRunState: 0
_times: 0
_tri_times: 0
_time1: 0
_action1:
_time2: 0
_action2:
_lpData: 0
checkNum count: 1
WiFi Connected.
IP Address:
192.168.1.102
begin: https://iot.diandeng.tech/api/v1/user/device/diy/auth?authKey=590125f169cb&miType=light
GET... code: 200
reply was:
==============================
{"detail": {"broker": "aliyun", "deviceName": "F51B77C42SR90D1B877V1LGS", "iotId": "zD6g5EiG2AwIvNHPnfTd000000", "iotToken": "^1^1590813831808^9c8b70634e97fd5", "productKey": "JgCGbHlndgz", "uuid": "f9ce4d425917d7c7091fd643478151f6"}, "message": 1000}
==============================
====================
DEVICE_NAME_MQTT: F51B77C42SR90D1B877V1LGS
MQTT_PRODUCTINFO_MQTT: JgCGbHlndgz
MQTT_ID_MQTT: F51B77C42SR90D1B877V1LGS
MQTT_NAME_MQTT: zD6g5EiG2AwIvNHPnfTd000000
MQTT_KEY_MQTT: ^1^1590813831808^9c8b70634e97fd5
MQTT_BROKER: aliyun
HOST: public.iot-as-mqtt.cn-shanghai.aliyuncs.com
PORT: 1883
UUID_MQTT: f9ce4d425917d7c7091fd643478151f6
====================
BLINKER_PUB_TOPIC_MQTT: /JgCGbHlndgz/F51B77C42SR90D1B877V1LGS/s
BLINKER_SUB_TOPIC_MQTT: /JgCGbHlndgz/F51B77C42SR90D1B877V1LGS/r
Freeheap: 10080
mDNS responder started
webSocket_MQTT server started
ws://F51B77C42SR90D1B877V1LGS.local:81
Current time: Sat May 30 04:44:04 2020

NTP time: 1590785044
time (millis() - ntpFreshTime): 16467
ntpGetTime: 0
1
==== needInit ====
message: /share/device?deviceName=F51B77C42SR90D1B877V1LGS&key=590125f169cb
blinker server begin
Freeheap: 31256
HTTPS begin: https://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=F51B77C42SR90D1B877V1LGS&key=590125f169cb
HTTPS payload: /share/device?deviceName=F51B77C42SR90D1B877V1LGS&key=590125f169cb
status... code: 200
{"detail": {"users": []}, "message": 1000}
payload: {"users":[]}
sharers data: {"users":[]}
load timing
load timing taskCount: 0
freshTiming wDay: 6, nowMins: 284, nowSeconds: 17045
nextTask: 10apartSeconds: 69355 wDay: 6
cbackData: 10
change apartSeconds: 3600
Connecting to MQTT...
MQTT Connected!
Freeheap: 10440
millis: 18930, connect_time: 16469
MQTT conn init success
Got: {"deviceType":"DiyArduino","data":{"get":"state"},"fromDevice":"f9ce4d425917d7c7091fd643478151f6","toDevice":"F51B77C42SR90D1B877V1LGS"}
data: {"get":"state"}
fromDevice: f9ce4d425917d7c7091fd643478151f6
Authority uuid
parse data: {"get":"state"}
defined BLINKER_ARDUINOJSON
autoFormatData key: state, json: "state":"online"
new.
timer codes: 000
autoFormatData key: timer, json: "timer":"000"
add.
autoFormatData key: version, json: "version":"0.1.0"
add.
print: {"state":"online","timer":"000","version":"0.1.0"}
Proto print...
Freeheap: 7576
isJson: {"data":{"state":"online","timer":"000","version":"0.1.0"},"fromDevice":"F51B77C42SR90D1B877V1LGS","toDevice":"f9ce4d425917d7c7091fd643478151f6","deviceType":"OwnApp"}
MQTT Publish...
Freeheap: 7576
{"data":{"state":"online","timer":"000","version":"0.1.0"},"fromDevice":"F51B77C42SR90D1B877V1LGS","toDevice":"f9ce4d425917d7c7091fd643478151f6","deviceType":"OwnApp"}
...OK!
Freeheap: 7576
Freeheap: 8608
heartBeat isParsed
checkNum count: 1
isParsed
num: 0, Connected from: 192.168.1.31, url: /
num: 0, get Text: {"get":"state"}, length: 15
parse data: {"get":"state"}
defined BLINKER_ARDUINOJSON
autoFormatData key: state, json: "state":"online"
new.
timer codes: 000
autoFormatData key: timer, json: "timer":"000"
add.
autoFormatData key: version, json: "version":"0.1.0"
add.
print: {"state":"online","timer":"000","version":"0.1.0"}
Proto print...
Freeheap: 7968
WS response:
{"state":"online","timer":"000","version":"0.1.0"}
Success...
Freeheap: 8328
heartBeat isParsed
checkNum count: 1
isParsed
num: 0, get Text: {"abc":"on"}, length: 12
parse data: {"abc":"on"}
defined BLINKER_ARDUINOJSON
checkNum count: 1
strWidgetsParse isParsed
strWidgetsParse: abc
get button state: on
isParsed
num: 0, get Text: {"abc":"on"}, length: 12
parse data: {"abc":"on"}
defined BLINKER_ARDUINOJSON
checkNum count: 1
strWidgetsParse isParsed
strWidgetsParse: abc
get button state: on
isParsed
num: 0, get Text: {"abc":"on"}, length: 12
parse data: {"abc":"on"}
defined BLINKER_ARDUINOJSON
checkNum count: 1
strWidgetsParse isParsed
strWidgetsParse: abc
get button state: on
isParsed
num: 0, get Text: {"abc":"on"}, length: 12
parse data: {"abc":"on"}
defined BLINKER_ARDUINOJSON
checkNum count: 1
strWidgetsParse isParsed
strWidgetsParse: abc
get button state: on
isParsed
MQTT Ping!
Freeheap: 10072
Disconnected! 0
MQTT Ping!
Freeheap: 10360

Tahngarth 发表于 2020-5-30 12:46

我用blinker开关了一下灯没有问题,小爱还是不行

奈何col 发表于 2020-5-30 14:28

使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

13264653206 发表于 2020-5-30 21:49

奈何col 发表于 2020-5-30 14:28
使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

谢谢大佬,这问题我卡了好久,就是不知道哪出问题了,今天试了下新库,可以了;P

Tahngarth 发表于 2020-5-31 02:05

奈何col 发表于 2020-5-30 14:28
使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

太感谢了终于解决了:D

时光星星 发表于 2020-6-15 21:10

13264653206 发表于 2020-5-30 21:49
谢谢大佬,这问题我卡了好久,就是不知道哪出问题了,今天试了下新库,可以了 ...

小哥,我也有这样的问题,这lib是什么,能分享一下改好后的代码不

hanweiyang 发表于 2020-6-16 01:43

奈何col 发表于 2020-5-30 14:28
使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

为什么我更了最新的库还是不行 只能用blinker软件控制 小爱同学不行
页: [1] 2
查看完整版本: 新手求助!blinker同步到米家,但手机里的小爱控制不了ESP8266