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

    Lopy4 issue receiving in a tight loop

    Scheduled Pinned Locked Moved LoPy
    7 Posts 2 Posters 65 Views 2 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.
    • M Offline
      mbyamukama
      last edited by

      I have the following bit of code.

      from network import LoRa
      import socket
      import time
      import pycom
      
      # Please pick the region that matches where you are using the device
      pycom.heartbeat(False)
      lora = LoRa(mode=LoRa.LORA, region=LoRa.EU868, bandwidth=LoRa.BW_250KHZ,coding_rate=LoRa.CODING_4_5,sf=7, tx_power=14,power_mode=LoRa.ALWAYS_ON,preamble=8,
                  tx_iq=False, rx_iq=False) # >17000 bps
      s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
      s.setblocking(False)
      i = 0
      while True:
          data=s.recv(512)
          if len(data)>0:
              print('count {0} value {1} length {2}'.format(i,data,len(data)))
              i = i+1
              pycom.rgbled(0xFFD058)
              time.sleep_ms(2)
              pycom.rgbled(0x000000)
              time.sleep_ms(2)
          time.sleep_ms(1)
      

      I receive data well, except when I comment out the 1ms delay in the while loop. In which case I receive no data at all. The transmissions are happening slowly. About every 1 second.

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

        Because you have an infinite loop, removing the delay will leave no time for the watchdog timer to trigger, making the device reset internally. You can perhaps use time.sleep_us(...) instead?

        Gijs

        M 1 Reply Last reply Reply Quote 0
        • M Offline
          mbyamukama
          last edited by

          This post is deleted!
          1 Reply Last reply Reply Quote 0
          • M Offline
            mbyamukama @Gijs
            last edited by

            @Gijs Thank you for your response.
            Any document I can read more about this?

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

              Its all in here: https://docs.pycom.io/firmwareapi/micropython/utime/
              Note that the 'u' in front of utime can be left when importing, its the same module

              Gijs

              M 1 Reply Last reply Reply Quote 0
              • M Offline
                mbyamukama @Gijs
                last edited by

                @Gijs What I meant was any documentation on the watchdog timer versus tight loops.

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

                  Right, we do not have specific documentation on that (yet) I believe, as in my experience its a fundamental feature of microcontrollers in general. Could you recommend a place where you would expect this information?

                  Gijs

                  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