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