--- layout: default title: Arduino Client for MQTT ---

This library provides a client for doing simple publish/subscribe messaging with a server that supports MQTT

For more information about MQTT, visit mqtt.org.

Download

The latest version of the library can be downloaded from GitHub.

Documentation

The library comes with a number of example sketches. See File > Examples > PubSubClient within the Arduino application.

Full API Documentation

Compatible Hardware

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:

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.

Author

Nick O'Leary - @knolleary

License

This library is released under the MIT License.

Change History

The complete change history is available on GitHub.

2.0
  • Add (and default to) MQTT 3.1.1 support
  • Fix PROGMEM handling for Intel Galileo/ESP8266
  • Add overloaded constructors for convenience
  • Add chainable setters for server/callback/client/stream
  • Add state function to return connack return code
1.9
  • Do not split MQTT packets over multiple calls to _client->write()
  • API change: All constructors now require an instance of Client to be passed in.
  • Fixed example to match 1.8 api changes - dpslwk
  • Added username/password support - WilHall
  • Added publish_P - publishes messages from PROGMEM - jobytaffey
1.8
  • KeepAlive interval is configurable in PubSubClient.h
  • Maximum packet size is configurable in PubSubClient.h
  • API change: Return boolean rather than int from various functions
  • API change: Length parameter in message callback changed from int to unsigned int
  • Various internal tidy-ups around types
  • Able to specify server address by DNS name
1.7
  • Improved keepalive handling
  • Updated to the Arduino-1.0 API
1.6
  • Added ability to publish retained messages
1.5
  • Added default constructor
  • Fixed compile error when used with arduino-0021 or later
1.4
  • Fixed connection lost handling
1.3
  • Fixed packet reading bug
1.2
  • Fixed compile error when used with arduino-0016 or later
1.1
  • Reduced size of library
  • Added support for Will messagesClarified licensing – see LICENSE.txt
1.0
  • Only Quality of Service (QOS) 0 messaging is supported
  • The maximum message size, including header, is 128 bytes
  • The keepalive interval is set to 30 seconds
  • No support for Will messages