8000 Documentation Improvement Suggestion: esp8266/quickref.rst WebREPL UART + RXBUF · Issue #8333 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content
@bai-yi-bai

Description

@bai-yi-bai

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).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0