Conversation
EspSoftwareSerial keeps two receive buffers: the byte buffer and an ISR buffer with one 32-bit entry per bit transition. We pass the same capacity for both, but a byte at 8E1 produces up to 11 transitions, so a 256 entry ISR buffer holds roughly 25 bytes, about 0.1 s of data at 2400 baud. Any loop() stall longer than that (serving the web UI, an MQTT publish burst, a LittleFS write) overflows the ISR buffer and the reader reports "Serial buffer full" even though the byte buffer is almost empty. Scale the ISR buffer by SWSERIAL_ISR_BUFFER_FACTOR (default 4: ~0.4 s of slack, 1 kB extra with the default 64 byte buffer). The library default of 11 would be correct but costs 11 kB with a 256 byte buffer, which ESP8266 cannot afford. The factor can be overridden at build time. Verified on an ESP8266 reading an Aidon 6525 over GPIO5 (software serial): with the factor at 8, loading the web UI over a weak WiFi link no longer produces serial buffer overflows.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
EspSoftwareSerial keeps two receive buffers: the byte buffer and an ISR buffer with one 32-bit entry per bit transition.
PassiveMeterCommunicatorpasses the same capacity for both. A byte at 8E1 produces up to 11 transitions, so a 256 entry ISR buffer holds roughly 25 bytes, about 0.1 s of data at 2400 baud. Anyloop()stall longer than that (serving the web UI, an MQTT publish burst, a LittleFS write) overflows the ISR buffer and the reader reports "Serial buffer full" although the byte buffer is almost empty. The library's own documentation suggestsbufCapacity * (2 + data bits + parity).Fix
Scale the ISR buffer by
SWSERIAL_ISR_BUFFER_FACTOR(default 4: about 0.4 s of slack, 1 kB extra with the default 64 byte buffer). The library default of 11 would be exact but costs 11 kB with a 256 byte buffer, which ESP8266 cannot afford. The factor can be overridden with-D SWSERIAL_ISR_BUFFER_FACTOR=n.Tested
ESP8266 reading an Aidon 6525 (2400 baud 8E1) on GPIO5 via software serial over a weak WiFi link. Before: loading the web UI reliably produced "Serial buffer overflow" in the debug log. With the factor raised, the same test produced none.