HelloMQTT over TLS.

Dependencies:   MQTT

Fork of HelloMQTT by Osamu Koizumi

HelloMQTT over TLS

This program is a fork of HelloMQTT. Added TLS capability by using TLSSocket library. Tested on K64F.

This sample program connects to iot.eclipse.org:8883 by default. Verifies server identification. Subscribes a certain topic. Then publishes three messages with different QoSs, i.e. QoS0, QoS1, and QoS2.

Warning

Some brokers do not accept QoS2 and/or QoS1 message. For example, AWS IoT Message Broker doesn't accept QoS2. In such broker, this program doesn't work as is. Change QoS level.

Output from console

HelloMQTT: version is 0.70

Opening network interface...
Network interface opened successfully.

Connecting to host iot.eclipse.org:8883 ...
Connection established.

MQTT client is trying to connect the server ...
Client connected.

Client is trying to subscribe a topic "mbed-test".
Client has subscribed a topic "mbed-test".

Client publishes messages ...
Publishing message QoS 0.
QoS 0 message published.
! Message arrived: qos 0, retained 0, dup 0, packetid 6257
! Payload Hello World!  QoS 0 message from app version 0.700000

Publishing message QoS 1.
QoS 1 message published.
! Message arrived: qos 1, retained 0, dup 0, packetid 1
! Payload Hello World!  QoS 1 message from app version 0.700000

Publishing message QoS 2.
QoS 2 message published.
! Message arrived: qos 2, retained 0, dup 0, packetid 2
! Payload Hello World!  QoS 2 message from app version 0.700000

Version 0.70: finish 3 msgs

Known Issues

On K64F, when serial baud rate is changed from 9600 to 115200, program fails.

Files at this revision

API Documentation at this revision

Comitter:
Osamu Koizumi
Date:
Wed Jun 13 14:42:00 2018 +0900
Parent:
41:deed7540b456
Child:
43:4dfeeaa9713e
Commit message:
Updated TLSSocket and change HelloMQTT to adopt it.

Changed in this revision

MQTTNetwork.h Show annotated file Show diff for this revision Revisions of this file
TLSSocket.lib Show annotated file Show diff for this revision Revisions of this file
--- a/MQTTNetwork.h	Mon Jun 11 17:54:18 2018 +0900
+++ b/MQTTNetwork.h	Wed Jun 13 14:42:00 2018 +0900
@@ -41,7 +41,8 @@
             return ret;
         }
 #ifdef USE_TLS
-        socket->set_cert_key(ssl_ca_pem, ssl_cli_pem, ssl_pk_pem);
+        socket->set_root_ca_cert(ssl_ca_pem);
+        socket->set_client_cert_key(ssl_cli_pem, ssl_pk_pem);
 #endif /* USE_TLS */
         return socket->connect(hostname, port);
     }
--- a/TLSSocket.lib	Mon Jun 11 17:54:18 2018 +0900
+++ b/TLSSocket.lib	Wed Jun 13 14:42:00 2018 +0900
@@ -1,1 +1,1 @@
-https://github.com/coisme/TLSSocket/#572dd6082257f27ac36374eb424df3e9114fb892
+https://github.com/coisme/TLSSocket/#c4f675b809d69680a18d1cb94f90646a1b415d19