← index #8333PR #6120
Related · high · value 1.168
QUERY · ISSUE

Documentation Improvement Suggestion: esp8266/quickref.rst WebREPL UART + RXBUF

openby bai-yi-baiopened 2022-02-20updated 2024-09-08
docsport-esp8266

Hi,

I have a small suggestion for improving the ESP8266 documentation.
Specifically, https://github.com/micropython/micropython/blob/master/docs/esp8266/quickref.rst

Today I attempted to read serial output from a Plantower PMS-3003 air quality sensor. This device outputs a 24 bytes at a fairly consistent interval with the same 2 start characters. It also has a checksum included in the message. (I will create a github project for this in the near future documenting my work). I used the asyncio library to do this.

async def uart_receive():
    sreader = uasyncio.StreamReader(uart)
    while True:
        res = await sreader.read(24)

Initially, I wrote my code on an RP2, but eventually I want to connect this over Wi-Fi and log the data to a remote server, so I began bringing the code up one of my ESP8266 NodeMCU modules. However, an ESP8266 only has one UART, so I had to use the WebREPL.

Some findings which were not clear from the current MicroPython documentation:

  1. The Thonny IDE has the ability to connect to the WebREPL; this solves the HTTPS issue noted on https://micropython.org/webrepl/
  2. Setting up the WebREPL to use an existing Wi-Fi network was not clear. It would be helpful to create a separate section for users looking to do this and to instruct them to modify their boot.py in this manner:
def do_connect():
    sta_if = network.WLAN(network.STA_IF)
    if not sta_if.isconnected():
        print('connecting to network...')
        sta_if.active(True)
        sta_if.connect('<network>', '<password>')
        ap_if.active(False)
        while not sta_if.isconnected():
            pass
    print('network config:', sta_if.ifconfig())
    
do_connect()
  1. Next, I disconnected the REPL from the ESP8266's UART using uos.dupterm(None, 1) in the boot.py. I then set up the UART to receive data using uart = UART(the_uart, baudrate=9600, parity=None, stop=1, rx=Pin(3), tx=Pin(1)).

After a lot of debugging, had to make two changes to my code for the ESP8266:

With these changes I was able to simultaneously view the output of the air sensor from both the RP2 and ESP8266.

Therefore, I would suggest adding to the ESP8266's uart-serial-bus section that "Including a larger rxbuf value size may help with serial communications when using the WebREPL".

Also, reading the readexactly() and read() issue, it may help to include a link from the official Micropython documentation on uasyncio — asynchronous I/O scheduler Peter Hinch's tutorial: Async I/O ](https://github.com/peterhinch/micropython-async/blob/master/v3/docs/TUTORIAL.md#64-writing-streaming-device-drivers).

CANDIDATE · PULL REQUEST

esp8266 docs: Add quickref documentation for UART on esp8266

closedby nickcrabtreeopened 2020-06-07updated 2020-06-10
docs

This patch adds quickref documentation for the change in commit
afd0701bf7a9dcb50c5ab46b0ae88b303fec6ed3. This commit added the ability to
disable the REPL and hence use UART0 for serial communication on the esp8266,
but was not previously documented anywhere.

The text is largely taken from the commit message, with generic information on
using the UART duplicated from the Wipy quickref document.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied