【求助】Blinker接入MIOT
我先用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)
# -*- coding: utf-8 -*-
"""
天猫精灵接入
"""
__author__ = 'stao'
from blinker import Device
from blinker.voice_assistant import VoiceAssistant, VAType, MiLightMode, PowerMessage, ModeMessage, ColorMessage, \
ColorTempMessage, BrightnessMessage, DataMessage
async def power_change(message: PowerMessage):
""" 电源状态改变(适用于灯和插座)
"""
set_state = message.data["pState"]
print("change power state to : {0}".format(set_state))
if set_state == "on":
pass
elif set_state == "off":
pass
await (await message.power(set_state)).update()
async def mode_change(message: ModeMessage):
""" 模式改变(适用于灯和插座)
"""
mode = message.data["mode"]
print("change mode to {0}".format(mode))
if mode == MiLightMode.READING:
pass
elif mode == MiLightMode.MOVIE:
pass
elif mode == MiLightMode.SLEEP:
pass
elif mode == MiLightMode.HOLIDAY:
pass
elif mode == MiLightMode.MUSIC:
pass
elif mode == MiLightMode.COMMON:
pass
await (await message.mode(mode)).update()
async def color_change(message: ColorMessage):
""" 颜色改变(适用于灯)
支持的颜色:Red红色\Yellow黄色\Blue蓝色\Green绿色\White白色\Black黑色\Cyan青色\Purple紫色\Orange橙色
"""
color = message.data["col"]
print("change color to {0}".format(color))
await (await message.color(color)).update()
async def colorTemp_change(message: ColorTempMessage):
"""色温改变(适用于灯)
"""
color_temp = message.data["colTemp"]
print("change color temp to {0}".format(color_temp))
await (await message.colorTemp(100)).update()
async def brightness_change(message: BrightnessMessage):
""" 亮度改变(适用于灯)
"""
if "bright" in message.data:
brightness = int(message.data["bright"])
elif "upBright" in message.data:
brightness = int(message.data["upBright"])
elif "downBright" in message.data:
brightness = int(message.data["downBright"])
else:
brightness = 50
print("change brightness to {0}".format(brightness))
await (await message.brightness(brightness)).update()
async def state_query(message: DataMessage):
print("query state: {0}".format(message.data))
await message.power("on")
await message.mode(MiLightMode.DAY)
await message.color("red")
await message.brightness(66)
await message.update()
device = Device("*******", mi_type=VAType.LIGHT)
voice_assistant = VoiceAssistant(VAType.LIGHT)
voice_assistant.mode_change_callable = mode_change
voice_assistant.colortemp_change_callable = colorTemp_change
voice_assistant.color_change_callable = color_change
voice_assistant.brightness_change_callable = brightness_change
voice_assistant.state_query_callable = state_query
voice_assistant.power_change_callable = power_change
device.addVoiceAssistant(voice_assistant)
if __name__ == '__main__':
device.run() 原本使用点灯APP进行控制都是没有问题 说明MQTT连接都是正常的 之前使用Arduino开发过 所以小爱同学的绑定也弄过这次重新绑定了 没有啥问题 附几张图片
页:
[1]