【求助】Blinker接入MIOT-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 520|回复: 2

【求助】Blinker接入MIOT

[复制链接]
发表于 2022-4-14 15:05 | 显示全部楼层 |阅读模式
我先用ESP-IDF开发接入MIOT作为LIGHT设备使用,但是用小爱同学控制时,提示“小爱和设备沟通失败”。
然后我尝试使用Python Blinker库进行接入,结果是同样的效果
python运行log:
2022-04-14 15:00:50.280 | INFO     | blinker.mqttclient:send_to_voiceassistant:115 - send mqtt message to voice assistant: {"fromDevice": "FB21DF3B1JM4UX3QQKPUSSIP", "toDevice": "ServerReceiver", "data": {"pState": "true", "mode": "day", "color": "red", "brightness": "66", "messageId": "6257c6a39eee0595"}}
python接入代码就是在例程上面改动的,从log上看 程序确实对小爱的请求做了反馈,同时wireshark也可以抓到通讯的报文,但是小爱同学接入就是不成功。


附代码:(例程基础上就改了下key)

  1. # -*- coding: utf-8 -*-

  2. """
  3. 天猫精灵接入
  4. """

  5. __author__ = 'stao'

  6. from blinker import Device
  7. from blinker.voice_assistant import VoiceAssistant, VAType, MiLightMode, PowerMessage, ModeMessage, ColorMessage, \
  8.     ColorTempMessage, BrightnessMessage, DataMessage


  9. async def power_change(message: PowerMessage):
  10.     """ 电源状态改变(适用于灯和插座)
  11.     """

  12.     set_state = message.data["pState"]
  13.     print("change power state to : {0}".format(set_state))

  14.     if set_state == "on":
  15.         pass
  16.     elif set_state == "off":
  17.         pass

  18.     await (await message.power(set_state)).update()


  19. async def mode_change(message: ModeMessage):
  20.     """ 模式改变(适用于灯和插座)
  21.     """

  22.     mode = message.data["mode"]
  23.     print("change mode to {0}".format(mode))

  24.     if mode == MiLightMode.READING:
  25.         pass
  26.     elif mode == MiLightMode.MOVIE:
  27.         pass
  28.     elif mode == MiLightMode.SLEEP:
  29.         pass
  30.     elif mode == MiLightMode.HOLIDAY:
  31.         pass
  32.     elif mode == MiLightMode.MUSIC:
  33.         pass
  34.     elif mode == MiLightMode.COMMON:
  35.         pass

  36.     await (await message.mode(mode)).update()


  37. async def color_change(message: ColorMessage):
  38.     """ 颜色改变(适用于灯)
  39.     支持的颜色:Red红色\Yellow黄色\Blue蓝色\Green绿色\White白色\Black黑色\Cyan青色\Purple紫色\Orange橙色
  40.     """

  41.     color = message.data["col"]
  42.     print("change color to {0}".format(color))
  43.     await (await message.color(color)).update()


  44. async def colorTemp_change(message: ColorTempMessage):
  45.     """色温改变(适用于灯)
  46.     """

  47.     color_temp = message.data["colTemp"]
  48.     print("change color temp to {0}".format(color_temp))
  49.     await (await message.colorTemp(100)).update()


  50. async def brightness_change(message: BrightnessMessage):
  51.     """ 亮度改变(适用于灯)
  52.     """

  53.     if "bright" in message.data:
  54.         brightness = int(message.data["bright"])
  55.     elif "upBright" in message.data:
  56.         brightness = int(message.data["upBright"])
  57.     elif "downBright" in message.data:
  58.         brightness = int(message.data["downBright"])
  59.     else:
  60.         brightness = 50

  61.     print("change brightness to {0}".format(brightness))
  62.     await (await message.brightness(brightness)).update()


  63. async def state_query(message: DataMessage):
  64.     print("query state: {0}".format(message.data))
  65.     await message.power("on")
  66.     await message.mode(MiLightMode.DAY)
  67.     await message.color("red")
  68.     await message.brightness(66)
  69.     await message.update()


  70. device = Device("*******", mi_type=VAType.LIGHT)
  71. voice_assistant = VoiceAssistant(VAType.LIGHT)
  72. voice_assistant.mode_change_callable = mode_change
  73. voice_assistant.colortemp_change_callable = colorTemp_change
  74. voice_assistant.color_change_callable = color_change
  75. voice_assistant.brightness_change_callable = brightness_change
  76. voice_assistant.state_query_callable = state_query
  77. voice_assistant.power_change_callable = power_change

  78. device.addVoiceAssistant(voice_assistant)

  79. if __name__ == '__main__':
  80.     device.run()
复制代码
 楼主| 发表于 2022-4-14 15:07 | 显示全部楼层
原本使用点灯APP进行控制都是没有问题 说明MQTT连接都是正常的 之前使用Arduino开发过 所以小爱同学的绑定也弄过  这次重新绑定了 没有啥问题
 楼主| 发表于 2022-4-14 15:46 | 显示全部楼层
附几张图片 Screenshot_2022-04-14-15-42-33-108_iot.clz.me.jpg 微信图片_20220414154404.jpg 1.jpg 屏幕截图 2022-04-14 154601.png

屏幕截图 2022-04-14 154601.png
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 09:40 , Processed in 0.075301 second(s), 18 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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