Skip to content

A client library for the Arduino Ethernet Shield that provides support for MQTT.

License

Notifications You must be signed in to change notification settings

mkeras/pubsubclient_iiot

 
 

Repository files navigation

PubSubClient Fork

This library is a fork of Nick O'Leary's PubSubClient. The only changes I have made is an additional connect method implementation:

boolean connect(const char* id, const char* user, const char* pass, const char* willTopic, uint8_t willQos, boolean willRetain, const uint8_t* willBuffer, size_t willLength, boolean cleanSession);

The purpose is to accept will payloads in serial formats like google protobufs. A serialized protobuf payload can contain 0's, which is the end of string in a char, thus resulting in errors when using such a payload as a const char* willMessage. By having on option for const uint8_t* willBuffer and size_t willLength, this problem is resolved.

Refactored the header and cpp files, but the definitions of the library remain the same, meaning PubSubClient and this library cannot be used at the same time.

Arduino Client for MQTT

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

I have added another connect() method for allowing a byte buffer and buffer length to be passed for death payload instead of a const char. This is so the death payload can be in a serialized format like google protobuf and not run into issues with const char in the case that there is a 0 value byte in the payload.

Examples

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

Full API documentation is available here: https://pubsubclient.knolleary.net

Limitations

  • It can only publish QoS 0 messages. 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 in PubSubClient.h or can be changed by calling PubSubClient::setBufferSize(size).
  • The keepalive interval is set to 15 seconds by default. This is configurable via MQTT_KEEPALIVE in PubSubClient.h or can be changed by calling PubSubClient::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 in PubSubClient.h.

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 > 90 bytes with this shield, enable the MQTT_MAX_TRANSFER_SIZE define in PubSubClient.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.

License

This code is released under the MIT License.

About

A client library for the Arduino Ethernet Shield that provides support for MQTT.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C++ 88.6%
  • Python 9.8%
  • C 1.1%
  • Makefile 0.5%