NodeMCU - What Are MQTT & Pubsubclient?

by osoyooproduct in Circuits > Microcontrollers

127 Views, 1 Favorites, 0 Comments

NodeMCU - What Are MQTT & Pubsubclient?

QQ图片20170215182323.jpg

In order to make better use of nodemcu to complete more interesting IOT project,we will learn what is MQTT and what is the psbcubclient in this lesson.For those who already familiar with MQTT / Pubsubclient can skip following peragraph,for biginers read for these introduction.

What Is MQTT Protocol?

MQTT is a machine-to-machine (M2M)/”Internet of Things” connectivity protocol. It was designed as an extremely lightweight publish/subscribe messaging transport.In a simple language when you want to communicate to your controller through mobile or a web browser you need a communication protocol and MQTT does that magic.MQTT is a message queuing telemetry transport. It is specifically designed for automation.

MQTT works on publish subscribe events. It requires MQTT broker in between. It is very vast subject. To learn more about MQTT visit: http://mqtt.org/ or: https://github.com/mqtt/mqtt.github.io/wiki

What Is Pubsubclient?

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

Limitations

  • It can only publish QoS 0 messages. It can subscribe at QoS 0 or QoS 1.
  • The maximum message size, including header, is 128 bytes by default. This is configurable via MQTT_MAX_PACKET_SIZE in PubSubClient.h.
  • The keepalive interval is set to 15 seconds by default. This is configurable via MQTT_KEEPALIVE in PubSubClient.h.
  • 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.

Download

The latest version of the library can be downloaded from GitHub. https://github.com/knolleary/pubsubclient/releases...

Documentation

The library comes with a number of example sketches. See File > Examples > PubSubClient within the Arduino application. Full API Documentation https://pubsubclient.knolleary.net/api.html

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 EthernetArduino
  • 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 https://github.com/dpslwk/WiFly
  • TI CC3000 WiFi – library https://github.com/sparkfun/SFE_CC3000_Library
  • Intel Galileo/Edison
  • ESP8266(NodeMCU)

Author: Nick O’Leary – @knolleary

License This library is released under the MIT License.