Skip to content

Commit 78ccb44

Browse files
deshipudpgeorge
authored andcommitted
docs: Document esp module for ESP8266.
I document as much as I could guess from experiments and reading the code for the ``esp`` module for the ESP8266 port of Micropython. For now the tag has to be set manually with -t option when building, when we have properly split documentation, there will be a separate config file for esp8266 with that the tag "port_esp8266" set. To build use: make SPHINXOPTS="-t port_esp8266" html
1 parent 278d22c commit 78ccb44

3 files changed

Lines changed: 150 additions & 0 deletions

File tree

docs/library/esp.rst

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
:mod:`esp` --- functions related to the ESP8266
2+
===============================================
3+
4+
.. module:: esp
5+
:synopsis: functions related to the ESP8266
6+
7+
The ``esp`` module contains specific functions related to the ESP8266 module.
8+
9+
10+
Functions
11+
---------
12+
13+
.. function:: connect(ssid, password)
14+
15+
Connect to the specified wireless network, using the specified password.
16+
17+
.. function:: disconnect()
18+
19+
Disconnect from the currently connected wireless network.
20+
21+
.. function:: scan(cb)
22+
23+
Initiate scanning for the available wireless networks.
24+
25+
Once the scanning is complete, the provided callback function ``cb`` will
26+
be called once for each network found, and passed a tuple with information
27+
about that network.
28+
29+
.. function:: status()
30+
31+
Return the current status of the wireless connection.
32+
33+
The possible statuses are defined as constants:
34+
35+
* ``STAT_IDLE`` -- no connection and no activity,
36+
* ``STAT_CONNECTING`` -- connecting in progress,
37+
* ``STAT_WRONG_PASSWORD`` -- failed due to incorrect password,
38+
* ``STAT_NO_AP_FOUND`` -- failed because no access point replied,
39+
* ``STAT_CONNECT_FAIL`` -- failed due to other problems,
40+
* ``STAT_GOT_IP`` -- connection susccessful.
41+
42+
.. function:: getaddrinfo((hostname, port, lambda))
43+
44+
Initiate resolving of the given hostname.
45+
46+
When the hostname is resolved, the provided ``lambda`` callback will be
47+
called with two arguments, first being the hostname being resolved,
48+
second a tuple with information about that hostname.
49+
50+
Classes
51+
-------
52+
53+
.. toctree::
54+
:maxdepth: 1
55+
56+
esp.socket.rst

docs/library/esp.socket.rst

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
class socket -- network socket
2+
==============================
3+
4+
``socket`` is an object that represents a network socket. Example usage::
5+
6+
socket = esp.socket()
7+
socket.onrecv(print)
8+
socket.connect(('207.58.139.247', 80))
9+
socket.send('GET /testwifi/index.html HTTP/1.0\r\n\r\n')
10+
11+
Constructors
12+
------------
13+
14+
.. class:: esp.socket()
15+
16+
Create and return a socket object.
17+
18+
19+
TCP Methods
20+
-----------
21+
22+
.. method:: socket.connect(addr)
23+
24+
Connect to the adress and port specified in the ``addr`` tuple.
25+
26+
.. method:: socket.close()
27+
28+
Close the connection.
29+
30+
.. method:: socket.accept()
31+
32+
Accept a single connection from the connection queue.
33+
34+
.. method:: socket.listen(backlog)
35+
36+
Start listening for incoming connections.
37+
38+
Note: Only one socket can be listening for connections at a time.
39+
40+
.. method:: socket.bind(addr)
41+
42+
Bind the socket to the address and port specified by the ``addr`` tuple.
43+
44+
.. method:: socket.send(buf)
45+
46+
Send the bytes from ``buf``.
47+
48+
.. method:: socket.recv()
49+
50+
Receive and return bytes from the socket.
51+
52+
53+
UDP Methods
54+
-----------
55+
56+
.. method:: socket.sendto(data, addr)
57+
58+
Placeholder for UDP support, not implemented yet.
59+
60+
.. method:: socket.recvfrom(addr)
61+
62+
Placeholder for UDP support, not implemented yet.
63+
64+
65+
Callback Setter Methods
66+
-----------------------
67+
68+
.. method:: onconnect(lambda)::
69+
70+
When connection is established, call the callback ``lambda``.
71+
72+
.. method:: onrecv(lambda)::
73+
74+
When data is received, call the callback ``lambda``.
75+
76+
.. method:: onsent(lamda)::
77+
78+
What data is finished sending, call the callback ``lambda``.
79+
80+
.. method:: ondisconnect(lambda)::
81+
82+
Call the callback ``lambda`` when the connection is closed.

docs/library/index.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,15 @@ The following libraries are specific to the pyboard.
6565

6666
pyb.rst
6767
network.rst
68+
69+
.. only:: port_esp8266
70+
71+
Libraries specific to the ESP8266
72+
---------------------------------
73+
74+
The following libraries are specific to the ESP8266.
75+
76+
.. toctree::
77+
:maxdepth: 2
78+
79+
esp.rst

0 commit comments

Comments
 (0)