Listener

The class declaration for the Listener class looks like this:

class Listener : public mosqpp::mosquittopp {          // public:          Listener(string clientId, string host, int port, string user, string pass);          ~Listener();          void on_connect(int rc);          void on_message(const struct mosquitto_message* message);          void on_subscribe(int mid, int qos_count, const int* granted_qos);          void sendMessage(string topic, string& message);          void sendMessage(string& topic, char* message, int msgLength); };

This class provides a simple API to connect to an MQTT broker and send messages to said broker. We inherit from the mosquittopp class, re-implementing a number of callback methods to handle the events of connecting newly received messages and completed subscriptions ...

Get Hands-On Embedded Programming with C++17 now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.