MQTTClient test to subscribe to Pachube feed

Dependencies:   NetServices mbed DNSResolver

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Tue Mar 20 21:06:24 2012 +0000
Commit message:

Changed in this revision

DNSResolver.lib Show annotated file Show diff for this revision Revisions of this file
MQTTClient.lib Show annotated file Show diff for this revision Revisions of this file
NetServices.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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r fb491df6af35 DNSResolver.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DNSResolver.lib	Tue Mar 20 21:06:24 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hlipka/code/DNSResolver/#097d4993dd1e
diff -r 000000000000 -r fb491df6af35 MQTTClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MQTTClient.lib	Tue Mar 20 21:06:24 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/SomeRandomBloke/code/MQTTClient/#a0e39cea763a
diff -r 000000000000 -r fb491df6af35 NetServices.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/NetServices.lib	Tue Mar 20 21:06:24 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/segundo/code/NetServices/#4e2468d7d5cb
diff -r 000000000000 -r fb491df6af35 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Mar 20 21:06:24 2012 +0000
@@ -0,0 +1,62 @@
+#include "mbed.h"
+#include "EthernetNetIf.h"
+#include "MQTTClient.h"
+#include "dnsresolve.h"
+
+EthernetNetIf ethernet;    
+
+void callback(char* topic, char* payload); /*Callback function prototype*/
+
+MQTTClient mqtt;
+
+Serial pc(USBTX, USBRX); // tx, rx
+
+void callback(char* topic, char* payload)
+{
+    printf("Topic: %s\r\n", topic);
+    printf("Payload: %s\r\n\r\n", payload);
+    //Send incoming payloads back to topic "/mbed".
+//    mqtt.publish("mbed", payload);
+}
+
+int main() 
+{  
+   pc.baud(115200);
+    printf("\r\n############### MQTTClient Tester  ###########\r\n\r\n");
+    DNSResolver resolver;
+    
+    EthernetErr ethErr = ethernet.setup();
+    if(ethErr){
+        printf("Ethernet Error %d\r\n", ethErr);  
+        return -1;
+    } 
+    
+    char clientID[] = "mbed";   /*Client name show for MQTT server*/
+    char sub_topic[] = "/v2/feeds/XXXXXX.csv";   /*Subscribe to topic - a Pachube feed, replace XXXXXX with your own feed number */
+    
+    IpAddr serverIpAddr = resolver.resolveName("api.pachube.com");
+    
+    mqtt.init(&serverIpAddr, 1883, "your-api-key-here", NULL, callback);
+    
+    if(!mqtt.connect(clientID)){
+        printf("\r\nConnect to server failed ..\r\n");
+        return -1;
+    }
+    printf("\r\nConnect to server sucessed ..\r\n");
+    
+//    mqtt.publish(pub_topic, "Hello here is mbed...");
+    mqtt.subscribe(sub_topic);
+    
+    int flag = 0;
+    /*Keep alive for 300s or 5mins*/
+    while(flag < 300){
+        Net::poll();
+        wait(1);
+        flag++;
+        mqtt.live();
+    }
+    
+    mqtt.disconnect();
+    
+    printf("#### End of the test.. ####\r\n\r\n");
+}
diff -r 000000000000 -r fb491df6af35 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Mar 20 21:06:24 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/737756e0b479