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

    OSError: Network card not available

    Scheduled Pinned Locked Moved Discussion
    lopy
    7 Posts 5 Posters 2.2k Views 5 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.
    • M Offline
      misterlisty
      last edited by

      OSError: Network card not available What does this mean?

      1 Reply Last reply Reply Quote 0
      • X Offline
        Xykon administrators
        last edited by

        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

        Christian Ehlers

        sorenS 1 Reply Last reply Reply Quote 0
        • sorenS Offline
          soren @Xykon
          last edited by

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

          J 1 Reply Last reply Reply Quote 0
          • J Offline
            jmarcelino @soren
            last edited by jmarcelino

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

            sorenS 1 Reply Last reply Reply Quote 0
            • sorenS Offline
              soren @jmarcelino
              last edited by jmarcelino

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

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

                think about people first, then computers

                sorenS 1 Reply Last reply Reply Quote 1
                • sorenS Offline
                  soren @livius
                  last edited by

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

                  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