Has anyone gotten machine.lightsleep to work from UIflow?

  • I'm trying to use light sleep to extend battery life of a wrist clock on an M5Stick-C Plus. Source here: https://raw.githubusercontent.com/wsanders/M5StickC-Plus-Nixie-clock2/master/wmsclock_uiflow.png

    machine.lightsleep in the main loop of the program causes the device to eventually crash and reset. I've tried sleep settings between 10 and 1000 msec. Has anyone gotten this to work?

    In case WiFi was a contributing factor, I tried a "Disconnect Wifi" block but the code would not compile with the error

    Traceback (most recent call last):
      File "flow/m5cloud.py", line 76, in _exec_fun
      File "<string>", line 86, in <module>
    NameError: name 'wlan' isn't defined```
    Any other ways to turn off WiFi, etc, to save power?

  • Hello @wsanders

    using UIFlow firmware 1.9.5 machine.lightsleep() works for me in a simple loop where I turn on / off the LED. I've tried 100, 1000, 10000 ms successfully.

    For the Disconnect WiFi block to work you'll need to first call the Create Station Interface block which in turn will set wlan.


  • Thanks! Some success.

    Originally I was using the "Connect to WiFi" block, and UIFlow would not put the wifiCfg.doConnect call in a callback function or a try/except block, it ignored where I placed it in UIFlow and always put in near the top of the main part of the python. Because.....

    .... If I moved the wifiCfg.doConnect inside by hand into a callback in the python window, the code would crash immediately when the callback ran.

    This is a wristwatch program that can sync with NTP: What I've done is put all the network code in a button A+B callback so the program doesn't connect to the network at the start, only at the command of the user:


    Once the program is back in the main loop, I call machine.lightsleep for 500 msec at the bottom of every loop cycle. (A button press will not wake up lightsleep in UIFlow.) This presumably turns off WiFi. But, it still crashes after a few minutes.

    There are some other bugs - the program only works in "Internet Mode", and won't run after a device reset. It also doesn't save the time in the RTC (maybe I'm just not waiting long enough. ) Reconnecting to Wifi alter lightsleep is called is hit or miss, usually it hangs.

  • @wsanders I got the program to run with lightsleep, but only in "Internet Mode" and not "App Mode". Battery life was no different with lightsleep than with wait, about 2 hr. (Wait is probably is just a call to lightsleep, just in a more organized manner.)

    It appears that in 1.9.6 Wifi doesn't come back up after lightsleep, I seem to remember the above callback function worked in 1.9.5 even after lightsleep. Now it hangs.

    Back to square one. I think the best way is to have two separate programs, one to sync the watch to NTP, and one to run the clock with the time from the RTC (so I can still use the watch outside of my home wifi network.)