@@ -20,7 +20,7 @@ Load this module from the :doc:`esp` module. A simple example would be:
20
20
21
21
e = espnow.ESPNow()
22
22
e.init()
23
- peer = b'0\xae\xa4XC\xd0 ' # MAC address of peer's wifi interface
23
+ peer = b'\xbb\xbb\xbb\xbb\xbb\xbb ' # MAC address of peer's wifi interface
24
24
e.add_peer(peer)
25
25
26
26
e.send("Starting...") # Send to all peers
@@ -39,7 +39,7 @@ Load this module from the :doc:`esp` module. A simple example would be:
39
39
40
40
e = espnow.ESPNow()
41
41
e.init()
42
- peer = b'0\xae\xa4XC\xa0 ' # MAC address of peer's wifi interface
42
+ peer = b'\xaa\xaa\xaa\xaa\xaa\xaa ' # MAC address of peer's wifi interface
43
43
e.add_peer(peer)
44
44
45
45
print(e.irecv())
@@ -70,14 +70,14 @@ Configuration
70
70
protocol, including:
71
71
72
72
- initialise the ESPNow data structures,
73
- - allocate the send and recv data buffers ,
73
+ - allocate the recv data buffer ,
74
74
- invoke esp_now_init() and
75
75
- register the send and recv callbacks.
76
76
77
77
.. method :: ESPNow.deinit()
78
78
79
- De-initialise the Espressif ESPNow software stack (esp_now_deinit()), disable
80
- the interrupt callbacks and deallocate the send and recv data buffers .
79
+ De-initialise the Espressif ESPNow software stack (esp_now_deinit()),
80
+ disable callbacks and deallocate the recv data buffer .
81
81
82
82
**Note **: `deinit() ` will also deregister all peers which must be
83
83
re-registered after `init() `.
@@ -89,24 +89,18 @@ Configuration
89
89
Get or set configuration values of the ESPNow interface. To get a value the
90
90
parameter name should be quoted as a string, and just one parameter is
91
91
queried at a time. To set values use the keyword syntax, and one or more
92
- parameters can be set at a time. Invocation with no arguments will return a
93
- dict of all parameter names and values.
92
+ parameters can be set at a time.
94
93
95
94
Currently supported values are:
96
95
97
- - ``txbuf ``: *(default=140) * Get/set the size in bytes of the internal
98
- buffer used to store send response data. Increasing this allows better
99
- handling of bursty outgoing/incoming data.
100
-
101
- - ``rxbuf ``: *(default=514) * Get/set the size in bytes of the internal
96
+ - ``rxbuf ``: *(default=516) * Get/set the size in bytes of the internal
102
97
buffer used to store incoming ESPNow packet data. The default size is
103
- selected to fit two
104
- max-sized ESPNow packets (250 bytes) with associated mac_address (6 bytes)
105
- and a message byte count (1 byte) plus buffer overhead. Increase this if
106
- you expect to receive a lot of large packets or expect bursty incoming
107
- traffic.
98
+ selected to fit two max-sized ESPNow packets (250 bytes) with associated
99
+ mac_address (6 bytes) and a message byte count (1 byte) plus buffer
100
+ overhead. Increase this if you expect to receive a lot of large packets
101
+ or expect bursty incoming traffic.
108
102
109
- **Note: ** The send and recv buffers are only allocated by `ESPNow.init() `.
103
+ **Note: ** The recv buffer is only allocated by `ESPNow.init() `.
110
104
Changing these values will have no effect until the next call of
111
105
`ESPNow.init() `.
112
106
@@ -115,7 +109,7 @@ Configuration
115
109
116
110
.. method :: ESPNow.clear(True)
117
111
118
- Clear out any data in the recv (and send-response) buffers . Use this to clean
112
+ Clear out any data in the recv buffer . Use this to clean
119
113
up after receiving a ``Buffer error `` (should not happen). All data in the
120
114
buffers will be discarded. An arg of `True ` is required to guard against
121
115
inadvertent use.
@@ -131,34 +125,43 @@ Sending and Receiving Data
131
125
--------------------------
132
126
133
127
A wifi interface (``network.STA_IF `` or ``network.AP_IF ``) must be
134
- `active()<network.WLAN.active> `
135
- before messages can be sent or received, but it is not necessary to connect or
136
- configure the WLAN interface. For example::
128
+ `active()<network.WLAN.active> ` before messages can be sent or received,
129
+ but it is not necessary to connect or configure the WLAN interface.
130
+ For example::
137
131
138
132
import network
139
133
140
134
w0 = network.WLAN(network.STA_IF)
141
135
w0.active(True)
142
136
143
- .. method :: ESPNow.send(mac, msg, [sync])
137
+ .. method :: ESPNow.send(mac, msg, [sync=True])
138
+ ESPNow.send(msg)
144
139
145
140
Send the data contained in ``msg `` to the peer with given network ``mac ``
146
- address. ``mac `
629A
` must be a byte string exactly 6 bytes long and ``msg `` must
147
- be a string or byte-string such that ``0<len(msg)<=espnow.MAX_DATA_LEN ``
148
- (250) bytes. If ``mac `` is ``None `` the message will be sent to all
149
- registered peers as an ESP-Now broadcast.
141
+ address. In the second form, ``mac=None `` and ``sync=True ``.
142
+
143
+ Arguments:
150
144
151
- - If ``sync=True `` send ``msg `` to the peer and wait for a response (or not).
152
- Returns ``False `` if any peers fail to respond.
145
+ - ``mac ``: byte string exactly 6 bytes long or ``None ``
146
+ - ``msg ``: string or byte-string such that
147
+ ``0<len(msg)<=espnow.MAX_DATA_LEN `` (250) bytes
148
+ - ``sync ``:
153
149
154
- - If ``sync=False `` handover ``msg `` to the esp_now software stack for
155
- transmission and return immediately.
156
- Responses from the peers will be discarded.
157
- Always returns ``True ``.
150
+ - ``True ``: (default) send ``msg `` to the peer and wait for a response
151
+ (or not). Returns ``False `` if any peers fail to respond.
152
+
153
+ - ``False `` handover ``msg `` to the esp_now software stack for
154
+ transmission and return immediately.
155
+ Responses from the peers will be discarded.
156
+ Always returns ``True ``.
157
+
158
+ If ``mac `` is ``None `` the message will be sent to all
159
+ registered peers as an ESP-Now broadcast.
158
160
159
161
**Note **: A peer will respond with success if it's wifi interface is
160
- active(), regardless of whether it has initialised it's ESP-Now system or
161
- is actively listening for ESP-Now traffic (see the Espressif ESP-Now docs).
162
+ active() and set to the same channel as the sender, regardless of whether
163
+ it has initialised it's ESP-Now system or is actively listening for ESP-Now
164
+ traffic (see the Espressif ESP-Now docs).
162
165
163
166
.. method :: ESPNow.recv([timeout])
164
167
@@ -169,30 +172,36 @@ configure the WLAN interface. For example::
169
172
170
173
- ``msg `` is the message/data sent from the peer.
171
174
172
- ``Timeout `` optionally sets a timeout (in milliseconds) for the read. The
175
+ ``timeout `` optionally sets a timeout (in milliseconds) for the read. The
173
176
default timeout can be set in `ESPNow.config() `.
174
177
175
- **Note **: repeatedly calling `irecv ()<ESPNow.send ()> ` will exercise the
176
- micropython garbage collection as new storage is allocated for each new<
F438
/div>
178
+ **Note **: repeatedly calling `recv ()<ESPNow.recv ()> ` will exercise the
179
+ micropython memory allocation as new storage is allocated for each new
177
180
message and tuple. Use `irecv()<ESPNow.irecv()> `
178
181
for a more memory-efficient option.
179
182
180
183
.. method :: ESPNow.irecv([timeout])
181
184
182
185
As for `recv()<ESPNow.recv()> ` except that ``irecv() `` will return a
183
- "callee-owned" tuple.
184
- That is, memory will be allocated for the tuple and byte strings on the
185
- first call and re-used for subsequent calls. You must make copies if you
186
+ "callee-owned" tuple of bytearrays.
187
+ That is, memory will be allocated once for the tuple and byte strings on
188
+ invocation of espnow.ESPNow() and re-used for subsequent calls to
189
+ `irecv()<ESPNow.irecv()> `. You must make copies if you
186
190
wish to keep the values across calls to ``irecv() ``.
187
191
188
192
.. method :: ESPNow.stats()
189
193
190
- Return a 4-tuple containing the number of packets sent/received/lost:
191
- ``(sent_packets, send_responses, recv_packets, lost_rx_packets) ``. Packets
192
- are *lost * when the recv buffers are full. To reduce packet loss,
193
- increase the ``txbuf `` and ``rxbuf `` config parameters and ensure you are
194
+ Return a 5-tuple containing the number of packets sent/received/lost::
195
+
196
+ (sent_packets, sent_responses, sent_failures, recv_packets, lost_rx_packets)
197
+
198
+ Incoming packets are *dropped * when the recv buffers are full. To reduce
199
+ packet loss, increase the ``rxbuf `` config parameters and ensure you are
194
200
in a tight loop calling `irecv()<ESPNow.irecv()> ` as quickly as possible.
195
201
202
+ **Note **: Dropped packets will still be acknowledged to the sender as
203
+ received.
204
+
196
205
Iteration over ESPNow
197
206
---------------------
198
207
@@ -209,8 +218,8 @@ for a message.
209
218
Peer Management
210
219
---------------
211
220
212
- The ESP-Now protocol requires that other devices (peers) must be * registered *
213
- before we can `send()<ESPNow.send()> ` them messages.
221
+ The Esspresif ESP-Now software requires that other devices (peers) must be
222
+ * registered * before we can `send()<ESPNow.send()> ` them messages.
214
223
215
224
.. method :: ESPNow.add_peer(mac, [lmk], [channel], [ifidx], [encrypt])
216
225
ESPNow.add_peer(mac, 'param'=value, ...)
@@ -222,8 +231,7 @@ before we can `send()<ESPNow.send()>` them messages.
222
231
- ``lmk ``: The Local Master Key (LMK) key used to encrypt data transfers
223
232
with this peer (if the *encrypt * parameter is set to *True *). Must be:
224
233
225
- - a byte-string of length ``<= espnow.KEY_LEN `` (16 bytes) (the key will be
226
- padded to the right with zeroes), or
234
+ - a byte-string of length ``espnow.KEY_LEN `` (16 bytes), or
227
235
- any non-`True ` python value (default= ``b'' ``), signifying an *empty * key
228
236
which will disable encryption.
229
237
0 commit comments