Sample MQTT program - simple send and receive

Dependencies:   C12832 MQTT

Dependents:   MQTT_G_SENSOR

This program and the MQTT libraries it uses are part of the EclipseTM Paho project; specifically the embedded client.

This example and API are working, but are still in progress. Please give us your feedback.

HelloMQTT is an example of using the MQTT API. The MQTT API is portable across network interface stacks. MQTT is designed to be used with TCP/IP, but any transport with similar characteristics should be suitable.

HelloMQTT uses the NetworkInterface APIs in mbed OS 5 to show how this works. The MQTT library contains an MQTTNetwork.h header, which is a wrapper around the mbed networking interface. To switch between connectivity methods (the default is Ethernet) the easy-connect library is provided in this example application. You can change the connectivity method in mbed_app.json.

Adding new connectivity methods to the program is trivial, as long as they implement the mbed OS 5 NetworkStack API.

Files at this revision

API Documentation at this revision

Comitter:
Jan Jongboom
Date:
Thu Sep 07 10:06:22 2017 +0100
Parent:
20:49c9daf2b0ff
Child:
22:f5f6c9059eed
Commit message:
changeset: 21:6ab7c0b84d9e
tag: tip
user: Jan Jongboom <janjongboom@gmail.com>
date: Thu Sep 07 10:02:29 2017 +0100
summary: Update to mbed OS 5.5.6

Changed in this revision

MQTT.lib Show annotated file Show diff for this revision Revisions of this file
MQTTNetwork.h Show annotated file Show diff for this revision Revisions of this file
easy-connect.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed_app.json Show annotated file Show diff for this revision Revisions of this file
--- a/MQTT.lib	Tue Jan 10 18:10:17 2017 -0600
+++ b/MQTT.lib	Thu Sep 07 10:06:22 2017 +0100
@@ -1,1 +1,1 @@
-http://mbed.org/teams/mqtt/code/MQTT/#c299463ae853
+https://mbed.org/teams/mqtt/code/MQTT/#08571008b958
--- a/MQTTNetwork.h	Tue Jan 10 18:10:17 2017 -0600
+++ b/MQTTNetwork.h	Thu Sep 07 10:06:22 2017 +0100
@@ -26,8 +26,8 @@
         return socket->connect(hostname, port);
     }
 
-    void disconnect() {
-
+    int disconnect() {
+        return socket->close();
     }
 
 private:
--- a/easy-connect.lib	Tue Jan 10 18:10:17 2017 -0600
+++ b/easy-connect.lib	Thu Sep 07 10:06:22 2017 +0100
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/easy-connect/#cb933fb19cda0a733a64d6b71d271fb6bdaf9e6d
+https://github.com/ARMmbed/easy-connect/#4f8e48a4b076bf638c3c02c23995a883e1efa921
--- a/main.cpp	Tue Jan 10 18:10:17 2017 -0600
+++ b/main.cpp	Thu Sep 07 10:06:22 2017 +0100
@@ -25,8 +25,8 @@
 
  */
 
- // change this to 0 to output messages to serial instead of LCD
-#define USE_LCD 1
+ // change this to 1 to output messages to LCD instead of serial
+#define USE_LCD 0
 
 #if USE_LCD
 #include "C12832.h"
@@ -75,7 +75,7 @@
 
     MQTTNetwork mqttNetwork(network);
 
-    MQTT::Client<MQTTNetwork, Countdown> client = MQTT::Client<MQTTNetwork, Countdown>(mqttNetwork);
+    MQTT::Client<MQTTNetwork, Countdown> client(mqttNetwork);
 
     const char* hostname = "m2m.eclipse.org";
     int port = 1883;
--- a/mbed-os.lib	Tue Jan 10 18:10:17 2017 -0600
+++ b/mbed-os.lib	Thu Sep 07 10:06:22 2017 +0100
@@ -1,1 +1,1 @@
-https://github.com/ARMmbed/mbed-os/#2885c1b41e63158cb6faf5f107cd821ae06ef26c
+https://github.com/ARMmbed/mbed-os/#98ba8acb83cfc65f30a8a0771a27c71443ab093a
--- a/mbed_app.json	Tue Jan 10 18:10:17 2017 -0600
+++ b/mbed_app.json	Thu Sep 07 10:06:22 2017 +0100
@@ -1,7 +1,7 @@
 {
     "config": {
         "network-interface":{
-            "help": "options are ETHERNET,WIFI_ESP8266,MESH_LOWPAN_ND,MESH_THREAD",
+            "help": "options are ETHERNET, WIFI_ESP8266, WIFI_ODIN, WIFI_RTW, MESH_LOWPAN_ND, MESH_THREAD, CELLULAR_ONBOARD",
             "value": "ETHERNET"
         },
         "mesh_radio_type": {