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


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


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:

  • Arduino Ethernet
  • Arduino Ethernet Shield
  • Arduino YUN – use the included YunClient in place of EthernetClient, and be sure to do a Bridge.begin() first
  • Arduino WiFi Shield - if you want to send packets greater than 90 bytes with this shield, enable the MQTT_MAX_TRANSFER_SIZE option in PubSubClient.h.
  • Sparkfun WiFly Shield – when used with this library
  • Intel Galileo/Edison
  • ESP8266

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.


Nick O'Leary - @knolleary


This library is released under the MIT License.

Change History

The complete change history is available on GitHub.

  • 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
  • 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
  • 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
  • Improved keepalive handling
  • Updated to the Arduino-1.0 API
  • Added ability to publish retained messages
  • Added default constructor
  • Fixed compile error when used with arduino-0021 or later
  • Fixed connection lost handling
  • Fixed packet reading bug
  • Fixed compile error when used with arduino-0016 or later
  • Reduced size of library
  • Added support for Will messagesClarified licensing – see LICENSE.txt
  • 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