HTTP Post with urequests OSError: -1
-
Hi,
I am trying to post the temperature reading from my sensor to my cloud platform it works perfectly for about 5 mins than I get the following error message. Can someone please help with what I have missed.
while True:
temp.start_conversion() time.sleep(5) res = urequests.post('cloudsite', json={'mysensor': str(temp.read_temp_async())}) res.close() if (res.status_code - 200) < 100: # check that response code is in the 200 range print("Temperature POST Successful - " + str(temp.read_temp_async()) + " Degrees") else: print('there was some error') pycom.heartbeat(False) #If using battery remove '#' time.sleep(20)
-
@livius Thanks for your help, the gc.collect() has worked and the loop has remained stable for a few hours now.
-
@livius ahh thanks that will prob do it
-
@jimpower said in HTTP Post with urequests OSError: -1:
What is the function of garbage collect?
Free mem
-
@livius I added to connect to WiFi as part of the loop today and pinged my sensor it still failed with same error MSG but ping never dropped a packet so I don't think it is a network connectivity issue, well I assume it isn't.
What is the function of garbage collect?
-
@jimpower said in HTTP Post with urequests OSError: -1:
sample for gc
import gc while True: do something gc.collect()
Add try except block and try reconnect to the network on exception condition
simple use
try: your send statements except: yourConnectWifiProc()
you can do more intelligent check for some error codes and different conditions
but this is simplification to show simple thing
-
@livius is it possible for you to give me an example of how to add the gc.collect() and network reconnect on condition?
-
@jimpower
Will be good if you add to every loop:
gc.collect()
also it is possible that you loose connection to the network?
Add try except block and try reconnect to the network on exception condition