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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.