UIFlow Guide
This program remotely controls the device via the MQTT protocol, monitoring the load’s voltage, current, and power, and starts a web server in AP mode to poll data. When button A is pressed, the relay state toggles (on/off), and the RGB LED color updates to indicate the status.
from m5stack import *
from m5ui import *
from uiflow import *
from base.Socket_Kit import Socket
import time
button_next = None
sock = Socket()
from numbers import Number
def buttonA_wasPressed():
global button_next
button_next = (button_next if isinstance(button_next, Number) else 0) + 1
if button_next == 1:
sock.set_relay_state(1)
elif button_next == 2:
sock.set_relay_state(0)
button_next = 0
pass
btnA.wasPressed(buttonA_wasPressed)
button_next = 0
sock.remote_control(1)
print(sock.pub_topic)
print((str('This is Subscribe Topic(Relay State), Use Remote User: ') + str((sock.sub_topic_relay))))
print((str('This is Subscribe Topic(Parameter Status), Use Remote User: ') + str((sock.sub_topic_data))))
while True:
if sock.wait_update_data():
print((str('Voltage(V): ') + str((sock.get_voltage()))))
print((str('Current(mA): ') + str((sock.get_current()))))
print((str('Power(W): ') + str((sock.get_active_power()))))
sock.server_loop()
wait(1)
button_next = int((sock.get_relay_status()))
if button_next:
rgb.setColorAll(0x009900)
else:
rgb.setColorAll(0xff0000)
wait_ms(2)
sock.pub_topic
sock.sub_topic_relay
sock.get_active_power()
sock.get_current()
sock.get_voltage()
sock.get_relay_status()
sock.remote_control(1)
sock.server_loop()
sock.set_relay_state(1)
sock.wait_update_data()