UI Flow MQTT code on M5Stack Core works when run from flow.m5stack.com but not (MQTTException -> 128) when downloaded to device



  • I used a Win 11 laptop for development and using M5Burner burned the v1.10.9 UI Flow firmware to M5 Core device and configure its WiFi to my local SSID.

    I next connected to the device (which is successfully online in internet mode) to xxxxxxxx from https://flow.m5stack.com/

    I then made a minimal MQTT connect and publish program to a public test MQTT broker and published a message.

    from m5stack import *
    from m5ui import *
    from uiflow import *
    from m5mqtt import M5mqtt

    setScreenColor(0x222222)

    m5mqtt = M5mqtt('kilnageer', 'test.mosquitto.org', 1883, '', '', 300)
    m5mqtt.start()
    m5mqtt.publish(str('kilnageer/test'), str('hello'), 0)

    I tested the public broker with the following code..

    pi@tola-smarthome-v3:~ $ mosquitto_sub -h test.mosquitto.org -t kilnageer/test &
    1 9842
    pi@tola-smarthome-v3:~ $
    pi@tola-smarthome-v3:~ $ mosquitto_pub -h test.mosquitto.org -t kilnageer/test -m "hi"
    pi@tola-smarthome-v3:~ $ hi

    pi@tola-smarthome-v3:~ $

    pi@tola-smarthome-v3:~ $ hello

    pi@tola-smarthome-v3:~ $
    pi@tola-smarthome-v3:~ $ date
    Mon 28 Nov 09:50:57 GMT 2022
    pi@tola-smarthome-v3:~ $

    So seeing "hello" proves the running the code works..

    Also running a web terminal to the device at this time showed no errors:

    Next I downloaded the code (main.m5f) to the device and so changed it from "internet" mode to "app" mode.

    Now I now longer see the message published and the terminal shows and MQTT error:

    APIKEY: xxxxxxxx
    MicroPython 77320d1de-dirty on 2022-11-24; M5Stack with ESP32
    Type "help()" for more information.
    >>> [2495] MQTTException -> 128
    reconnect start ...
    reconnect finish ...

    Also when I was developing the real code and connecting to a local Pi based MQTT broker I could see that the connection was never made (in the failing case) by looking at the mosquitto logs.

    pi@tola-smarthome-v3:~ $ sudo tail -f /var/log/mosquitto/mosquitto.log
    1669623877: New connection from 192.168.3.15 on port 1883.
    1669623877: New client connected from 192.168.3.15 as mqttdash-10aaf3d5 (c1, k30, u'tola').
    1669624454: Socket error on client mqttdash-10aaf3d5, disconnecting.

    But I could see the connecting being made by the M5Stack client when I just ran the code from the web console.



  • Hello @kilnageer

    when the code is downloaded to the device and is run in app mode, WiFi might no longer be connected. Try adding below blocks to your program to ensure WiFi is connected.

    0_1669632749798_UiFlowWiFi_20221128.png

    Thanks
    Felix



  • Thanks Felix. That worked like a dream. I had though of doing that and then strayed to the dark side of Tasmota and Berry UI! Which is a pity because the UI Flow web GUI is superb! Enjoy your day and thanks again! :) I guess a newbie error in that "run" mode makes use of the fact the boot firmware brings it online to use the Web GUI whereas when you "download" you must do everything yourself! Happy coding.



  • Hello @kilnageer

    you are welcome. Thank you for reporting back. I am happy to read that it worked for you.

    Same to you!

    Thanks
    Felix