Simple demo with GPIO MQTT protocol test on STM32 broker tests.mosquitto.org WIFI interface ESP8266 Issue of topic0 by pressing the button If reception of ', switching of the led If received from 'q' end of program

Dependencies:   MQTT

This is a MQTT protocol test on STM32 NUCLEO The broker is tests.mosquitto.org The WIFI interface is ESP8266

For configuration please check mbed_app.json and #define in main.cpp

Issue of topic0 by pressing the button If received 'l' from broker then switching of the led If received 'q' from broker then end the program

Information and debug with a terminal using UART over USB https://os.mbed.com/media/uploads/cdupaty/mqtt2.jpg

This test has been checked with MQTT.fx https://os.mbed.com/media/uploads/cdupaty/mqttfx.jpg

Revision:
12:086a9314e8a5
Parent:
9:5beb8609e9f7
Child:
16:28d062c5522b
--- a/main.cpp	Thu May 22 23:58:34 2014 +0000
+++ b/main.cpp	Fri Aug 01 17:02:22 2014 +0000
@@ -67,6 +67,8 @@
     MQTTPacket_connectData data = MQTTPacket_connectData_initializer;       
     data.MQTTVersion = 3;
     data.clientID.cstring = "mbed-sample";
+    data.username.cstring = "testuser";
+    data.password.cstring = "testpassword";
     if ((rc = client.connect(&data)) != 0)
         lcd.printf("rc from MQTT connect is %d\n", rc);
     
@@ -84,7 +86,7 @@
     message.payload = (void*)buf;
     message.payloadlen = strlen(buf)+1;
     rc = client.publish(topic, &message);
-    while (arrivedcount == 0)
+    while (arrivedcount < 1)
         client.yield(100);
         
     // QoS 1
@@ -92,7 +94,7 @@
     message.qos = MQTT::QOS1;
     message.payloadlen = strlen(buf)+1;
     rc = client.publish(topic, &message);
-    while (arrivedcount == 1)
+    while (arrivedcount < 2)
         client.yield(100);
         
     // QoS 2
@@ -100,8 +102,19 @@
     message.qos = MQTT::QOS2;
     message.payloadlen = strlen(buf)+1;
     rc = client.publish(topic, &message);
-    while (arrivedcount == 2)
+    while (arrivedcount < 3)
         client.yield(100);
+        
+    // n * QoS 2
+    for (int i = 1; i <= 10; ++i)
+    {
+        sprintf(buf, "Hello World!  QoS 2 message number %d from app version %f\n", i, version);
+        message.qos = MQTT::QOS2;
+        message.payloadlen = strlen(buf)+1;
+        rc = client.publish(topic, &message);
+        while (arrivedcount < i + 3)
+            client.yield(100);
+    }
     
     if ((rc = client.unsubscribe(topic)) != 0)
         printf("rc from unsubscribe was %d\n", rc);