I am developing an application that is supposed to read a lot of text data from HW UART. For some reason it reads only first 15 bytes, and the rest of the message disappears. I tried both asyncio and raw UART approaches - same behavior. I also tried to use UART IRQ - looks like this is not supported in ESP8266 port.
Here is my sender (runs on a host Windows machine)
Code: Select all
import serial
import time
ser = serial.Serial('COM4', baudrate=115200)
i=0
while True:
l = "Hello World ABC " + str(i) + "\n"
i = i+1
ser.write(l.encode()) # write a string
time.sleep(1)
Code: Select all
import machine
import network
import webrepl
import uos
import time
connectWiFi('ssid', 'wifi_pw') # No problems with WiFi connectivity
webrepl.start() # detaching REPL from HW uart, use WebREPL only
uos.dupterm(None, 1)
uart = machine.UART(0, 115200)
while True:
s = uart.read(128)
if s:
print("s = " + ' '.join('{:02x}'.format(x) for x in s))
l = s.decode()
print(l)
# Some network connectivity code here in future
Code: Select all
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 30 0a
Hello World ABC0
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 31 0a
Hello World ABC1
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43
Hello World ABC
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 33 0a
Hello World ABC3
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 34 0a
Hello World ABC4
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 35 0a
Hello World ABC5
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43
Hello World ABC
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 37 0a
Hello World ABC7
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 38 0a
Hello World ABC8
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 39 0a
Hello World ABC9
s = 48 65 6c 6c 6f 20 57 6f 72 6c 64 20 41 42 43 31 30 0a
Hello World ABC10
There will be some processing of the received message, and particularly sending the data to a server over a TCP connection. I tried to use asyncio, but have the same truncation at 15 byte boundary. Messages are pretty infrequent (once a second), but the baud rate seems to matter.
Is this because some heavy processing (e.g. prints, sending data over the network for WebREPL) which causes missing the rest of the message? Any thoughts?