Network on STM32F4Discovery

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
Yupiter
Posts: 3
Joined: Mon Nov 17, 2014 12:38 pm

Network on STM32F4Discovery

Post by Yupiter » Wed Jan 28, 2015 1:24 pm

Hello,

I'm trying to start TCP/IP echo server on STM32F4Discovery.

My script is:

Code: Select all

#try:
import usocket as socket
#except:
#import socket
print("TCP/IP echo server")
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ai = socket.getaddrinfo("192.168.0.10", 7)
print("Bind address info:", ai)
addr = ai[0][4]
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind(addr)
s.listen(1)
print("Listening")
res = s.accept()
client_s = res[0]
client_addr = res[1]
print("Client address:", client_addr)
print("Client socket:", client_s)
while True:
	recv_buf = client_s.recv(128)
	client_s.send(bytes(recv_buf, "ascii"))
client_s.close()
And I had an error:
Traceback (most recent call last):
File "main.py", line 6, in <module>
OSError: no available NIC
1) What is 'NIC'?
2) Can anybody help me with the error?

Thanks.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Network on STM32F4Discovery

Post by blmorris » Wed Jan 28, 2015 9:56 pm

'NIC' is 'Network Interface Controller', the hardware you are using to connect to your network. Your script is throwing the error at line 6:

Code: Select all

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
because you haven't initialized a network interface.
What network hardware (wifi, Ethernet, other?) are you using and how is it connected?

-Bryan

Yupiter
Posts: 3
Joined: Mon Nov 17, 2014 12:38 pm

Re: Network on STM32F4Discovery

Post by Yupiter » Thu Jan 29, 2015 6:28 am

you haven't initialized a network interface
- I thought so.

I'm trying to start ethernet communication.

Could you please explain me how can I initialize an ethernet connection? Or give me a link to the network documentation because I did not find it on the site.

Thanks.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Network on STM32F4Discovery

Post by blmorris » Thu Jan 29, 2015 5:50 pm

As far as I know, the only ethernet devices supported within micropython are the Wiznet adapters, which are documented here:
http://micropython.readthedocs.org/en/l ... s-wiznet5k

For the Discovery board, you may need to build your firmware with the Wiznet and network module included, I believe that I just dod this with the following command:

Code: Select all

make -B BOARD=STM32F4DISC MICROPY_PY_WIZNET5K=1
But I don't have a Wiznet adapter connected to a discovery board to test.
To deploy in a single command:

Code: Select all

make -B BOARD=STM32F4DISC MICROPY_PY_WIZNET5K=1 USE_PYDFU=1 deploy
Hope this helps.
-Bryan

Yupiter
Posts: 3
Joined: Mon Nov 17, 2014 12:38 pm

Re: Network on STM32F4Discovery

Post by Yupiter » Mon Feb 02, 2015 2:56 pm

Hello,

Accordingly to previous post I changed my script (it's not a whole script and just only interesting part)

Code: Select all

import network
print("TCP/IP echo server")
nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.PA7, pyb.Pin.board.PA4)
print(nic.ifconfig())

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
And I have the following script output:
CP/IP echo server
('255.255.255.255', '255.255.255.0', '255.255.255.255', '192.168.0.2')
As I understand '('255.255.255.255', '255.255.255.0', '255.255.255.255', '192.168.0.2')' means '(<ip>, <net mask>, <gateway>, <dns>)'.
Net mask and dns are correct but ip should be equal 192.168.0.10 and gateway should be equal 192.168.0.1

I was trying all combinations of 'network.WIZNET5K' parameters but never get right net mask and dns.

Could you please explain why I had wrong data.

Thanks.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: Network on STM32F4Discovery

Post by blmorris » Mon Feb 02, 2015 4:53 pm

Looks like your call to 'print(nic.ifconfig())' is just returning the default values.
According to the network documentation at http://micropython.readthedocs.org/en/l ... k.ifconfig you can pass a tuple with your network configuration to 'nic.ifconfig()' to set the network values:

Code: Select all

nic.ifconfig(('192.168.0.10', '255.255.255.0', '192.168.0.1', '192.168.0.2'))
but I don't have a pyboard + wiznet ethernet setup to confirm that this works.

-Bryan

kjarke
Posts: 5
Joined: Wed Jun 17, 2015 12:28 am

Re: Network on STM32F4Discovery

Post by kjarke » Wed Jun 17, 2015 12:44 am

Has anybody got the a network on the discovery board with the CC3000 working? I can connect to my wifi network and I get an IP address. The IP address looks real since the router also lists it under attached devices with matching MAC address. I think I can also create a socket but when I try bind or connect I get OSError: -126. getaddrinfo fails with OSError: -85. Has anybody got a working code example?

This is what I got:

Code: Select all

import pyb
import network
import usocket as socket

nic = network.CC3K(pyb.SPI(2), pyb.Pin.cpu.A15, pyb.Pin.cpu.B10, pyb.Pin.cpu.B11)
nic.connect('SSID', 'password')
while not nic.isconnected():
    pyb.delay(50)
print(nic.ifconfig())

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('192.168.0.43', 8080))
s.send(b"Hi there")
print(s.recv(64))
s.close()

Post Reply