移远EC600N 连接阿里云 --- 错误记录
作者:互联网
-v0.1 2021.6.29 Hans draft
'''
@Author: Pawn
@Date: 2020-09-28
@Description: example for module aLiYun
@FilePath: example_aliyun_file.py
'''
import log
import utime
import checkNet
from aLiYun import aLiYun
'''
下面两个全局变量是必须有的,用户可以根据自己的实际项目修改下面两个全局变量的值
'''
PROJECT_NAME = "QuecPython_AliYin_example"
PROJECT_VERSION = "1.0.0"
checknet = checkNet.CheckNetwork(PROJECT_NAME, PROJECT_VERSION)
# 设置日志输出级别
log.basicConfig(level=log.INFO)
aliYun_log = log.getLogger("ALiYun")
productKey = "a1G1GLnaODF" # 产品标识(参照阿里云应用开发指导)
productSecret = None # 产品密钥(使用一机一密认证时此参数传入None,参照阿里云应用开发指导)
DeviceName = "11102" # 设备名称(参照阿里云应用开发指导)
DeviceSecret = "8619793a70cb3fa2e8e8283c097fafec" # 设备密钥(使用一型一密认证此参数传入None,免预注册暂不支持,需先在云端创建设备,参照阿里云应用开发指导)
state = 5
# 回调函数
def sub_cb(topic, msg):
global state
aliYun_log.info("Subscribe Recv: Topic={},Msg={}".format(topic.decode(), msg.decode()))
state -= 1
if __name__ == '__main__':
stagecode, subcode = checknet.wait_network_connected(30)
if stagecode == 3 and subcode == 1:
aliYun_log.info('Network connection successful!')
# 创建aliyun连接对象
ali = aLiYun(productKey, productSecret, DeviceName, DeviceSecret)
# 设置mqtt连接属性
clientID = "mach6666ine" # 自定义字符(不超过64)
ali.setMqtt(clientID, clean_session=False, keepAlive=300)
# 设置回调函数
ali.setCallback(sub_cb)
topic = "/a1G1GLnaODF/11102/user/test" # 云端自定义或自拥有的Topic
# 订阅主题
ali.subscribe(topic)
# 发布消息
ali.publish(topic, "hello world")
# 运行
ali.start()
while 1:
if state:
pass
else:
ali.disconnect()
break
else:
aliYun_log.info('Network connection failed! stagecode = {}, subcode = {}'.format(stagecode, subcode))
以上代码运行现象如下
可以看出MQTT连接失败
解决: 修改阿里云产品地域
解释: 待更新
标签:__,topic,log,ali,EC600N,移远,---,阿里,aliYun 来源: https://blog.csdn.net/weixin_37756941/article/details/118341233