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 hangs on receive loop while in c-clas

    Scheduled Pinned Locked Moved Support & Troubleshooting
    lopy4c classreceivehang
    3 Posts 2 Posters 45 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.
    • J Offline
      Jamie
      last edited by

      while True:
          try:
              rx = s.recv(64)
              if rx:
                  rxStr = str(rx).split("'")
                  s.send("Sw#," + rxStr[1])
                  index = int(rxStr[1])
                  i2c.writeto(56, 255-index)
                  print("swSet = ", index)
                  wdt.feed()
          except Exception as error:
              print(error)
              s.send(str(error))
          time.sleep_ms(500)
      

      Greetings,
      I'm hoping someone might see a problem in this receive loop. The device is in c class mode when it reaches this code and then it waits to receives data that is sent every minute. The data is a incrementing number and the number is echoed back thru the gateway and into a database for testing. The problem is that the devices will work fine for awhile and then hang until the WDT resets. I have five devices working side by side with the message coming in to each device spaced one second apart and they will all hang but how offend differs between devices. I also miss messages but that does not concern me as much as the 5 to 7 minutes it takes to restart the device. The i2c chip is a I expander running switches. Do I need to do something as simple as adding a time.sleep() somewhere?
      Thanks

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

        @Jamie you should probably add a few logs in order to determine exactly where it hangs (receiving or sending over LoRa, sending over I2C).

        Is the socket set to blocking or non-blocking?

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jamie
          last edited by

          while True:
              rx = s.recv(64)
              time.sleep_ms(10)
              if rx:
                  time.sleep_ms(10)
                  rxStr = str(rx).split("'")
                  index = int(rxStr[1])
                  
                  try:
                      i2c.writeto(56, 255-index)
                  except Exception as error:
                      print("i2c",error)
                      
                  startTime = time.ticks_ms()
                  s.setblocking(True)
                  time.sleep_ms(10)
                  
                      try:
                          s.send("ack")
                      except Exception as error:
                          print("send ",error)
                          
                  time.sleep_ms(10)
                  s.setblocking(False)
                  print(time.ticks_ms()-startTime)
                  wdt.feed()
          

          @jcaron thanks for your response. The problem is in the s.send(). I added the setblocking() statements around the statement along with putting it in its own try/except but they are still resetting at least 12-16 times a day. Is there any thing else you think I should check? Gateway setting? I'm using a Multitech Conduit gateway that's running node-red.

          Thanks again

          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