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.

Revision:
1:a1d5c7a6acbc
Parent:
0:0cae29831d01
Child:
2:638c854c0695
--- a/main.cpp	Tue Feb 04 22:38:15 2014 +0000
+++ b/main.cpp	Wed Feb 05 10:50:15 2014 +0000
@@ -1,10 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2014 IBM Corp.
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * and Eclipse Distribution License v1.0 which accompany this distribution.
+ *
+ * The Eclipse Public License is available at
+ *    http://www.eclipse.org/legal/epl-v10.html
+ * and the Eclipse Distribution License is available at
+ *   http://www.eclipse.org/org/documents/edl-v10.php.
+ *
+ * Contributors:
+ *    Ian Craggs - initial API and implementation and/or initial documentation
+ *******************************************************************************/
+
 #include "mbed.h"
 #include "EthernetInterface.h"
 #include "C12832_lcd.h"
 
 #include "MQTTPacket.h"
 
-
 DigitalOut myled(LED2);
 C12832_LCD lcd;
 
@@ -53,13 +68,15 @@
     return 0;
 }
 
-int main() {
+int main()
+{
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
     lcd.printf("IP Address is %s\n", eth.getIPAddress());
     
-    while(1) {
+    while(1) 
+    {
         myled = 1;
         publish();
         wait(0.2);