A Threaded Secure MQTT Client example. Uses MBED TLS for SSL/TLS connection. QoS0 only for now. Example has been tested with K64F connected via Ethernet.
Fork of HelloMQTT by
Revision 27:c90092f35d79, committed 2017-03-27
- Comitter:
- vpcola
- Date:
- Mon Mar 27 14:08:46 2017 +0000
- Parent:
- 26:4b21de8043a5
- Child:
- 28:01d5cc81af31
- Commit message:
- Minor comments added
Changed in this revision
| MQTTThreadedClient.cpp | Show annotated file Show diff for this revision Revisions of this file |
| MQTTThreadedClient.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/MQTTThreadedClient.cpp Mon Mar 27 13:45:26 2017 +0000
+++ b/MQTTThreadedClient.cpp Mon Mar 27 14:08:46 2017 +0000
@@ -916,6 +916,7 @@
reconnect:
// reconnect?
+ printf("Client disconnected!! ... retrying ...\r\n");
disconnect();
};
--- a/MQTTThreadedClient.h Mon Mar 27 13:45:26 2017 +0000
+++ b/MQTTThreadedClient.h Mon Mar 27 14:08:46 2017 +0000
@@ -100,7 +100,14 @@
disconnect();
}
-
+ /**
+ * Sets the connection parameters. Must be called before running the startListener as a thread.
+ *
+ * @param host - pointer to the host where the MQTT server is running
+ * @param port - the port number to connect, 1883 for non secure connections, 8883 for
+ * secure connections
+ * @param options - the connect data used for logging into the MQTT server.
+ */
void setConnectionParameters(const char * host, uint16_t port, MQTTPacket_connectData & options);
int publish(PubMessage& message);
@@ -114,6 +121,8 @@
topicCBMap.insert(std::pair<std::string, FP<void,MessageData &> >(std::string(topic),fp));
}
+ // TODO: Add unsubscribe functionality.
+
// Start the listener thread and start polling
// MQTT server.
void startListener();
