Skip to content

Commit 8ccd05b

Browse files
committed
Document ESP32 support. Remove redundant ESP32 hacks.
1 parent 0b4c19c commit 8ccd05b

6 files changed

+17
-37
lines changed

README.md

+17-28
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Introduction
22

33
This library provides a resilient full duplex communication link between a WiFi
4-
connected board and a server on the wired LAN. The board may be an ESP8266 or
5-
other target including the Pyboard D. The design is such that the code can run
6-
for indefinite periods. Temporary WiFi or server outages are tolerated without
7-
message loss.
4+
connected board and a server on the wired LAN. The board may be an ESP8266,
5+
ESP32 or other target including the Pyboard D. The design is such that the code
6+
can run for indefinite periods. Temporary WiFi or server outages are tolerated
7+
without message loss.
88

99
The API is simple and consistent between client and server applications,
1010
comprising `write` and `readline` methods. Guaranteed message delivery is
@@ -22,9 +22,8 @@ reliability is therefore paramount. Security is also a factor for endpoints
2222
exposed to the internet.
2323

2424
Under MicroPython the available hardware for endpoints is limited. Testing has
25-
been done on the ESP8266 and the Pyboard D. The ESP32 running official firmware
26-
V1.10 remains incapable of coping with WiFi outages: see
27-
[Appendix 1 ESP32](./README.md#appendix-1-esp32).
25+
been done on the ESP8266, ESP32 and the Pyboard D. The ESP32 must run firmware
26+
dated on or after 25th March 2019.
2827

2928
The ESP8266 remains as a readily available inexpensive device which, with care,
3029
is capable of long term reliable operation. It does suffer from limited
@@ -114,7 +113,6 @@ but one which persists through outages and offers guaranteed message delivery.
114113
10. [How it works](./README.md#10-how-it-works)
115114
10.1 [Interface and client module](./README.md#101-interface-and-client-module)
116115
10.2 [Server module](./README.md#102-server-module)
117-
[Appendix 1 ESP32](./README.md#appendix-1-esp32)
118116

119117
# 2. Design
120118

@@ -172,7 +170,8 @@ installation on that platform.
172170

173171
#### Firmware/Dependency
174172

175-
On all client platforms firmware must be V1.10 or later.
173+
Firmware must be V1.10 or later; on ESP32 it must be more recent, specifically
174+
builds dated 25th March 2019 or later.
176175

177176
On ESP8266 it is easiest to use the latest release build of firmware: such
178177
builds incorporate `uasyncio` as frozen bytecode. Daily builds do not.
@@ -190,7 +189,8 @@ On ESP8266 it is necessary to
190189

191190
#### Preconditions
192191

193-
The demo programs store client configuration data in a file `local.py`. This
192+
The demo programs store client configuration data in a file `local.py`. Each
193+
demo has its own `local.py` located in the directory of the demo code. This
194194
contains the following constants which should be edited to match local
195195
conditions:
196196

@@ -312,8 +312,9 @@ from micropython_iot.qos import c_qos
312312
#### The fast qos demo
313313

314314
This tests the option of concurrent `qos` writes. This is an advanced feature
315-
discussed in [section 7.1](./README.md#71-the-wait-argument). To run the demo,
316-
on the server navigate to the parent directory of `micropython_iot` and run:
315+
discussed in [section 7.1](./README.md#71-the-wait-argument). This demo runs
316+
but is not resilient on ESP32. See the above link. To run the demo, on the
317+
server navigate to the parent directory of `micropython_iot` and run:
317318
```
318319
python3 -m micropython_iot.qos.s_qos_fast
319320
```
@@ -753,6 +754,10 @@ number of such `qos` messages sent in quick succession: on ESP8266 clients
753754
buffer overflows can occur. Demands on `uasyncio` are increased: it may be
754755
necessary to amend the default queue sizes in `get_event_loop`.
755756

757+
The ESP32 is not resilient under these circumstances. Setting `wait=False` is
758+
not recommended. If used, applications should be tested to verify resilience in
759+
the face of WiFi outages.
760+
756761
If messages are sent with `wait=False` there is a chance that they may not be
757762
received in the order in which they were sent. As described above, in the event
758763
of `qos` message loss, retransmission occurs after a timeout period has
@@ -888,19 +893,3 @@ messages to the client. Application code which blocks the scheduler can cause
888893
this not to be scheduled in a timely fashion with the result that the client
889894
declares an outage and disconnects. The consequence is a sequence of disconnect
890895
and reconnect events even in the presence of a strong WiFi signal.
891-
892-
# Appendix 1 ESP32
893-
894-
Using official firmware V1.10 the ESP32 seems incapable of recovering from an
895-
outage. The client initially connects and runs. When an outage occurs this is
896-
detected in the usual way by a timeout. Unfortunately I failed to discover a
897-
strategy for detecting when the outage was over. The station interface
898-
`isconnected` method always returns `True` even if you explicitly disconnect.
899-
You can issue a `connect` statement but I could find no way to determine
900-
whether the attempt was successful.
901-
902-
In my view the ESP32 running official MicroPython remains unsuitable for a
903-
resilient link.
904-
905-
Contributions and suggestions are invited. Also any test results for the
906-
Loboris port.

client.py

-9
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
WDT_CANCEL = const(-2)
2828
WDT_CB = const(-3)
2929

30-
ESP32 = platform == 'esp32' or platform == 'esp32_LoBo'
31-
3230
# Message ID generator. Only need one instance on client.
3331
getmid = gmid()
3432
gc.collect()
@@ -151,11 +149,6 @@ async def bad_wifi(self):
151149
s = self._sta_if
152150
if s.isconnected():
153151
return
154-
if ESP32: # Is this still needed?
155-
s.disconnect()
156-
utime.sleep_ms(20) # Hopefully no longer required
157-
await asyncio.sleep(1)
158-
159152
while True: # For the duration of an outage
160153
s.connect(self._ssid, self._pw)
161154
if await self._got_wifi(s):
@@ -175,8 +168,6 @@ def _close(self):
175168
# Await a WiFi connection for 10 secs.
176169
async def _got_wifi(self, s):
177170
for _ in range(20): # Wait t s for connect. If it fails assume an outage
178-
if ESP32: # Hopefully no longer needed
179-
utime.sleep_ms(20)
180171
await asyncio.sleep_ms(500)
181172
self._feed(0)
182173
if s.isconnected():

images/block diagram.odg

676 Bytes
Binary file not shown.

images/block_diagram.png

-4.01 KB
Loading

images/block_diagram_orig.odg

50 Bytes
Binary file not shown.

images/block_diagram_orig.png

-614 Bytes
Loading

0 commit comments

Comments
 (0)