Simple usage example of MQTTS library
Dependencies: EthernetInterface MQTTS NTPClient SDFileSystem mbed-rtos mbed wolfSSL
Fork of HelloMQTT by
MQTT is light weight protocol for M2M, IoT. MQTTS adds TLS(SSL) security layer into the MQTT. This program shows simple usage example of MQTTS library.
Connect information has to be stored in SD file "connectInfo.txt", with following lines in it.
- Host Name
- User Name
- Password
- Client ID
- Topic
The program asks following information on the terminal
- Port Number to be connected. If the port is >8000 it assumes MQTTS.
- Message to be published
- Certificate file name, if MQTTS. Input file name on SD card. Simply Return key force it to no server verification. The program set up the realtime clock by NTP for certificate verification.
This program was tested with FRDM-K64F, against Sango MQTT server by Shiguredo. https://sango.shiguredo.jp/
References:
- wolfSSL Home: https://www.wolfssl.com
- Original work of MQTT: https://developer.mbed.org/teams/mqtt.
- 日本語ホーム:https://developer.mbed.org/users/wolfSSL/code/HelloMQTTS/wiki/MQTTSホーム
Revision 20:0404c7f31c69, committed 2015-08-01
- Comitter:
- wolfSSL
- Date:
- Sat Aug 01 20:50:27 2015 +0000
- Parent:
- 19:3bf315cb74b4
- Commit message:
- Added QoS2
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 3bf315cb74b4 -r 0404c7f31c69 main.cpp --- a/main.cpp Mon Jul 27 01:38:23 2015 +0000 +++ b/main.cpp Sat Aug 01 20:50:27 2015 +0000 @@ -23,7 +23,7 @@ system libraries. */ - +#define MQTTCLIENT_QOS2 1 #include "MQTTEthernet.h" #include "MQTTClient.h" @@ -181,9 +181,9 @@ while (arrivedcount < 2) client.yield(100); -#if 0 /* QoS 2 not tested */ +#if 1 /* QoS 2 not tested */ // QoS 2 - sprintf(buf, "\"%s\", QoS 2 message from app version %f\n", version); + sprintf(buf, "\"%s\", QoS 2 message from app version %f\n", msg, version); message.qos = MQTT::QOS2; message.payloadlen = strlen(buf)+1; rc = client.publish(topic, message); @@ -193,7 +193,7 @@ // n * QoS 2 for (int i = 1; i <= 10; ++i) { - sprintf(buf, "\"%s\", QoS 2 message number %d from app version %f\n", i, version); + sprintf(buf, "\"%s\", QoS 2 message number %d from app version %f\n",msg, i, version); message.qos = MQTT::QOS2; message.payloadlen = strlen(buf)+1; rc = client.publish(topic, message);