Based on the Adafruit MQTT library, this library enables async-like behavior for MQTT and WiFi on single-threaded microcontrollers.
Most Arduino network libraries are filled with delay()
and while(true)
loops in order to
ensure delivery and receipt of packet information. This library instead reads packets and
completes tasks over multiple loops.
This library is a work-in-progress and is currently only tested with the
WiFiNiNA library. Other WiFi libraries
will likely work as well, possibly with minor changes. Because the WiFi connection loop cannot
be abstracted to a single connect()
method, wider compatibility is not easy. If you'd like to
adapt this library for a different WiFi driver, look to the wifiSetup()
, wifiConnect()
, and
mqttConnect()
and related methods. If you'd like to adapt the library for ethernet, these same
methods could likely be simplified or removed from the loop.
The easiest way to install is to search for MQTT_Looped
in the Library Manager in the Arduino IDE or VS Code extension.
See examples for example usage.