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) -
@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 -
@livius is it possible for you to give me an example of how to add the gc.collect() and network reconnect on condition?
-
@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 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:
What is the function of garbage collect?
Free mem
-
@livius ahh thanks that will prob do it
-
@livius Thanks for your help, the gc.collect() has worked and the loop has remained stable for a few hours now.
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