python 如何订阅小米小爱消息-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2051|回复: 0

[过期] python 如何订阅小米小爱消息

[复制链接]
发表于 2020-4-4 17:47 | 显示全部楼层 |阅读模式
连接时返回的状态码一直是2。
基于这篇文章的代码修改https://blog.csdn.net/ruoyusixian/article/details/104368894。

请问为什么会问题的原因是在什么地方。

# 获取信息
def getInfo(auth):
    host = 'https://iot.diandeng.tech'
    url = '/api/v1/user/device/diy/auth?authKey=' + auth
    print(host + url)
    data = requests.get(host + url).json()
    return data
       
requests.get("https://iot.diandeng.tech/api/v1/user/device/diy/auth?authKey="+key+"&miType=light&version=1.2.2")
info = getInfo(auth)

# 设置设备类型
client_id = info['detail']['deviceName']
server = "public.iot-as-mqtt.cn-shanghai.aliyuncs.com"
user = info['detail']['iotId']
pwd = info['detail']['iotToken']
subtopic = "/" + info['detail']['productKey'] + "/" + info['detail']['deviceName'] + "/r"# 拉的主题
pubtopic = "/" + info['detail']['productKey'] + "/" + info['detail']['deviceName'] + "/s"# 推的主题
print(subtopic,"/r",pubtopic)

# 连接成功的回调函数
def on_connect(client, userdata, flags, rc):
    print("Ne session being set .", rc)//打印rc结果为2

client = mqtt.Client(client_id=client_id)
client.username_pw_set(user, pwd)
client.on_connect = on_connect
client.on_message = on_message
client.connect(server, 1883, 60)


您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

GMT+8, 2024-11-28 07:32 , Processed in 0.069123 second(s), 16 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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