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
Diff: main.cpp
- Revision:
- 33:38e2e7bf91eb
- Parent:
- 32:16ef25cbb05c
--- a/main.cpp Sat Apr 01 12:55:49 2017 +0000
+++ b/main.cpp Sun Apr 02 09:11:53 2017 +0800
@@ -36,9 +36,7 @@
Serial pc(USBTX, USBRX, 115200);
Thread msgSender(osPriorityNormal, DEFAULT_STACK_SIZE * 2);
-#define MQTT_USE_TLS
-#ifdef MQTT_USE_TLS
/* List of trusted root CA certificates
* currently only "letsencrypt", the CA for mbedhacks.com
*
@@ -103,7 +101,7 @@
"PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
"KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
"-----END CERTIFICATE-----";
-#endif
+
static const char * clientID = "mbed-sample";
static const char * userID = "mbedhacks";
@@ -154,20 +152,13 @@
return -1;
}
-#ifdef MQTT_USE_TLS
+
MQTTThreadedClient mqtt(network, SSL_CA_PEM);
-#else
- MQTTThreadedClient mqtt(network);
-#endif
const char* hostname = "mqtt.mbedhacks.com";
// const char* hostname = "192.168.0.7";
-#ifdef MQTT_USE_TLS
int port = 8883;
-#else
- int port = 1883;
-#endif
MQTTPacket_connectData logindata = MQTTPacket_connectData_initializer;
logindata.MQTTVersion = 3;
