Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Deep sleep and pending network output

    Scheduled Pinned Locked Moved Getting Started
    wipypysenseudpdeep sleep
    7 Posts 4 Posters 1.6k Views 4 Watching
    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.
    • T Offline
      tshead
      last edited by

      Gang:

      I’ve got a WiPy 2.0 and PySense, sending sensor readings to a UDP socket before entering deep sleep. Everything works fine, so long as I put a call to time.sleep() between the calls to socket.sendto() and machine.deepsleep(). Without it, the receiving end never receives anything. I assume that deep sleep is shutting-down the radio before the packet has been transmitted? Is there a way to do a synchronous send on a socket that doesn’t return until the data is well-and-truly sent? The time.sleep() workaround is unsatisfying, since the correct duration is indeterminate.

      Thanks in advance,
      Tim

      J 1 Reply Last reply Reply Quote 1
      • J Offline
        jcaron @tshead
        last edited by

        @tshead have you tried setting to socket to blocking?

        1 Reply Last reply Reply Quote 0
        • T Offline
          tshead
          last edited by

          @jcaron - thanks for the quick response. Calling socket.setblocking(True) does not eliminate the need for a sleep() before deepsleep(). On some level this makes sense to me because I assume that under the hood the WiPy network stack is off handling sends and receives in a separate thread. If there isn’t API to know when then radio is finished sending, it would be useful to have some sort of official best practices / rule of thumb on how to wait (is machine.idle() better than time.sleep()?) and for how long.

          Cheers,
          Tim

          1 Reply Last reply Reply Quote 0
          • D Offline
            daniel
            last edited by

            @tshead we'll have a loot to see how this can be improved, but the best practice would be to wait for a reply from the other side confirming the reception of the packet before calling machine.deepsleep(). In your tests, what value do you have to pass to time.sleep() in order to make it work?

            Cheers,
            Daniel

            S 1 Reply Last reply Reply Quote 0
            • S Offline
              ssmith @daniel
              last edited by

              @daniel This is an issue I've seen in various places. Is there a flag that can be checked to know when this has completed? Random delay loops are very dangerous and usually come back to bite you.

              1 Reply Last reply Reply Quote 0
              • D Offline
                daniel
                last edited by

                @ssmith we'll check if there's a flag that we can add and check. I don't recommend random delay loops but instead adding a response from the other end to the protocol confirming that the packet was received.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tshead
                  last edited by

                  @daniel - Fair enough, I’ll think about switching from UDP to TCP (or BLE). I haven’t explored the sleep duration thoroughly, it’s set to 100ms at the moment, which has been reliable enough for my purposes.

                  Presumably this would be an issue for any networking stack on any machine, but we don’t think about it because we aren’t focused on putting a workstation to sleep immediately following a sendto().

                  Many thanks,
                  Tim

                  1 Reply Last reply Reply Quote 0

                  Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                  Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                  With your input, this post could be even better 💗

                  Register Login
                  • 1 / 1
                  • First post
                    Last post

                  Pycom on Twitter

                  Pycom