OSError: Network card not available after updating firmware via OTA



  • Hello all!

    On occasion, when I update a LoPy4 via OTA (transferring appimg.bin to /flash/sys and then rebooting), I get the following exception when running standard code in my LoPy4:

    OSError: Network card not available
    

    The exception is thrown on this line:

    s_app = socket.socket()
    

    What could be causing this? The only way I have found of solving the problem has been re-flashing the firmware.

    Any insights are appreciated.

    Best,

    Dan


  • Global Moderator

    Last week I did check out the code for a bit, and when no network adapter is explicitely specified, it should default to AF_INET (thats WLAN or LTE). Im not exactly sure what is happening on your end. Do you check whether the network is connected beforehand (ie wlan.isconnected() should return True, it could take a couple of seconds for the WiFi handshake to complete)

    Let me know what you find

    Gijs



  • @Gijs Hello! Thank you for your reply.

    In fact, I do define a network beforehand. In boot.py I run the following code, always:

    currSSID = WLAN().ssid()
    WLAN().deinit()
    WLAN().init(mode=WLAN.AP, ssid=currSSID, auth=(WLAN.WPA2, 'pwd'), hidden=True, antenna=WLAN.INT_ANT)
    

    And then, in main.py I first initialize a LoRa socket (which goes smoothly) and then initialize the WLAN socket via s_app = socket.socket().

    However, I have not tried indicating the exact type of network to use in the socket. Could this be the culprit? I will try to reproduce the error.

    Best,

    Dan


  • Global Moderator

    Hi,
    I get exactly the same (without the OTA transfer), if i do not define a network first. I'll show you an example:

    >>> import socket
    >>> s = socket.socket()
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    OSError: Network card not available
    >>> from network import WLAN
    >>> wlan = WLAN()
    >>> wlan.init()
    >>> wlan.connect(ssid='Pycom', auth=(WLAN.WPA2, 'PyE!ndh0ven#'))
    >>> wlan.isconnected()
    False
    >>> wlan.isconnected()
    True
    >>> s = socket.socket()
    >>> 
    

    Which is logical. What you need to do is connect to a network first. What might be the case, is that either Pybytes is activated, or some wlan or lte on boot setting is activated in the background before calling socket.socket() making the error not appear.
    Its also best practice to specify the type of network you want to use like so
    s = socket.socket(usocket.AF_INET)

    Gijs


Log in to reply
 

Pycom on Twitter