查看: 1204|回复: 13

[已解答] 新手求助!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 | 显示全部楼层
程序里面有些是可以省略的,但感觉这些都不是关键,之前我是直接用官网给的程序也是不行。
  • TA的每日心情
    郁闷
    2018-12-6 22:21
  • 签到天数: 48 天

    [LV.5]常住居民I

    发表于 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开关了一下灯没有问题,小爱还是不行
  • TA的每日心情
    郁闷
    2018-12-6 22:21
  • 签到天数: 48 天

    [LV.5]常住居民I

    发表于 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

    太感谢了终于解决了
  • TA的每日心情
    开心
    2020-6-15 21:13
  • 签到天数: 1 天

    [LV.1]初来乍到

    发表于 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软件控制 小爱同学不行
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    热门推荐

    5分钟带你快速了解新一代开发板:M5STACK
    5分钟带你快速了解新一代
    一、什么是M5Stack M5Stack是一种模块化、可堆叠扩展的开发板,每个模块
    创客火首发无人机编队套装,开启不一样的人工智能教育
    创客火首发无人机编队套装
    2017年国务院发布《新一代人工智能发展规划》,提出要广泛开展人工智能科普活动,在中
    胸卡式儿童红花榜(blinker+三色墨水屏)
    胸卡式儿童红花榜(blinke
    【项目名称】胸卡式儿童红花榜【项目简介】 小朋友有很强的自尊心和荣誉感,也有自
    ADAFRUIT_GFX库 tft屏真彩图怎么取模
    ADAFRUIT_GFX库 tft屏真彩
    请问这种16位的是用什么软件取的,网上找了好久取模软件,取的都是8位的
    温度传感器实验求代码
    温度传感器实验求代码
    求详细代码,急!
    Copyright   ©2015-2016  Arduino中文社区  Powered by©Discuz!   
    快速回复 返回顶部 返回列表