OSError: Network card not available



  • OSError: Network card not available What does this mean?



  • @livius Ah shoot, I thought I was enabling manual garbage collectin with gc.enable(). And the UART duplication is obviously a mistake. Thanks for pointing those out !



  • @soren
    two things but i do not suppose that are releated to the issue:
    you initialize twice UART and do dupterm

    uart = UART(0, 115200)
    os.dupterm(uart)
    print('starting up...')
    print(gc.mem_free())
    gc.enable()
    uart = UART(0, 115200)
    os.dupterm(uart)
    

    all above initialization can be ommited because dupterm is done in frozen _boot.py

    second, you have enabled automatic garbage collecion gc.enable()
    but then you use it manually gc.collect() - of course you can do this but is this intentional?



  • @jmarcelino Yes of course. Strange thing is, after unplugging the power completely (hard reset was not enough), problem stopped for now. Anyway, if there's something fishy, this is my boot:

    import machine
    import gc
    from machine import UART
    from network import WLAN
    import pycom
    import os
    uart = UART(0, 115200)
    os.dupterm(uart)
    print('starting up...')
    print(gc.mem_free())
    gc.enable()
    uart = UART(0, 115200)
    os.dupterm(uart)
    pycom.heartbeat(False)
    pycom.rgbled(0x7f0000) # red
    
    wlan = WLAN()
    if machine.reset_cause() != machine.SOFT_RESET:
        print('setting wlan config...')
        wlan.init(mode=WLAN.STA)
        wlan.ifconfig(config=('10.42.0.14', '255.255.255.0', '10.42.0.1', '8.8.8.8'))
    
    if not wlan.isconnected():
        print('looking for network...')
        wlan.connect('cooppifi', auth=(WLAN.WPA2, 'PasswordRemoved'), timeout=5000)
        while not wlan.isconnected():
            machine.idle()
    print('connected to wifi!')
    print(gc.mem_free())
    

    and this is my main. the issue happens where i send to the socket:

    
    from network import Bluetooth
    import socket
    #from network import socket
    import pycom
    import gc
    import time
    import machine
    import binascii
    from machine import Timer
    pycom.heartbeat(False)
    pycom.rgbled(0x000000) # turn off led
    gc.enable()
    lopyID = 4 # set this unique to each lopy
    print('started! lopy id: ', lopyID)
    print("a")
    gc.collect()
    print(gc.mem_free())
    bluetooth = Bluetooth()
    bluetooth.stop_scan()
    time.sleep(1)
    bluetooth.start_scan(-1)
    adv = None # bluetooth advertisementa
    
    time.sleep(1)
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    pycom.rgbled(0x007f00)
    
    #print(gc.mem_free())
    def sendToSocket(beaconID, rssi):
        print(gc.mem_free())
        RSSIpositive = rssi * -1
        string = str(lopyID) + "," + str(beaconID) + "," + str(RSSIpositive) + ","
        data = bytearray(string)
        addr = socket.getaddrinfo('10.42.0.1', 7007)[0][-1]
        s.sendto(data, addr)
    
    # new mac adresses:
    #C7:C3:83:EE:AA:A4
    #FB:6F:11:25:79:9B
    #F7:F0:BB:A6:ED:F7
    #C3:C7:E7:73:7C:3F
    
    while True:
    
        gc.collect()
        pycom.rgbled(0x007f00)
        advList = bluetooth.get_advertisements()
        for adv in advList:
            macRaw = adv[0] # binary mac address
            macReal = binascii.hexlify(macRaw) # convert to hexadecimal
            if macReal == b'fb6f1125799b': # old: b'f3bc0b6feb4c':
                print('beacon A rssi: ', adv[3]) # adv[3] is rssi
                sendToSocket(beaconID = 1, rssi = adv[3])
            elif macReal == b'f7f0bba6edf7': # old: b'edbed48d0b87':
                print('beacon B rssi: ', adv[3])
                sendToSocket(beaconID = 2, rssi = adv[3])
            elif macReal == b'c7c383eeaaa4': # <-- old
                print('beacon C rssi: ', adv[3])
                sendToSocket(beaconID = 3, rssi = adv[3])
            elif macReal == b'c3c7e7737c3f': # old: b'cd87e6a38dc2':
                print('beacon D rssi: ', adv[3])
                sendToSocket(beaconID = 4, rssi = adv[3]) # adv[3]
            gc.collect()
    s.close()
    


  • @soren
    Can you post your code? or at least the network initialisation / sockets part.

    Without more details it's impossible to help since you could be trying to initialise WiFi, LoRa, Sigfox...



  • @xykon i'm getting this error for no apparent reason... even though i'm doing a hard reset.
    is there a dev who knows what's happening?


  • administrators

    The error is thrown when creating a socket but the esp32 cannot find a network card available to handle the request.

    The error is thrown in modnetwork.c which is called by modsocket.c


 

Hello World?

Pylife on Kickstarter - November 2018








Back Us On Kickstarter >

Pycom on Twitter