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

    HTTP Post with urequests OSError: -1

    Scheduled Pinned Locked Moved Comments & Feedback
    http postjsonurequest.pyoserror
    8 Posts 2 Posters 2.5k 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
      jimpower
      last edited by

      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.

      0_1515709182169_81271025-2abf-4a98-87fc-c0c14ad7642b-image.png

      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)
      
      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @jimpower
        last edited by

        @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

        think about people first, then computers

        J 1 Reply Last reply Reply Quote 0
        • J Offline
          jimpower @livius
          last edited by

          @livius is it possible for you to give me an example of how to add the gc.collect() and network reconnect on condition?

          L 1 Reply Last reply Reply Quote 0
          • L Offline
            livius @jimpower
            last edited by livius

            @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

            think about people first, then computers

            J 1 Reply Last reply Reply Quote 0
            • J Offline
              jimpower @livius
              last edited by

              @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?

              L 1 Reply Last reply Reply Quote 0
              • L Offline
                livius @jimpower
                last edited by

                @jimpower said in HTTP Post with urequests OSError: -1:

                What is the function of garbage collect?

                Free mem

                think about people first, then computers

                J 2 Replies Last reply Reply Quote 0
                • J Offline
                  jimpower @livius
                  last edited by

                  @livius ahh thanks that will prob do it

                  1 Reply Last reply Reply Quote 0
                  • J Offline
                    jimpower @livius
                    last edited by

                    @livius Thanks for your help, the gc.collect() has worked and the loop has remained stable for a few hours now.

                    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