Simple usage example of MQTTS library

Dependencies:   EthernetInterface MQTTS NTPClient SDFileSystem mbed-rtos mbed wolfSSL

Fork of HelloMQTT by MQTT

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:

Committer:
wolfSSL
Date:
Sat Aug 01 20:50:27 2015 +0000
Revision:
20:0404c7f31c69
Parent:
17:25584027fae0
Added QoS2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wolfSSL 17:25584027fae0 1
wolfSSL 17:25584027fae0 2 #include <mbed.h>
wolfSSL 17:25584027fae0 3
wolfSSL 17:25584027fae0 4 int getline(char *prompt, char *buff, int size)
wolfSSL 17:25584027fae0 5 {
wolfSSL 17:25584027fae0 6 int sz ;
wolfSSL 17:25584027fae0 7
wolfSSL 17:25584027fae0 8 printf("%s", prompt) ;
wolfSSL 17:25584027fae0 9 for(sz = 0 ; (sz < size) && ((*buff = getchar()) != '\r'); sz++, buff++) {
wolfSSL 17:25584027fae0 10 putchar(*buff) ;
wolfSSL 17:25584027fae0 11 if(*buff == '\\') {
wolfSSL 17:25584027fae0 12 if(++sz >= size)break ;
wolfSSL 17:25584027fae0 13 *buff = getchar() ;
wolfSSL 17:25584027fae0 14 putchar(*buff) ;
wolfSSL 17:25584027fae0 15 switch(*buff) {
wolfSSL 17:25584027fae0 16 case 'n' :
wolfSSL 17:25584027fae0 17 *buff = '\n' ;
wolfSSL 17:25584027fae0 18 break ;
wolfSSL 17:25584027fae0 19 case 'r' :
wolfSSL 17:25584027fae0 20 *buff = '\r' ;
wolfSSL 17:25584027fae0 21 break ;
wolfSSL 17:25584027fae0 22 case 't' :
wolfSSL 17:25584027fae0 23 *buff = '\t' ;
wolfSSL 17:25584027fae0 24 break ;
wolfSSL 17:25584027fae0 25 case '\\':
wolfSSL 17:25584027fae0 26 *buff = '\\' ;
wolfSSL 17:25584027fae0 27 break ;
wolfSSL 17:25584027fae0 28 default:
wolfSSL 17:25584027fae0 29 buff[1] = buff[0] ;
wolfSSL 17:25584027fae0 30 buff[0] = '\\' ;
wolfSSL 17:25584027fae0 31 buff++ ;
wolfSSL 17:25584027fae0 32 }
wolfSSL 17:25584027fae0 33 } else if(*buff == '\b') {
wolfSSL 17:25584027fae0 34 if(sz >= 2) {
wolfSSL 17:25584027fae0 35 buff-=2 ;
wolfSSL 17:25584027fae0 36 sz-=2;
wolfSSL 17:25584027fae0 37 }
wolfSSL 17:25584027fae0 38 }
wolfSSL 17:25584027fae0 39 } ;
wolfSSL 17:25584027fae0 40 putchar('\n') ;
wolfSSL 17:25584027fae0 41 *buff = '\0' ;
wolfSSL 17:25584027fae0 42 return sz ;
wolfSSL 17:25584027fae0 43 }