This library provides a client for doing simple publish/subscribe messaging with a server that supports MQTT.
This is a fork of the repository knolleary/pubsubclient v2.8, which was last updated in May 20, 2020. There was an update approach in #1045, but it's also stale.
I tried lot's of different other MQTT libs, but they need more resources than PubSubClient or lacking maintenance as well:
- https://github.com/256dpi/arduino-mqtt
- https://github.com/hideakitai/MQTTPubSubClient
- https://github.com/bertmelis/espMqttClient
- https://github.com/arduino-libraries/ArduinoMqttClient
- https://github.com/thingsboard/pubsubclient
Since there was no progress I decided to merge the most important PRs manually and publish a new major version. I also renamed to PubSubClient3 to have a similar but different name of the library.
I appreciate every contribution to this library.
The library comes with a number of example sketches. See File > Examples > PubSubClient within the Arduino application.
Full API documentation is available here: https://hmueller01.github.io/pubsubclient3/api
-
The client is based on the MQTT Version 3.1.1 specification with some limitations.
-
It can publish at QoS 0, 1 or 2.
WARNING: No retransmission is supported to keep the library as much memory friendly as possible.
Note: Without retransmission support, the publish QoS is only meaningful when the broker sends your message to a subscriber, supposing that the subscriber subscribes with a QoS greater then or equal to the publish QoS. Consider that MQTT runs over TCP, so retransmission isn't really required in most cases, especially when publishing to the broker.
-
It can subscribe at QoS 0 or QoS 1.
-
The maximum message size, including header, is 256 bytes by default. This is configurable via
MQTT_MAX_PACKET_SIZE
inPubSubClient.h
or can be changed by callingPubSubClient::setBufferSize(size)
. -
The keepalive interval is set to 15 seconds by default. This is configurable via
MQTT_KEEPALIVE
inPubSubClient.h
or can be changed by callingPubSubClient::setKeepAlive(keepAlive)
. -
The client uses MQTT 3.1.1 by default. It can be changed to use MQTT 3.1 by changing value of
MQTT_VERSION
inPubSubClient.h
.
The library uses the Arduino Ethernet Client api for interacting with the underlying network hardware. This means it Just Works with a growing number of boards and shields, including:
- Arduino Ethernet
- Arduino Ethernet Shield
- Arduino YUN – use the included
YunClient
in place ofEthernetClient
, and be sure to do aBridge.begin()
first - Arduino WiFi Shield - if you want to send packets > 90 bytes with this shield,
enable the
MQTT_MAX_TRANSFER_SIZE
define inPubSubClient.h
. - Sparkfun WiFly Shield – library
- TI CC3000 WiFi - library
- Intel Galileo/Edison
- ESP8266
- ESP32
The library cannot currently be used with hardware based on the ENC28J60 chip – such as the Nanode or the Nuelectronics Ethernet Shield. For those, there is an alternative library available.
This code is released under the MIT License.