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

    New LTE Firmware releases v1.18.1.r4 (stable) & 1.19.0.b5 (development) & NB-IoT firmware 40343

    Scheduled Pinned Locked Moved Announcements & News
    firmwarelte
    51 Posts 12 Posters 10.8k Views 14 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.
    • I Offline
      iwahdan @danielm
      last edited by

      Hi @danielm the error you are getting
      HTTP POST failed: 'NoneType' object has no attribute 'split' is because the socket operation socket.recv() has returned error code = EGAIN which could be when the operation timesout if you are are setting a socket timeout > 0 , where this error is considered non blocking by the readline function in MicroPython py/stream.c where in that case a None object is returned. maybe this should be handled in requests.py

      on the other hand the problem of failing to create more sockets HTTP POST failed: 23 that happens at some point, is because lwip stack fails to allocate new sockets and this is because every time the exception 'NoneType' object has no attribute 'split' is raised it is not caught by the exception handler in requests.py

          except OSError:
              s.close()
              raise
      

      As it is an AttributeError not an OSError exp, thus the socket is not closed and by turn the lwip stack does not free that socket as it considers conn still active since err code is EGAIN.
      I know that in the normal case when the POST is successful you also don't close the socket afterwards but that is not a problem as the lwip will Reuse the oldest socket not closed yet [Note: that the Max active sockets is Configured to 10] .

      so the flow goes as follow socket # 54 gets allocated for first message then 55 for second and so on till #64 .. then lwip will allocate socket #54 again for creating new socket then #55 and so on.
      However when a socket connection timeout if the socket is not closed the socket # will be reserved forever.

      so in your case if a socket operation timeout say every 1000 successful POST the esp32 will fail to allocate new sockets after 10000 POSTs (so it is a socket leak)

      so to fix you problem you have to do the following modifications in requests.py:

      Update exception handler to include all exceptions so that the socket is closed in any case:

          except :
              s.close()
              raise
      

      maybe it is also a good idea to close the socket after successful POST as follows:

      response = urequests.post(url, headers={ "Content-Type": "application/json", "Accept": "application/json"}, data='{"time": "%s"}' % (time.time()))
      print("INFO", "%s. HTTP POST successful: %s" % (n, response.text))
      response.close()
      

      Thanks for your help.

      Wahdan

      1 Reply Last reply Reply Quote 0
      • D Offline
        danielm
        last edited by

        Hi @iwahdan. Thank you for excelent analysis. I will perform recommended modifications and also long-term tests.
        I believe that this issue is not related to issues you are describing in this post?
        https://forum.pycom.io/topic/3985/new-lte-firmware-releases-v1-18-1-r4-stable-1-19-0-b5-development-nb-iot-firmware-40343/39

        I 1 Reply Last reply Reply Quote 0
        • I Offline
          iwahdan @danielm
          last edited by

          @danielm Thanks, No the problem I mentioned in that post is because the ssl handshake does not timeout, which I think is not what happens in your case.

          Wahdan

          D 1 Reply Last reply Reply Quote 0
          • D Offline
            danielm @iwahdan
            last edited by

            @iwahdan
            Is it possible to fix the ssl handshake not timing out?
            What about socket.connect() timeout workaround implementation?

            Due to nature of network communication any socket operation may fail but it should never hang if timeout is set. Otherwise it will not be possible to develop reliable applications.

            I 1 Reply Last reply Reply Quote 0
            • I Offline
              iwahdan @danielm
              last edited by

              Hi @danielm, I am investigating the handshake problem, and for a the socket.connect timeout I think it is possible to have a workaround in the Micropython, but it would need proper design to ensure a robust implementation .

              I've already created an internal ticket for it.

              Wahdan

              D 1 Reply Last reply Reply Quote 0
              • D Offline
                danielm @iwahdan
                last edited by

                @iwahdan
                Great, please let me know if you need help with testing.

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tlanier @tlanier
                  last edited by

                  @tlanier
                  The bug I was experiencing was caused by my inexperience using Python. I was allocating a new WLAN object every time I ran the code without destroying the old object.

                  Here is a listing of my new wifi.py module that fixes my problem. I'm sorry if I've caused anyone to lose confidence in the GPy or spend time looking for bugs that did not exist.

                  from network import WLAN
                  from util import log
                  import utime
                  
                  wlan = None
                  
                  def connect():
                      global wlan
                  
                      if (wlan != None):
                          if wlan.isconnected():
                              print('Already connected')
                              return
                  
                      wlan = WLAN(mode=WLAN.STA)
                      
                      while True:
                          # scan for WIFI access points
                          nets = wlan.scan()
                          print(nets)
                          
                          for net in nets:
                              if (net.ssid == 'NURSEX'):
                                  print('NURSEX WIFI found')
                                  # wlan.connect(net.ssid, auth=(net.sec, 'password'), timeout=5000)
                                  wlan.connect(net.ssid, auth=(net.sec, 'password'))
                                  while not wlan.isconnected():
                                      utime.sleep_ms(1000)
                                  print('WLAN connection succeeded!')
                                  return
                          
                          utime.sleep_ms(1000)
                  
                  def disconnect():
                      global wlan
                  
                      if (wlan != None):
                          wlan.disconnect()
                          wlan = None```
                  I 1 Reply Last reply Reply Quote 0
                  • I Offline
                    iwahdan @tlanier
                    last edited by

                    @tlanier No problem!, thanks for letting us know

                    Wahdan

                    D 1 Reply Last reply Reply Quote 0
                    • D Offline
                      danielm @iwahdan
                      last edited by

                      @iwahdan
                      Are there any news regarding solution for known socket issues?

                      W 1 Reply Last reply Reply Quote 0
                      • W Offline
                        wghirakawa @danielm
                        last edited by

                        @danielm what socket issues are you referring too?

                        If everyone in the world could do their passion, the world would be an unbelievable place!

                        D 1 Reply Last reply Reply Quote 0
                        • D Offline
                          danielm @wghirakawa
                          last edited by danielm

                          @wghirakawa
                          The issue is that socket.connect() and SSL handshake will not timeout also in case the socket timeout is set and hang the application forever.
                          https://forum.pycom.io/topic/3985/new-lte-firmware-releases-v1-18-1-r4-stable-1-19-0-b5-development-nb-iot-firmware-40343/45

                          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
                          • 2
                          • 3
                          • 3 / 3
                          • First post
                            Last post

                          Pycom on Twitter

                          Pycom