usocket issue: EBADF (or ENOTCONN) after doing a single GET request (using urequests) over LTE (NB-IoT)



  • Hi,
    I'm having trouble using urequests over an LTE (NB-IoT) connection, which appears like a bug somewhere in usocket or LTE. I'm not having this issue when using WLAN.

    After making a single request using urequests, I'm getting the OSError: [Errno 9] EBADF or OSError: [Errno 128] ENOTCONN when trying to do anything with sockets (e.g. usocket.getaddrinfo('cloudiotdevice.googleapis.com', 443)):

    Traceback (most recent call last):
      File "main.py", line 24, in <module>
    OSError: [Errno 128] ENOTCONN
    

    Here is the smallest main.py I could make to reconstruct the issue. If you uncomment the gc.collect() line, the error changes to EBADF instead of ENOTCONN.

    import usocket
    import time
    import urequests
    import gc
    from network import LTE
    from network import WLAN
    
    gc.enable()
    
    lte = LTE()
    lte.attach(band=20,apn='nbiot.iot')
    while not lte.isattached():
        print('Attaching...')
        time.sleep(1)
    print('LTE is attached')
    lte.connect()
    
    response = urequests.get('https://cloudiotdevice.googleapis.com')
    print(response.text)
    response.close()
    
    # gc.collect()
    
    usocket.getaddrinfo('cloudiotdevice.googleapis.com', 443)
    

    Since I do not get this issue when using a WLAN connection, I suspect the problem to be related to usocket and LTE. I am very new to micropython however, so I have no clue on how to figure this out.

    My device and firmware info is:

    Pycom MicroPython 1.20.0.rc3 [v1.9.4-c5b0b1d] on 2018-12-17; GPy with ESP32
    
    >>> sqnsupgrade.info()
    <<< Welcome to the SQN3330 firmware updater [1.2.1] >>>
    >>> GPy with firmware version 1.20.0.rc3
    Your modem is in application mode. Here is the current version:
    UE6.0.0.0
    LR6.0.0.0-40343
    

    As you can see, I'm running the latest NB-IoT modem firmware. I'm doing this on Orange Belgium network, where the dns lookup actually does not work (it returns useless data). I verified if this would be the origin of the issue by commenting out the use of getaddrinfo in the urequests library, but the problem stays the same: after a single request (i.e. a single socket use?), the next request would get the same error back from the usocket library.

    Any help would be appreciated.

    cheers
    Johan

    ps: I also have this issue with the current stable firmware (1.18.something ... sorry forget which one the stable was right now).



  • @johanbrichau said in usocket issue: EBADF (or ENOTCONN) after doing a single GET request (using urequests) over LTE (NB-IoT):

    After making a single request using urequests, I'm getting the OSError: [Errno 9] EBADF:

    I've updated to 1.18.2 as @johanbrichau mentions ... but I'm still to getting these Errors ...

    My work-around was to wrap them in a Try-Catch ... since the data was being transmitted to the server ...

    @paul-thornton said in usocket issue: EBADF (or ENOTCONN) after doing a single GET request (using urequests) over LTE (NB-IoT):

    I know there's a ton of work going on with the LTE stack to make improvements to stability at the moment. Ill make sure this is raised as an issue and gets looked at to.

    Great 👍🏻 ... let us know more when you've got something to test 🙃

    @johanbrichau said in usocket issue: EBADF (or ENOTCONN) after doing a single GET request (using urequests) over LTE (NB-IoT):

    This is fixed in 1.18.2 because you can set the dns manually: https://forum.pycom.io/topic/4361/new-stable-firmware-release-v1-18-2

    This 1.18.2 may fix the following: OSError: [Errno 128] ENOTCONN when trying to do anything with sockets (e.g. usocket.getaddrinfo('cloudiotdevice.googleapis.com', 443))

    Use the following to set your DNS Server to Google's DNS Servers ...

    usocket.dnsserver(0,'8.8.8.8')
    usocket.dnsserver(1,'4.4.4.4')
    usocket.dnsserver()
    ('8.8.8.8', '4.4.4.4')
    

    Then bring up your LTE Connection, and do:

    >>> print(usocket.getaddrinfo("www.google.com", 80)[0][-1])
    ('216.58.211.4', 80)


  • This is fixed in 1.18.2 because you can set the dns manually: https://forum.pycom.io/topic/4361/new-stable-firmware-release-v1-18-2



  • I know there's a ton of work going on with the LTE stack to make improvements to stability at the moment. Ill make sure this is raised as an issue and gets looked at to.


Log in to reply
 

Pycom on Twitter