🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Has anyone gotten machine.lightsleep to work from UIflow?

    UIFlow
    2
    4
    4.4k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • W
      wsanders
      last edited by wsanders

      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?
      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by felmue

        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
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 1
        • W
          wsanders
          last edited by wsanders

          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:

          0_1650586949403_Screenshot_20220421_172204.png

          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.

          1 Reply Last reply Reply Quote 0
          • W
            wsanders
            last edited by wsanders

            @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.)

            1 Reply Last reply Reply Quote 0
            • First post
              Last post