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

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 8484|回复: 16

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

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

微信图片_20200530022722.jpg 微信图片_20200530022712.jpg 微信图片_20200530022728.jpg 微信图片_20200530022730.jpg 微信图片_20200530023207.jpg
#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();
}

 楼主| 发表于 2020-5-30 02:43 | 显示全部楼层
程序里面有些是可以省略的,但感觉这些都不是关键,之前我是直接用官网给的程序也是不行。
发表于 2020-5-30 12:20 | 显示全部楼层
看看调试信息,是否正常收到控制指令
 楼主| 发表于 2020-5-30 12:46 | 显示全部楼层
[64]
__       __                __
/\ \     /\ \    __        /\ \              v0.3.3
\ \ \___ \ \ \  /\_\    ___\ \ \/'\      __   _ __   
\ \ '__`\\ \ \ \/\ \ /' _ `\ \ , <    /'__`\/\`'__\
  \ \ \L\ \\ \ \_\ \ \/\ \/\ \ \ \\`\ /\  __/\ \ \./
   \ \_,__/ \ \__\\ \_\ \_\ \_\ \_\ \_\ \____\\ \_\  
    \/___/   \/__/ \/_/\/_/\/_/\/_/\/_/\/____/ \/_/  
    To better use blinker with your IoT project!
    Download latest blinker library here!
    => https://github.com/blinker-iot/blinker-library

[97] _aliType:
[99] _duerType:
[100] _miType: &miType=light
[103] _authKey: 590125f169cb
[105] Connecting to Tahngarth-ME
[112] ESP8266_MQTT initialized...
[112]
===========================================================
================== Blinker Timer loaded! ==================
Warning!EEPROM address 1536-2431 is used for Blinker Timer!
============= DON'T USE THESE EEPROM ADDRESS! =============
===========================================================

[140] countdown state: false
[141] _cdRunState: 0
[143] _totalTime: 0
[145] _runTime: 0
[146] _action:
[148] loop state: false
[150] _lpRunState: 0
[152] _times: 0
[153] _tri_times: 0
[155] _time1: 0
[156] _action1:
[158] _time2: 0
[160] _action2:
[161] _lpData: 0
[163] checkNum count: 1
[1185] WiFi Connected.
[1186] IP Address:
[1186] 192.168.1.102
[1197] [HTTP] begin: https://iot.diandeng.tech/api/v1/user/device/diy/auth?authKey=590125f169cb&miType=light
[3362] [HTTP] GET... code: 200
[3369] reply was:
[3369] ==============================
[3369] {"detail": {"broker": "aliyun", "deviceName": "F51B77C42SR90D1B877V1LGS", "iotId": "zD6g5EiG2AwIvNHPnfTd000000", "iotToken": "^1^1590813831808^9c8b70634e97fd5", "productKey": "JgCGbHlndgz", "uuid": "f9ce4d425917d7c7091fd643478151f6"}, "message": 1000}
[3385] ==============================
[3390] ====================
[3391] DEVICE_NAME_MQTT: F51B77C42SR90D1B877V1LGS
[3396] MQTT_PRODUCTINFO_MQTT: JgCGbHlndgz
[3399] MQTT_ID_MQTT: F51B77C42SR90D1B877V1LGS
[3403] MQTT_NAME_MQTT: zD6g5EiG2AwIvNHPnfTd000000
[3408] MQTT_KEY_MQTT: ^1^1590813831808^9c8b70634e97fd5
[3413] MQTT_BROKER: aliyun
[3415] HOST: public.iot-as-mqtt.cn-shanghai.aliyuncs.com
[3420] PORT: 1883
[3422] UUID_MQTT: f9ce4d425917d7c7091fd643478151f6
[3426] ====================
[3429] BLINKER_PUB_TOPIC_MQTT: /JgCGbHlndgz/F51B77C42SR90D1B877V1LGS/s
[3435] BLINKER_SUB_TOPIC_MQTT: /JgCGbHlndgz/F51B77C42SR90D1B877V1LGS/r
[3441] Freeheap: 10080
[3447] mDNS responder started
[3448] webSocket_MQTT server started
[3449] ws://F51B77C42SR90D1B877V1LGS.local:81
[16466] Current time: Sat May 30 04:44:04 2020

[16466] NTP time: 1590785044
[16467] time (millis() - ntpFreshTime): 16467
[16467] ntpGetTime: 0
[16468] 1
[16469] ==== needInit ====
[16472] message: /share/device?deviceName=F51B77C42SR90D1B877V1LGS&key=590125f169cb
[16479] blinker server begin
[16482] Freeheap: 31256
[17505] HTTPS begin: https://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=F51B77C42SR90D1B877V1LGS&key=590125f169cb
[17505] HTTPS payload: /share/device?deviceName=F51B77C42SR90D1B877V1LGS&key=590125f169cb
[17513] [HTTP] status... code: 200
[17517] {"detail": {"users": []}, "message": 1000}
[17521] payload: {"users":[]}
[17526] sharers data: {"users":[]}
[17527] load timing
[17529] load timing taskCount: 0
[17531] freshTiming wDay: 6, nowMins: 284, nowSeconds: 17045
[17537] nextTask: 10  apartSeconds: 69355 wDay: 6
[17541] cbackData: 10
[17543] change apartSeconds: 3600
[17647] Connecting to MQTT...
[18930] MQTT Connected!
[18930] Freeheap: 10440
[18930] millis: 18930, connect_time: 16469
[18930] MQTT conn init success
[38883] Got: {"deviceType":"DiyArduino","data":{"get":"state"},"fromDevice":"f9ce4d425917d7c7091fd643478151f6","toDevice":"F51B77C42SR90D1B877V1LGS"}
[38886] data: {"get":"state"}
[38888] fromDevice: f9ce4d425917d7c7091fd643478151f6
[38893] Authority uuid
[38915] parse data: {"get":"state"}
[38915] defined BLINKER_ARDUINOJSON
[38916] autoFormatData key: state, json: "state":"online"
[38916] new.
[38917] timer codes: 000
[38919] autoFormatData key: timer, json: "timer":"000"
[38924] add.
[38925] autoFormatData key: version, json: "version":"0.1.0"
[38930] add.
[38932] print: {"state":"online","timer":"000","version":"0.1.0"}
[38937] Proto print...
[38939] Freeheap: 7576
[38942] isJson: {"data":{"state":"online","timer":"000","version":"0.1.0"},"fromDevice":"F51B77C42SR90D1B877V1LGS","toDevice":"f9ce4d425917d7c7091fd643478151f6","deviceType":"OwnApp"}
[38958] MQTT Publish...
[38960] Freeheap: 7576
[39061] {"data":{"state":"online","timer":"000","version":"0.1.0"},"fromDevice":"F51B77C42SR90D1B877V1LGS","toDevice":"f9ce4d425917d7c7091fd643478151f6","deviceType":"OwnApp"}
[39065] ...OK!
[39066] Freeheap: 7576
[39068] Freeheap: 8608
[39070] heartBeat isParsed
[39073] checkNum count: 1
[39075] isParsed
[39187] num: 0, Connected from: 192.168.1.31, url: /
[40887] num: 0, get Text: {"get":"state"}, length: 15
[40907] parse data: {"get":"state"}
[40907] defined BLINKER_ARDUINOJSON
[40909] autoFormatData key: state, json: "state":"online"
[40909] new.
[40909] timer codes: 000
[40911] autoFormatData key: timer, json: "timer":"000"
[40916] add.
[40917] autoFormatData key: version, json: "version":"0.1.0"
[40923] add.
[40924] print: {"state":"online","timer":"000","version":"0.1.0"}
[40930] Proto print...
[40932] Freeheap: 7968
[40934] WS response:
[40936] {"state":"online","timer":"000","version":"0.1.0"}
[40941] Success...
[40944] Freeheap: 8328
[40945] heartBeat isParsed
[40947] checkNum count: 1
[40950] isParsed
[42057] num: 0, get Text: {"abc":"on"}, length: 12
[42078] parse data: {"abc":"on"}
[42078] defined BLINKER_ARDUINOJSON
[42079] checkNum count: 1
[42079] strWidgetsParse isParsed
[42079] strWidgetsParse: abc
[42081] get button state: on
[42084] isParsed
[43210] num: 0, get Text: {"abc":"on"}, length: 12
[43231] parse data: {"abc":"on"}
[43231] defined BLINKER_ARDUINOJSON
[43232] checkNum count: 1
[43232] strWidgetsParse isParsed
[43232] strWidgetsParse: abc
[43234] get button state: on
[43236] isParsed
[47843] num: 0, get Text: {"abc":"on"}, length: 12
[47863] parse data: {"abc":"on"}
[47864] defined BLINKER_ARDUINOJSON
[47865] checkNum count: 1
[47865] strWidgetsParse isParsed
[47865] strWidgetsParse: abc
[47867] get button state: on
[47869] isParsed
[51170] num: 0, get Text: {"abc":"on"}, length: 12
[51191] parse data: {"abc":"on"}
[51191] defined BLINKER_ARDUINOJSON
[51192] checkNum count: 1
[51192] strWidgetsParse isParsed
[51192] strWidgetsParse: abc
[51194] get button state: on
[51196] isParsed
[69070] MQTT Ping!
[69070] Freeheap: 10072
[95979] Disconnected! 0
[99646] MQTT Ping!
[99646] Freeheap: 10360
 楼主| 发表于 2020-5-30 12:46 | 显示全部楼层
我用blinker开关了一下灯没有问题,小爱还是不行
发表于 2020-5-30 14:28 | 显示全部楼层
发表于 2020-5-30 21:49 | 显示全部楼层
奈何col 发表于 2020-5-30 14:28
使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

谢谢大佬,这问题我卡了好久,就是不知道哪出问题了,今天试了下新库,可以了
 楼主| 发表于 2020-5-31 02:05 | 显示全部楼层
奈何col 发表于 2020-5-30 14:28
使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

太感谢了终于解决了
发表于 2020-6-15 21:10 | 显示全部楼层
13264653206 发表于 2020-5-30 21:49
谢谢大佬,这问题我卡了好久,就是不知道哪出问题了,今天试了下新库,可以了 ...

小哥,我也有这样的问题,这lib是什么,能分享一下改好后的代码不
发表于 2020-6-16 01:43 | 显示全部楼层
奈何col 发表于 2020-5-30 14:28
使用最新的lib
https://github.com/blinker-iot/blinker-library/tree/dev_3.0

为什么我更了最新的库还是不行 只能用blinker软件控制 小爱同学不行
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 13:55 , Processed in 0.079364 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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