UIFlow Guide
from m5stack import *
from m5ui import *
from uiflow import *
from IoTcloud.Ali import AliIoT
import json
import time
import unit
setScreenColor(0x222222)
env2_0 = unit.get(unit.ENV2, unit.PORTA)
shadow_msg = None
raw_msg = None
user_msg = None
label0 = M5TextBox(16, 17, "Text", lcd.FONT_Default, 0xFFFFFF, rotate=0)
def shadow_get_cb(payload):
global shadow_msg, raw_msg, user_msg
shadow_msg = payload
label0.setText(str(shadow_msg))
pass
def raw_down_cb(payload):
global shadow_msg, raw_msg, user_msg
raw_msg = payload
label0.setText(str(raw_msg))
pass
def user_get_cb(payload):
global shadow_msg, raw_msg, user_msg
user_msg = payload
label0.setText(str(user_msg))
pass
ali = AliIoT(device_id='223', product_key='a1kJNBURsxj', device_name='ENV_UNIT', region_id='cn-shanghai', password='CB57870ED7708E24863DF9A7BD8A65BE')
ali.subscribe_shadow_get_msg(shadow_get_cb)
ali.subscribe_raw_down_msg(raw_down_cb)
ali.subscribe_user_get_msg(user_get_cb)
ali.start()
while True:
ali.publish_user_update_msg(str((json.dumps(({'Pressure':(env2_0.pressure),'Temperature':(env2_0.temperature),'Humidity':(env2_0.humidity)})))))
ali.publish_shadow_update_msg(desiredStr='DEVICE_STATE')
ali.publish_raw_up_msg(str('RAW MSG'))
wait(3)
wait_ms(2)
from IoTcloud.Ali import AliIoT
ali = AliIoT(device_id='', product_key='', device_name='', region_id='cn-qingdao', password='')
ali.start()
ali.publish_raw_up_msg(str('RAW MSG'))
ali.publish_shadow_update_msg(desiredStr='DEVICE_STATE')
ali.publish_user_update_msg(str((json.dumps(({'Pressure':(env2_0.pressure),'Temperature':(env2_0.temperature),'Humidity':(env2_0.humidity)})))))
def raw_down_cb(payload):
global shadow_msg, raw_msg, user_msg
raw_msg = payload
pass
ali.subscribe_raw_down_msg(raw_down_cb)
def shadow_get_cb(payload):
global shadow_msg, raw_msg, user_msg
shadow_msg = payload
pass
ali.subscribe_shadow_get_msg(shadow_get_cb)
def user_get_cb(payload):
global shadow_msg, raw_msg, user_msg
user_msg = payload
pass
ali.subscribe_user_get_msg(user_get_cb)