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

    pybytes deepsleep

    Scheduled Pinned Locked Moved Discussion
    6 Posts 5 Posters 103 Views 5 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.
    • J Offline
      j_mor
      last edited by j_mor

      Hi all,

      I've run into an issue using pybytes on my LoPy4 with Pysense shield.
      I would like to get data from sensors, send them to Pybytes and go to deepsleep.
      I do have sepadate funcions to get the data from sensors and to send the data.
      Simplified code without any definitions and library imports:

      sensorData = getSensorData()
      sendData(sensorData)
      py.setup_sleep(sleepTime)
      py.go_to_sleep()
      

      The getSensorData() returns JSON dictionary with all the sensor data.
      The sendData() looks like this:

      def sendData(data):
          pybytes.send_signal(1, data['batt'])
          pybytes.send_signal(2, data['temp1'])
          pybytes.send_signal(3, data['press'])
          .
          .
      

      (two dots represent more lines in the function, 9 values are being sent, wanted to save some space :) )
      The problem is that calling sendData() jumps out immediately and the actual data sending process takes on later. From what I understand pybytes.send_signal() sets up a new thread with given arguments and is done.

      So when I run the code, LoPy goes to deepsleep before it actually sends out any data to Pybytes.

      Is there any flag or variable I could check to see if my Lopy board is still sending out the data and in that case wait before going to deepsleep??

      Something like:

      sensorData = getSensorData()
      sendData(sensorData)
      while(True):
          if not "pybytes_still_sending_data":
              py.setup_sleep(sleepTime)
              py.go_to_sleep()
      

      Possible workaround may be to put time.sleep() for like 20 sec before the deepsleep, but I would like to avoid this "solution".

      Thank you,
      j_mor

      K C 2 Replies Last reply Reply Quote 2
      • L Offline
        leaf
        last edited by

        Would love to know this as well, or if there's any way to get confirmation that a message/signal was sent (with_ack)?

        1 Reply Last reply Reply Quote 0
        • K Offline
          katoa_mangu @j_mor
          last edited by

          @j_mor

          I had like to know the answer to this too.

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gijs
            last edited by

            Hi,
            Ill put this on the feature list!
            Gijs

            1 Reply Last reply Reply Quote 1
            • C Offline
              claus @j_mor
              last edited by

              I have hit this too. Maybe an optional callback parameter to send_signal which gets executed when done?

              1 Reply Last reply Reply Quote 1
              • C Offline
                claus
                last edited by

                I came up with a solution to this that for the moment seems to work. It is based on checking the length of the outgoing message queue (will fail if no mqtt connection)

                for _ in range(10):
                    in_queue = len(pybytes.__pybytes_connection.__connection.__mqtt._msgHandler._output_queue)
                    if in_queue == 0:
                        break
                    time.sleep(1)
                
                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