Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of HelloMQTT by
Diff: main.cpp
- Revision:
- 22:826657a00c44
- Parent:
- 21:a7506c90aa84
- Child:
- 23:06fac173529e
diff -r a7506c90aa84 -r 826657a00c44 main.cpp
--- a/main.cpp Tue Mar 21 03:32:27 2017 +0000
+++ b/main.cpp Tue Mar 21 12:57:07 2017 +0000
@@ -25,10 +25,11 @@
*/
-#define MQTTCLIENT_QOS2 1
+//#define MQTTCLIENT_QOS2 1
#include "mbed.h"
#include "rtos.h"
#include "easy-connect.h"
+#include "MQTTLogging.h"
#include "MQTTNetwork.h"
#include "MQTTmbed.h"
#include "MQTTClient.h"
@@ -45,7 +46,7 @@
{
MQTT::Message &message = md.message;
printf("Message arrived: qos %d, retained %d, dup %d, packetid %d\r\n", message.qos, message.retained, message.dup, message.id);
- printf("Payload %.*s\r\n", message.payloadlen, (char*)message.payload);
+ printf("Payload [%.*s]\r\n", message.payloadlen, (char*)message.payload);
++arrivedcount;
}
@@ -103,44 +104,44 @@
if ((rc = client.connect(data)) != 0)
printf("rc from MQTT connect is %d\r\n", rc);
- if ((rc = client.subscribe(topic, MQTT::QOS2, messageArrived)) != 0)
+ if ((rc = client.subscribe(topic, MQTT::QOS0, messageArrived)) != 0)
printf("rc from MQTT subscribe is %d\r\n", rc);
- // Start the data source
+ // Start the data producer
msgSender.start(SendDataThread);
while(true)
{
osEvent evt = queue.get(10);
if (evt.status == osEventMessage) {
- printf("Message arrived from main thread ...\r\n");
+ //printf("Message arrived from main thread ...\r\n");
// Unpack the message
MQTT::Message * message = (MQTT::Message *)evt.value.p;
printf("Publishing message to MQTT ...\r\n");
// Push to mqtt
- int rc = client.publish(topic, *message);
+ rc = client.publish(topic, *message);
if (rc < 0)
- printf("Error sending mqtt message \r\n");
+ printf("Error sending mqtt message rc = %d\r\n", rc);
else
printf("Message published ...\r\n");
- printf("Deleting payload ...\r\n");
+ //printf("Deleting payload ...\r\n");
// Delete payload
delete [] message->payload;
- printf("Deleting pool allocation ...\r\n");
+ //printf("Deleting pool allocation ...\r\n");
// Don't forget this!
pool.free(message);
}
- printf("MQTT client yeild ...\r\n");
+ //printf("MQTT client yield ...\r\n");
if (client.yield(100) != MQTT::SUCCESS)
{
printf("Yield error, client disconnected? ...\r\n");
break;
}
- printf("MQTT client yeild successful ...\r\n");
+ //printf("MQTT client yield successful ...\r\n");
}
if ((rc = client.unsubscribe(topic)) != 0)
