sparkleondata / pubsubclient

A client library for the ESP8266 that provides support for MQTT

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A client library for the ESP8266 (using the Arduino environment) that provides support for MQTT.

Modified from Nicholas O'Leary's original for the Arduino + Ethernet shield:
http://knolleary.net/arduino-client-for-mqtt/

See here for the ESP8266-Arduino work:
https://github.com/esp8266/Arduino

New features
------------

A whole set of MQTT classes has been added, one for each message type.
This moved a good amount of code out of the PubSubClient class, leaving it to
handle the high-level flow of the protocol. The MQTT classes handle getting
data into and out of the messages.

The PubSubClient class operates mostly as it did before. However, the
connect(), publish(), subscribe(), and unsubscribe() methods can now take an
appropriate MQTT object. This allows extra options to be set e.g QoS on
publish, or multiple topics with one (un)subscribe message.

You can use the MQTT classes and their chainable setter methods like this:

client.connect(MQTT::Connect("clientId")
               .set_clean_session()
               .set_will("status", "down")
               .set_auth("username", "password)
               .set_keepalive(30)
              );

client.publish(MQTT::Publish("topic", "payload")
               .set_retain()
               .set_qos(1, client.next_packet_id())
               .set_dup()
              );

client.subscribe(MQTT::Subscribe(client.next_packet_id())
                 .add_topic("topic1")
                 .add_topic("topic2", 1)	// optional qos value
                );

client.unsubscribe(MQTT::Unsubscribe(client.next_packet_id())
                   .add_topic("topic")
                  );

See also the mqtt_auth or mqtt_qos example sketches for how this is used.

About

A client library for the ESP8266 that provides support for MQTT

License:MIT License


Languages

Language:C++ 79.7%Language:Python 9.6%Language:Arduino 9.1%Language:C 1.1%Language:Makefile 0.5%