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
Revision 0:0cae29831d01, committed 2014-02-04
- Comitter:
- icraggs
- Date:
- Tue Feb 04 22:38:15 2014 +0000
- Child:
- 1:a1d5c7a6acbc
- Commit message:
- Sample program for MQTT client
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832_lcd.lib Tue Feb 04 22:38:15 2014 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/dreschpe/code/C12832_lcd/#8f86576007d6
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Tue Feb 04 22:38:15 2014 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/EthernetInterface/#6a67d2bddc7c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MQTTClient.lib Tue Feb 04 22:38:15 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/icraggs/code/MQTTClient/#7734401cc1b4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Feb 04 22:38:15 2014 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "C12832_lcd.h"
+
+#include "MQTTPacket.h"
+
+
+DigitalOut myled(LED2);
+C12832_LCD lcd;
+
+int publish()
+{
+ MQTTPacket_connectData data = MQTTPacket_connectData_initializer;
+ int rc = 0;
+ char buf[200];
+ int buflen = sizeof(buf);
+ TCPSocketConnection mysock;
+ MQTTString topicString = MQTTString_initializer;
+ char* payload = "I'm alive!";
+ int payloadlen = strlen(payload);
+ int len = 0;
+
+ mysock.connect("m2m.eclipse.org", 1883);
+
+ data.clientID.cstring = "mbed test client - Ian Craggs";
+ data.keepAliveInterval = 20;
+ data.cleansession = 1;
+ data.MQTTVersion = 3;
+
+ len = MQTTSerialize_connect(buf, buflen, &data);
+
+ topicString.cstring = "mbed NXP LPC1768";
+ len += MQTTSerialize_publish(buf + len, buflen - len, 0, 0, 0, 0, topicString, payload, payloadlen);
+
+ len += MQTTSerialize_disconnect(buf + len, buflen - len);
+
+ rc = 0;
+ while (rc < len)
+ {
+ int rc1 = mysock.send(buf, len);
+ if (rc1 == -1)
+ {
+ lcd.printf("Send failed\n");
+ break;
+ }
+ else
+ rc += rc1;
+ }
+ if (rc == len)
+ lcd.printf("Send succeeded\n");
+ wait(0.2);
+
+ return 0;
+}
+
+int main() {
+ EthernetInterface eth;
+ eth.init(); //Use DHCP
+ eth.connect();
+ lcd.printf("IP Address is %s\n", eth.getIPAddress());
+
+ while(1) {
+ myled = 1;
+ publish();
+ wait(0.2);
+ myled = 0;
+ publish();
+ wait(0.2);
+ }
+
+ eth.disconnect();
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Feb 04 22:38:15 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f \ No newline at end of file
