@csierra67 Python's API, blockl does not yet exist.
import M5
# Battery percentage
M5.Power.getBatteryLevel()
# set Charge Current
M5.Power.setChargeCurrent()
@csierra67 Python's API, blockl does not yet exist.
import M5
# Battery percentage
M5.Power.getBatteryLevel()
# set Charge Current
M5.Power.setChargeCurrent()
@kotobuki After init, wifi sta needs to be activated.
@mumin50 Yes, this feature is coming soon.
@smatlok @ajb2k3 There is an ADC class in the unit module, which is the abstract class of the ADC unit, and it conflicts with the class name of machine.ADC. It will be fixed in the next version.
@Nestor89 Thanks, you're right, it's a bug.
At present, the timing query is implemented through the soft timer, and only the last timer may take effect.
version: Alpha-17
import os, sys, io
import M5
from M5 import *
from umqtt import *
label0 = None
label2 = None
label1 = None
label3 = None
mqtt_client = None
def mqtt_testtopic_event(data):
global label0, label2, label1, label3, mqtt_client
label0.setText(str(((str('Topic:') + str((data[0]))))))
label1.setText(str(((data[1]).decode())))
def mqtt_testtopic1_event(data):
global label0, label2, label1, label3, mqtt_client
label2.setText(str(((str('Topic:') + str((data[0]))))))
label3.setText(str(((data[1]).decode())))
def setup():
global label0, label2, label1, label3, mqtt_client
M5.begin()
label0 = Widgets.Label("Text", 4, 3, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label2 = Widgets.Label("Text", 4, 55, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label1 = Widgets.Label("Text", 4, 29, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
label3 = Widgets.Label("Text", 3, 81, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
mqtt_client = MQTTClient('umqtt_client', '192.168.2.50', port=1883, user='m5stack', password='m5stack', keepalive=0)
mqtt_client.connect(clean_session=True)
mqtt_client.subscribe('testtopic', mqtt_testtopic_event, qos=0)
mqtt_client.subscribe('testtopic1', mqtt_testtopic1_event, qos=0)
label0.setFont(Widgets.FONTS.DejaVu12)
label1.setFont(Widgets.FONTS.DejaVu12)
label2.setFont(Widgets.FONTS.DejaVu12)
label3.setFont(Widgets.FONTS.DejaVu12)
def loop():
global label0, label2, label1, label3, mqtt_client
M5.update()
mqtt_client.wait_msg()
if __name__ == '__main__':
try:
setup()
while True:
loop()
except (Exception, KeyboardInterrupt) as e:
try:
from utility import print_error_msg
print_error_msg(e)
except ImportError:
print("please update to latest firmware")
test_mqtt.m5f2
{"version":"V2.0","type":"atoms3","components":[{"name":"screen","type":"screen","layer":0,"screenId":"","screenName":"","id":"__atoms3_screen","createTime":1681463262614,"x":0,"y":0,"width":280,"height":280,"backgroundColor":"#000","size":0},{"name":"label0","type":"label","layer":1,"screenId":"builtin","screenName":"","id":"v^k&_0&lzY#a-pVu","createTime":1681787932237,"x":4,"y":3,"color":"#ffffff","backgroundColor":"#222222","text":"Text","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0},{"name":"label1","type":"label","layer":2,"screenId":"builtin","screenName":"","id":"lg-u6bmP&KAb-BFg","createTime":1681787940036,"x":4,"y":29,"color":"#ffffff","backgroundColor":"#222222","text":"Text","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0},{"name":"label2","type":"label","layer":1,"screenId":"builtin","screenName":"","id":"m+Am3fMqYyQ$+VEm","createTime":1681788301006,"x":4,"y":55,"color":"#ffffff","backgroundColor":"#222222","text":"Text","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0,"width":37,"height":20},{"name":"label3","type":"label","layer":2,"screenId":"builtin","screenName":"","id":"fj^rW#mTo@K0dL5r","createTime":1681788303358,"x":3,"y":81,"color":"#ffffff","backgroundColor":"#222222","text":"Text","engine":"gfx","font":"Widgets.FONTS.DejaVu18","rotation":0,"width":37,"height":20}],"resources":[{"software":["mqtt"]}],"units":[],"hats":[],"i2cs":[],"blockly":"<block type=\"basic_on_loop\" id=\"loop_block\" deletable=\"false\" x=\"490\" y=\"70\"><mutation isUpdate=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_update\" id=\"system_m5_update\"><next><block type=\"mqtt_wait_msg\" id=\"T1rVj/Q%g){|@a=eic@f\"></block></next></block></statement></block><block type=\"basic_on_setup\" id=\"setup_block\" deletable=\"false\" x=\"130\" y=\"110\"><mutation isBegin=\"true\"></mutation><field name=\"UPDATEOP\">true</field><statement name=\"FUNC\"><block type=\"system_m5_begin\" id=\"system_m5_begin\"><next><block type=\"mqtt_set_client\" id=\"g+(|o=#m4jpn7OLPkw)J\"><value name=\"ID\"><shadow type=\"text\" id=\"?[M!b8*f#bx*SpMXH!!5\"><field name=\"TEXT\">umqtt_client</field></shadow></value><value name=\"SERVER\"><shadow type=\"text\" id=\"oNzSR(TF-,inxj~YS2}#\"><field name=\"TEXT\">192.168.2.76</field></shadow></value><value name=\"PORT\"><shadow type=\"math_number\" id=\"e~GXuZ!~qfASA;IYe3f=\"><mutation max=\"Infinity\" min=\"-Infinity\" precision=\"0\"></mutation><field name=\"NUM\">1883</field></shadow></value><value name=\"USER\"><shadow type=\"text\" id=\"3PbUi]|zTswyRzP*h=Zm\"><field name=\"TEXT\">m5stack</field></shadow></value><value name=\"PASSWORD\"><shadow type=\"text\" id=\"d.(iU%~um%@j5=N8C!9:\"><field name=\"TEXT\">m5stack</field></shadow></value><value name=\"KEEPALIVE\"><shadow type=\"math_slider\" id=\"4lCv3Yqkt^hJHwEHH,R)\"><mutation max=\"65535\" min=\"0\" step=\"1\" precision=\"1\"></mutation><field name=\"NUM\">0</field></shadow></value><next><block type=\"mqtt_connect\" id=\"N$GCr?UqrYp~!@[yZfZ~\"><field name=\"CLEAN\">True</field><next><block type=\"label_set_font\" id=\"sBjX6,JwP2hIWbkZU]#L\"><field name=\"NAME\">label0</field><field name=\"FONT\">Widgets.FONTS.DejaVu12</field><next><block type=\"label_set_font\" id=\"l{(uGTFfhsb)s(6iS/hU\"><field name=\"NAME\">label1</field><field name=\"FONT\">Widgets.FONTS.DejaVu12</field><next><block type=\"label_set_font\" id=\"Rn6r~[cLiSQf+]nM8sTq\"><field name=\"NAME\">label2</field><field name=\"FONT\">Widgets.FONTS.DejaVu12</field><next><block type=\"label_set_font\" id=\"oaK+AUCEaQtl@kR^|jP;\"><field name=\"NAME\">label3</field><field name=\"FONT\">Widgets.FONTS.DejaVu12</field></block></next></block></next></block></next></block></next></block></next></block></next></block></statement></block><block type=\"mqtt_subscribe\" id=\"w7Ov@_:I,|/99:[91gQ+\" x=\"90\" y=\"570\"><value name=\"MSG\"><shadow type=\"text\" id=\"5+0D;yAI;M9Kab.KdV([\"><field name=\"TEXT\">testtopic</field></shadow></value><statement name=\"FUNC\"><block type=\"label_set_text\" id=\"qN{uc|lEU4,^0u_YYo@7\"><field name=\"NAME\">label0</field><value name=\"TEXT\"><shadow type=\"text\" id=\"5~k^hoGX6L}naX9o!pt=\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_add_str\" id=\"tAsN]8zdz!{wa]J5fQRj\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"NTGIBKM?0;M)9Q$?/F/E\"><field name=\"TEXT\">Topic:</field></shadow></value><value name=\"VALUE2\"><block type=\"mqtt_get_topic\" id=\"O)j9sIdBDlw?k(Y4#E{]\"></block></value></block></value><next><block type=\"label_set_text\" id=\"AIj|L5*V}(Na=i~]!Wr{\"><field name=\"NAME\">label1</field><value name=\"TEXT\"><shadow type=\"text\" id=\"9gNvISVfV@]35[tz`S6-\" disabled=\"true\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_decode_str\" id=\"}[Ilzb9o=Qd12AOz*Q/k\"><value name=\"VALUE\"><block type=\"mqtt_get_msg\" id=\"p48aW7MN4QcC/]H_RqLv\"></block></value></block></value></block></next></block></statement></block><block type=\"mqtt_subscribe\" id=\":g;Bc#f6bCJv3D=P,C24\" x=\"690\" y=\"550\"><value name=\"MSG\"><shadow type=\"text\" id=\"p!BP(rRWfzb8%w2;)|Z/\"><field name=\"TEXT\">testtopic1</field></shadow></value><statement name=\"FUNC\"><block type=\"label_set_text\" id=\"+{@FB5tyv:a,[(0)S^?^\"><field name=\"NAME\">label2</field><value name=\"TEXT\"><shadow type=\"text\" id=\"5~k^hoGX6L}naX9o!pt=\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_add_str\" id=\"MOXaUlFRx59,!q}DPD;6\"><value name=\"VALUE1\"><shadow type=\"text\" id=\"ABnF09VK)vlEkGQ|B9P*\"><field name=\"TEXT\">Topic:</field></shadow></value><value name=\"VALUE2\"><block type=\"mqtt_get_topic\" id=\"3w2H7IRX7ZEIXgo$ZPFE\"></block></value></block></value><next><block type=\"label_set_text\" id=\"sAd`+qhCgZXd{Kt,+h$r\"><field name=\"NAME\">label3</field><value name=\"TEXT\"><shadow type=\"text\" id=\"9gNvISVfV@]35[tz`S6-\" disabled=\"true\"><field name=\"TEXT\">Label</field></shadow><block type=\"text_decode_str\" id=\"(3lEfMbcJYt7tw_fl=%3\"><value name=\"VALUE\"><block type=\"mqtt_get_msg\" id=\"YAAO(q1I]VjM1vGhYh2R\"></block></value></block></value></block></next></block></statement></block>","screen":[{"simulationName":"Built-in","type":"builtin","width":128,"height":128,"scale":1.3,"screenName":"","blockId":"","id":"builtin","createTime":1681463262611}]}