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.

Committer:
Osamu Koizumi
Date:
Tue Apr 17 18:54:56 2018 +0900
Revision:
28:70c0694ae0cf
Child:
34:8f7a465c2192
Added MQTT_server_setting.h

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Osamu Koizumi 28:70c0694ae0cf 1 #ifndef _SERVER_ROT_CERT_H_
Osamu Koizumi 28:70c0694ae0cf 2 #define _SERVER_ROT_CERT_H_
Osamu Koizumi 28:70c0694ae0cf 3
Osamu Koizumi 28:70c0694ae0cf 4 const char MQTT_SERVER_HOST_NAME[] = "iot.eclipse.org";
Osamu Koizumi 28:70c0694ae0cf 5
Osamu Koizumi 28:70c0694ae0cf 6 #if MBED_CONF_APP_USE_TLS == 1
Osamu Koizumi 28:70c0694ae0cf 7 const int MQTT_SERVER_PORT = 8883;
Osamu Koizumi 28:70c0694ae0cf 8
Osamu Koizumi 28:70c0694ae0cf 9 // DST Root CA X3, which is Root CA of iot.eclipse.org
Osamu Koizumi 28:70c0694ae0cf 10 const char SSL_CA_PEM[] =
Osamu Koizumi 28:70c0694ae0cf 11 "-----BEGIN CERTIFICATE-----\n"
Osamu Koizumi 28:70c0694ae0cf 12 "MIIDSjCCAjKgAwIBAgIQRK+wgNajJ7qJMDmGLvhAazANBgkqhkiG9w0BAQUFADA/\n"
Osamu Koizumi 28:70c0694ae0cf 13 "MSQwIgYDVQQKExtEaWdpdGFsIFNpZ25hdHVyZSBUcnVzdCBDby4xFzAVBgNVBAMT\n"
Osamu Koizumi 28:70c0694ae0cf 14 "DkRTVCBSb290IENBIFgzMB4XDTAwMDkzMDIxMTIxOVoXDTIxMDkzMDE0MDExNVow\n"
Osamu Koizumi 28:70c0694ae0cf 15 "PzEkMCIGA1UEChMbRGlnaXRhbCBTaWduYXR1cmUgVHJ1c3QgQ28uMRcwFQYDVQQD\n"
Osamu Koizumi 28:70c0694ae0cf 16 "Ew5EU1QgUm9vdCBDQSBYMzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEB\n"
Osamu Koizumi 28:70c0694ae0cf 17 "AN+v6ZdQCINXtMxiZfaQguzH0yxrMMpb7NnDfcdAwRgUi+DoM3ZJKuM/IUmTrE4O\n"
Osamu Koizumi 28:70c0694ae0cf 18 "rz5Iy2Xu/NMhD2XSKtkyj4zl93ewEnu1lcCJo6m67XMuegwGMoOifooUMM0RoOEq\n"
Osamu Koizumi 28:70c0694ae0cf 19 "OLl5CjH9UL2AZd+3UWODyOKIYepLYYHsUmu5ouJLGiifSKOeDNoJjj4XLh7dIN9b\n"
Osamu Koizumi 28:70c0694ae0cf 20 "xiqKqy69cK3FCxolkHRyxXtqqzTWMIn/5WgTe1QLyNau7Fqckh49ZLOMxt+/yUFw\n"
Osamu Koizumi 28:70c0694ae0cf 21 "7BZy1SbsOFU5Q9D8/RhcQPGX69Wam40dutolucbY38EVAjqr2m7xPi71XAicPNaD\n"
Osamu Koizumi 28:70c0694ae0cf 22 "aeQQmxkqtilX4+U9m5/wAl0CAwEAAaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAOBgNV\n"
Osamu Koizumi 28:70c0694ae0cf 23 "HQ8BAf8EBAMCAQYwHQYDVR0OBBYEFMSnsaR7LHH62+FLkHX/xBVghYkQMA0GCSqG\n"
Osamu Koizumi 28:70c0694ae0cf 24 "SIb3DQEBBQUAA4IBAQCjGiybFwBcqR7uKGY3Or+Dxz9LwwmglSBd49lZRNI+DT69\n"
Osamu Koizumi 28:70c0694ae0cf 25 "ikugdB/OEIKcdBodfpga3csTS7MgROSR6cz8faXbauX+5v3gTt23ADq1cEmv8uXr\n"
Osamu Koizumi 28:70c0694ae0cf 26 "AvHRAosZy5Q6XkjEGB5YGV8eAlrwDPGxrancWYaLbumR9YbK+rlmM6pZW87ipxZz\n"
Osamu Koizumi 28:70c0694ae0cf 27 "R8srzJmwN0jP41ZL9c8PDHIyh8bwRLtTcm1D9SZImlJnt1ir/md2cXjbDaJWFBM5\n"
Osamu Koizumi 28:70c0694ae0cf 28 "JDGFoqgCWjBH4d1QB7wCCZAA62RjYJsWvIjJEubSfZGL+T0yjWW06XyxV3bqxbYo\n"
Osamu Koizumi 28:70c0694ae0cf 29 "Ob8VZRzI9neWagqNdwvYkQsEjgfbKbYK7p2CNTUQ\n"
Osamu Koizumi 28:70c0694ae0cf 30 "-----END CERTIFICATE-----\n";
Osamu Koizumi 28:70c0694ae0cf 31 #else
Osamu Koizumi 28:70c0694ae0cf 32 /* No TLS */
Osamu Koizumi 28:70c0694ae0cf 33 const int MQTT_SERVER_PORT = 1883;
Osamu Koizumi 28:70c0694ae0cf 34 #endif /* MBED_CONF_APP_USE_TLS == 1 */
Osamu Koizumi 28:70c0694ae0cf 35
Osamu Koizumi 28:70c0694ae0cf 36 #endif /* _SERVER_ROT_CERT */