Page 1 of 1

wiznet - OSError: no available NIC

Posted: Tue Mar 26, 2019 12:59 pm
by devnull
I am using a pyboard and wiznet in place of an esp8266 running mqtt, the wiznet is working fine and has an ip address.

But umqtt_simple complains that it cannot find a NIC,

Code: Select all

umqtt_simple.py", line 16, in __init__
OSError: no available NIC
I declared the nic in the boot.py file.

Code: Select all

import network
nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin('X5'), pyb.Pin('X4'))

nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')
It works within the scope of the REPL, but how do I go about getting any other modules that call socket to recognize that there is an NIC attached as it appears that they dont !

Re: wiznet - OSError: no available NIC

Posted: Wed Mar 27, 2019 12:28 am
by Damien
If you get "no available NIC" then it's failing either in either socket.bind, socket.connect, socket.sendto or socket.getaddrinfo.

Try testing if socket.getaddrinfo(<mqtt_server>, 1883) works or not (eg at the REPL).

Re: wiznet - OSError: no available NIC

Posted: Wed Mar 27, 2019 10:32 am
by devnull
Damien, thanks for helping;

Yes, that works, but it appears that I need to declare the nic module in the scope that the socket will be created, which would mean that all of the modules that I already have would need to be re-written to declare the nic card inside the module.

Also, see this thread: viewtopic.php?f=6&t=6180&p=35206#p35206

The pyboard socket appears to be so restricted in terms of it's functions and options.

If I run these from the REPL:

Code: Select all

import socket, network
nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
nic.ifconfig()
nic.isconnected()

def subcb(val):
	pass

from umqtt_simple import MQTTClient
client = MQTTClient('123456789','xxxnet.com',port=1883)
client.set_callback(subcb)
 client.connect()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/nfs/qnap/data/uPython/bash/../flash/lib/umqtt_simple.py", line 74, in connect
AttributeError: 'socket' object has no attribute 'write'
As you can see it fails, so umqtt_simple would need to be re-written to use 'send', but also this fails:

Code: Select all

>>> import socket, network
>>> nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
>>> nic.ifconfig()
('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')
>>> nic.isconnected()
True
>>> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sf = s.makefile('rwb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'socket' object has no attribute 'makefile'
And without makefile, and there is no readline(), it difficult to be able to read the socket line by line.

Re: wiznet - OSError: no available NIC

Posted: Wed Mar 27, 2019 12:40 pm
by devnull
Hmmm...

I tried this example: http://docs.micropython.org/en/latest/e ... ttp-server

But that also fails with:

Code: Select all

listening on ('0.0.0.0', 80)
client connected from ('192.168.0.15', 80)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "wiztest.py", line 79, in <module>
  File "wiztest.py", line 68, in web2
AttributeError: 'socket' object has no attribute 'makefile'

Re: wiznet - OSError: no available NIC

Posted: Thu Mar 28, 2019 6:16 am
by Damien
You can switch to use a better socket implementation on the wiznet, by enabling MICROPY_PY_LWIP. Either build with "make MICROPY_PY_LWIP=1 MICROPY_PY_WIZNET5K=5500", or set these 2 parameters in mpconfigport.mk

Re: wiznet - OSError: no available NIC

Posted: Thu Mar 28, 2019 9:05 am
by devnull
Thanks, yes socket now seems more comprehensive, that's great, but now I am unable to connect the nic:

Code: Select all

import network, socket
net = network.WIZNET5K(pyb.SPI(1), pyb.Pin('X5'), pyb.Pin('X4'))
net.active(True)
net.ifconfig(('192.168.0.18','255.255.255.0','192.168.0.1','8.8.8.8'))
while not net.isconnected():
	pass
net.ifconfig()
socket.getaddrinfo('micropython.org',80)
Output:

Code: Select all

('192.168.0.18', '255.255.255.0', '192.168.0.1', '8.8.8.8')
Traceback (most recent call last):
  File "<stdin>", line 9, in <module>
OSError: -2
Cable is connected, both ethernet port lights are flashing, but cannot do dns lookup from the device and also cannot ping to the device.

Does it matter which order these are specified in:

Code: Select all

make MICROPY_PY_LWIP=1 MICROPY_PY_WIZNET5K=5500