HTTPS POST using urequests.py and Guru Mediation Error
-
I am developing LoRa gateway based on LoPy which posts received data to a particular IoT platform. My application always crashes with multiple Guru Meditation Errors, sometimes without automatic restart of LoPy. The crash may happen only after few sent POST requests or after several minutes or even tens of minutes. It is different after each restart (by hardware switch on LoPy). LoPy is running on firmware version 1.6.12.b1.
I tried to simplify my code and also switched to publicly available server which accepts POST requests over HTTPS.
urequests.py was downloaded from GitHub:
https://github.com/micropython/micropython-lib/blob/master/urequests/urequests.pyCould you please try the code and check if it crashes with your board?
import network import machine import urequests import time class Simplified(): def __init__(self): self.rtc = machine.RTC() self.wlan = network.WLAN(mode=network.WLAN.STA, antenna=network.WLAN.INT_ANT) self.timeSynchonized = False def test(self): self.wlan.ifconfig(config='dhcp') self.wlan.connect("<SSID>", auth=(network.WLAN.WPA2, "<PSWD>")) while True: self.rtcNow = self.rtc.now() if self.wlan.isconnected(): if not self.timeSynchonized: self.rtc.ntp_sync("pool.ntp.org") self.timeSynchonized = True else: data = '{"id": %s, "time": "%s-%02d-%02dT%02d:%02d:%02d.%03d+00:00"}' % (machine.rng(), self.rtcNow[0], self.rtcNow[1], self.rtcNow[2], self.rtcNow[3], self.rtcNow[4], self.rtcNow[5], self.rtcNow[6] // 1000) print(data) try: response = urequests.post("https://posttestserver.com/post.php", data = data) print(response.text) except Exception as e: print(e) time.sleep(1) node = Simplified() node.test()
-
@jimpower I think it should work ok with latest releases. However I did not test it for some time.
-
@danielm Did you end up solving this issue? I am experiencing the same issue will POST several times then board will reboot it seems like maybe a memory issue or to do with the urequests.py however it does POST perfectly for periods of time.
-
Thanks a lot, we will be waiting for a solution.
Btw, the board sometimes restarts and works ok, sometimes keeps restarting in a loop and in other cases it does not restart any more.
-
@danielm Ahh yes, you're right! The board restarts after X number of requests...
Let me raise this with Daniel - This is definitely odd behaviour...
-
I am currently running similar code posting requests to a particular IoT platform over HTTPs and the error happens after some number of requests, usually over 100. My FW version is 1.6.13.b1.
I will try to load simplified code from my first post in this thread and let you know.
Did you keep it running long enough?The socket is closed within urequests.py library when a response is received.
-
Hi @danielm,
Have you tried updating the firmware and trying this again? I've just tried this and it seems to work without issue.
My only suggestion would be to ensure that the socket opened in the http request is closed before the loop repeats itself.