Instability and LmacRxBlk:1 - SOLVED

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Instability and LmacRxBlk:1 - SOLVED

Post by pythoncoder » Sat Jul 22, 2017 5:49 am

While developing an MQTT application I was plagued by instability, including a situation where I stopped the application with ctrl-C and got to the REPL. Then after several seconds the board failed, repeatedly issuing 'LmacRxBlk:1'. The only ways to clear this were by pressing the reset button or power cycling. There were other strange symptoms.

The cause proved to be simple. On breaking into the program (and on occasions when it failed with an exception) the socket was not closed. It emerged that an open socket persists even when it is out of scope. In my case, after some time at the REPL, it received data from a test script: since no application was running to access the data the Espressif WiFi stack's buffer filled, provoking the error. This is readily solved with code along these lines:

Code: Select all

try:
    my_app.main()
except:
    raise  # Get debug traceback
finally:
    my_app.sock.close()
Since adopting this solution the ESP8266 has been entirely stable. Note that 'LmacRxBlk:1' can also occur non-fatally at runtime if incoming data is not processed in a timely fashion.

This behaviour is now referenced in the official docs http://docs.micropython.org/en/latest/e ... neral.html - section "Sockets and WiFi buffers overflow".
Peter Hinch
Index to my micropython libraries.

User avatar
deshipu
Posts: 1388
Joined: Thu May 28, 2015 5:54 pm

Re: Instability and LmacRxBlk:1 - SOLVED

Post by deshipu » Sat Jul 22, 2017 11:10 am

You can simply write:

Code: Select all

try:
    my_app.main()
finally:
    my_app.sock.close()

Post Reply