mirror of
https://gitee.com/quecpython/helios-service.git
synced 2025-05-19 06:08:22 +08:00
57 lines
1.5 KiB
Python
57 lines
1.5 KiB
Python
"""
|
|
使用云服务之前, 需要传入配置文件, 并启动云服务, 详见进阶篇中的操作使用云服务
|
|
"""
|
|
|
|
from usr.bin.guard import GuardContext
|
|
import utime
|
|
|
|
# 刷新容器
|
|
guard_context = GuardContext()
|
|
guard_context.refresh()
|
|
|
|
# 获取云服务
|
|
cloud_ser = guard_context.get_server("cloud")
|
|
"==============================================第一种方法==================================="
|
|
"""
|
|
这是非同步的, 所以需要sleep 2秒
|
|
"""
|
|
# # 加载优先级低的服务 并拉起
|
|
# guard_context.reload()
|
|
#
|
|
# # 等待下载, 因为是异步的这里可以等待2s
|
|
# utime.sleep(2)
|
|
# if cloud_ser.get_app_code() == "3001":
|
|
# # 重启设备
|
|
# pass
|
|
|
|
"=============================================第二种========================================"
|
|
"""
|
|
此为订阅此升级事件
|
|
"""
|
|
def func(*args, **kwargs):
|
|
"""
|
|
|
|
:param args: ('anonymous',) 发送人, 默认是'anonymous'无需关心
|
|
:param kwargs: 格式如下
|
|
{
|
|
'message':{
|
|
'message_id':2, # 消息ID
|
|
'sender':'anonymous', # 发送人
|
|
'message':'xxx', # 来的消息,
|
|
'from_event':'CLOUD', # 从哪个事件或服务来的
|
|
'msg_type':255 # 消息类型, 默认是255
|
|
}
|
|
}
|
|
:return:
|
|
"""
|
|
if kwargs['message']['message'] == '3001':
|
|
# 重启模块, 调用power接口
|
|
pass
|
|
|
|
|
|
# 订阅服务
|
|
cloud_ser.subscribe(func)
|
|
|
|
# reload容器
|
|
guard_context.reload()
|