Skip to content

Commit c0b3d45

Browse files
committed
docs: Update network docs to reflect changes to code.
1 parent 29a1ec1 commit c0b3d45

1 file changed

Lines changed: 132 additions & 18 deletions

File tree

docs/library/network.rst

Lines changed: 132 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,173 @@
55
.. module:: network
66
:synopsis: network configuration
77

8-
This module provides network drivers and routing configuration.
8+
This module provides network drivers and routing configuration. Network
9+
drivers for specific hardware are available within this module and are
10+
used to configure a hardware network interface. Configured interfaces
11+
are then available for use via the :mod:`socket` module.
12+
13+
For example::
14+
15+
# configure a specific network interface
16+
# see below for examples of specific drivers
17+
import network
18+
nic = network.Driver(...)
19+
print(nic.ifconfig())
20+
21+
# now use socket as usual
22+
import socket
23+
addr = socket.getaddrinfo('micropython.org', 80)[0][-1]
24+
s = socket.socket()
25+
s.connect(addr)
26+
s.send(b'GET / HTTP/1.1\r\nHost: micropython.org\r\n\r\n')
27+
data = s.recv(1000)
28+
s.close()
29+
30+
class CC3K
31+
==========
932

33+
This class provides a driver for CC3000 wifi modules. Example usage::
1034

11-
class CC3k
12-
==========
35+
import network
36+
nic = network.CC3K(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4, pyb.Pin.board.Y3)
37+
nic.connect('your-ssid', 'your-password')
38+
while not nic.isconnected():
39+
pyb.delay(50)
40+
print(nic.ifconfig())
41+
42+
# now use socket as usual
43+
...
44+
45+
For this example to work the CC3000 module must have the following connections:
46+
47+
- MOSI connected to Y8
48+
- MISO connected to Y7
49+
- CLK connected to Y6
50+
- CS connected to Y5
51+
- VBEN connected to Y4
52+
- IRQ connected to Y3
53+
54+
It is possible to use other SPI busses and other pins for CS, VBEN and IRQ.
1355

1456
Constructors
1557
------------
1658

17-
.. class:: CC3k(spi, pin_cs, pin_en, pin_irq)
59+
.. class:: CC3K(spi, pin_cs, pin_en, pin_irq)
60+
61+
Create a CC3K driver object, initialise the CC3000 module using the given SPI bus
62+
and pins, and return the CC3K object.
63+
64+
Arguments are:
1865

19-
Initialise the CC3000 using the given SPI bus and pins and return a CC3k object.
66+
- ``spi`` is an :ref:`SPI object <pyb.SPI>` which is the SPI bus that the CC3000 is
67+
connected to (the MOSI, MISO and CLK pins).
68+
- ``pin_cs`` is a :ref:`Pin object <pyb.Pin>` which is connected to the CC3000 CS pin.
69+
- ``pin_en`` is a :ref:`Pin object <pyb.Pin>` which is connected to the CC3000 VBEN pin.
70+
- ``pin_irq`` is a :ref:`Pin object <pyb.Pin>` which is connected to the CC3000 IRQ pin.
2071

72+
All of these objects will be initialised by the driver, so there is no need to
73+
initialise them yourself. For example, you can use::
74+
75+
nic = network.CC3K(pyb.SPI(2), pyb.Pin.board.Y5, pyb.Pin.board.Y4, pyb.Pin.board.Y3)
2176

2277
Methods
2378
-------
2479

2580
.. method:: cc3k.connect(ssid, key=None, \*, security=WPA2, bssid=None)
2681

82+
Connect to a wifi access point using the given SSID, and other security
83+
parameters.
84+
85+
.. method:: cc3k.disconnect()
86+
87+
Disconnect from the wifi access point.
88+
89+
.. method:: cc3k.isconnected()
90+
91+
Returns True if connected to a wifi access point and has a valid IP address,
92+
False otherwise.
93+
94+
.. method:: cc3k.ifconfig()
95+
96+
Returns a 7-tuple with (ip, subnet mask, gateway, DNS server, DHCP server,
97+
MAC address, SSID).
98+
99+
.. method:: cc3k.patch_version()
27100

28-
class WIZnet5k
101+
Return the version of the patch program (firmware) on the CC3000.
102+
103+
.. method:: cc3k.patch_program('pgm')
104+
105+
Upload the current firmware to the CC3000. You must pass 'pgm' as the first
106+
argument in order for the upload to proceed.
107+
108+
Constants
109+
---------
110+
111+
.. data:: CC3K.WEP
112+
.. data:: CC3K.WPA
113+
.. data:: CC3K.WPA2
114+
115+
security type to use
116+
117+
class WIZNET5K
29118
==============
30119

31120
This class allows you to control WIZnet5x00 Ethernet adaptors based on
32121
the W5200 and W5500 chipsets (only W5200 tested).
33122

34123
Example usage::
35124

36-
import wiznet5k
37-
w = wiznet5k.WIZnet5k()
38-
print(w.ipaddr())
39-
w.gethostbyname('micropython.org')
40-
s = w.socket()
41-
s.connect(('192.168.0.2', 8080))
42-
s.send('hello')
43-
print(s.recv(10))
125+
import network
126+
nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
127+
print(nic.ifconfig())
128+
129+
# now use socket as usual
130+
...
131+
132+
For this example to work the WIZnet5x00 module must have the following connections:
44133

134+
- MOSI connected to X8
135+
- MISO connected to X7
136+
- SCLK connected to X6
137+
- nSS connected to X5
138+
- nRESET connected to X4
139+
140+
It is possible to use other SPI busses and other pins for nSS and nRESET.
45141

46142
Constructors
47143
------------
48144

49-
.. class:: WIZnet5k(spi, pin_cs, pin_rst)
145+
.. class:: WIZNET5K(spi, pin_cs, pin_rst)
146+
147+
Create a WIZNET5K driver object, initialise the WIZnet5x00 module using the given
148+
SPI bus and pins, and return the WIZNET5K object.
149+
150+
Arguments are:
151+
152+
- ``spi`` is an :ref:`SPI object <pyb.SPI>` which is the SPI bus that the WIZnet5x00 is
153+
connected to (the MOSI, MISO and SCLK pins).
154+
- ``pin_cs`` is a :ref:`Pin object <pyb.Pin>` which is connected to the WIZnet5x00 nSS pin.
155+
- ``pin_rst`` is a :ref:`Pin object <pyb.Pin>` which is connected to the WIZnet5x00 nRESET pin.
50156

51-
Create and return a WIZnet5k object.
157+
All of these objects will be initialised by the driver, so there is no need to
158+
initialise them yourself. For example, you can use::
52159

160+
nic = network.WIZNET5K(pyb.SPI(1), pyb.Pin.board.X5, pyb.Pin.board.X4)
53161

54162
Methods
55163
-------
56164

57-
.. method:: wiznet5k.ipaddr([(ip, subnet, gateway, dns)])
165+
.. method:: wiznet5k.ifconfig([(ip, subnet, gateway, dns)])
58166

59167
Get/set IP address, subnet mask, gateway and DNS.
60168

169+
When called with no arguments, this method returns a 4-tuple with the above information.
170+
171+
To set the above values, pass a 4-tuple with the required information. For example::
172+
173+
nic.ifconfig(('192.168.0.4', '255.255.255.0', '192.168.0.1', '8.8.8.8'))
174+
61175
.. method:: wiznet5k.regs()
62176

63-
Dump WIZnet5k registers.
177+
Dump the WIZnet5x00 registers. Useful for debugging.

0 commit comments

Comments
 (0)