I am super impressed with m5flow coding blocks. Only problem is that on the m5core my code below only works when I press play, but not when I download the code on the device (it fails to connect to MQTT when code is downloaded but works fine when I just press play). Any help will be appreciated!
from m5ui import *
from uiflow import *
from m5mqtt import M5mqtt
setScreenColor(0x222222)
mqcount = None
angle = None
label0 = M5TextBox(8, 215, "Alive", lcd.FONT_Default, 0xFFFFFF, rotate=0)
alivecount = M5TextBox(69, 215, "0", lcd.FONT_Default, 0xFFFFFF, rotate=0)
circle0 = M5Circle(15, 113, 15, 0xFFFFFF, 0xFFFFFF)
label1 = M5TextBox(138, 156, "label1", lcd.FONT_Default, 0xFFFFFF, rotate=0)
from numbers import Number
def fun_f3f2_(topic_data):
global mqcount, angle
mqcount = (mqcount if isinstance(mqcount, Number) else 0) + 1
alivecount.setText(str(mqcount))
pass
@timerSch.event('timer1')
def ttimer1():
global mqcount, angle
m5mqtt.publish(str('f3f2'), str('alive'), 0)
pass
@timerSch.event('timer2')
def ttimer2():
global mqcount, angle
angle = (angle if isinstance(angle, Number) else 0) + 0.1
label1.setText(str(angle))
pass
m5mqtt = M5mqtt('f3f2', 'broker.emqx.io', 1883, '', '', 300)
m5mqtt.subscribe(str('f3f2'), fun_f3f2_)
m5mqtt.start()
mqcount = 0
angle = 0
timerSch.run('timer1', 1000, 0x00)
timerSch.run('timer2', 10, 0x00)```