Test C027 with Xively and Ethernet

Dependencies:   C027 EthernetInterface libxively mbed-rtos mbed HTTPClient

Fork of C027_Xively_Ethernet by Chau Vo

Files at this revision

API Documentation at this revision

Comitter:
olympux
Date:
Tue Apr 22 21:12:07 2014 +0000
Parent:
3:259ac92c3ca8
Child:
5:421189b51ac9
Commit message:
Tested with nne-server1.herokuapp.com: received heartbeat from server; can receive message from Chrome running on 64-bit Windows 7.

Changed in this revision

C027.lib Show annotated file Show diff for this revision Revisions of this file
C027_Websocket_Ethernet.lib Show annotated file Show diff for this revision Revisions of this file
HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
SocketIO.lib Show annotated file Show diff for this revision Revisions of this file
WebSocketClient.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-rtos.lib Show annotated file Show diff for this revision Revisions of this file
--- a/C027.lib	Wed Apr 09 20:14:57 2014 +0000
+++ b/C027.lib	Tue Apr 22 21:12:07 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/teams/ublox/code/C027/#8ca897c3cf41
+http://mbed.org/teams/ublox/code/C027/#06d5a702779c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C027_Websocket_Ethernet.lib	Tue Apr 22 21:12:07 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/olympux/code/C027_Websocket_Ethernet/#259ac92c3ca8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Tue Apr 22 21:12:07 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#432ccbec4bd8
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SocketIO.lib	Tue Apr 22 21:12:07 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/ansond/code/SocketIO/#d811e59b5810
--- a/WebSocketClient.lib	Wed Apr 09 20:14:57 2014 +0000
+++ b/WebSocketClient.lib	Tue Apr 22 21:12:07 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/samux/code/WebSocketClient/#4567996414a5
+http://mbed.org/users/samux/code/WebSocketClient/#3aa6ad3e4839
--- a/main.cpp	Wed Apr 09 20:14:57 2014 +0000
+++ b/main.cpp	Tue Apr 22 21:12:07 2014 +0000
@@ -2,52 +2,95 @@
 #include "C027.h"
 #include "EthernetInterface.h"
 #include "Websocket.h"
- 
- 
-void test(void const*)
+#include "SocketIO.h"
+
+
+//Debug is disabled by default
+#if 1
+//Enable debug
+#include <cstdio>
+#define DBG(x, ...) std::printf("[main : DBG]"x"\r\n", ##__VA_ARGS__); 
+#define WARN(x, ...) std::printf("[main : WARN]"x"\r\n", ##__VA_ARGS__); 
+#define ERR(x, ...) std::printf("[main : ERR]"x"\r\n", ##__VA_ARGS__); 
+
+#else
+//Disable debug
+#define DBG(x, ...) 
+#define WARN(x, ...)
+#define ERR(x, ...) 
+
+#endif
+
+
+void websocket_test(void const*)
 {
     char msg[512] = {0};
- 
+
     EthernetInterface eth;
     eth.init(); //Use DHCP
     eth.connect();
-    printf("IP Address is %s\n\r", eth.getIPAddress());
- 
+    DBG("IP Address is %s", eth.getIPAddress());
+
     Websocket ws("ws://sockets.mbed.org:443/ws/chauvo/wo");
     Timer t;
     t.start();
-    
+
     bool c = ws.connect();
-    printf("Connect result: %s\n", c?"OK":"Failed");
-    
-    for(int i = 0; i < 10000; i++) 
-    {
+    DBG("Connect result: %s", c?"OK":"Failed");
+
+    for(int i = 0; i < 10000; i++) {
         ws.connect();
         // create json string with acc/tmp data
         sprintf(msg, "Chau's demo loop: %d", i);
-        ws.send(msg);    
+        ws.send(msg);
         wait(0.5f);
         memset(msg, 0, 512);
-        
-        if (ws.read(msg))
-        {
-            printf("rcv: %s\r\n", msg);
-        }
-        else
-        {
-            printf("Loop %d ws.read() returns 0\n \t %s, line %d @ %6.2f seconds\n", i, __FILE__, __LINE__, t.read());
+
+        if (ws.read(msg)) {
+            DBG("rcv: %s\r\n", msg);
+        } else {
+            DBG("Loop %d ws.read() returns 0\n \t %s, line %d @ %6.2f seconds\n", i, __FILE__, __LINE__, t.read());
             wait(5.0f);
         }
         ws.close();
     }
-    
+
     while(1) {
     }
 }
 
+void socketio_test(void const*)
+{
+    char msg[512] = {0};
+
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    DBG("IP Address is %s", eth.getIPAddress());
+
+    SocketIO socketio("nne-server1.herokuapp.com");
+    //SocketIO socketio("websocketserver-tutorial11067089.rhcloud.com");
+    //SocketIO socketio("websocket-server.chau_vk.c9.io:8001");
+    //SocketIO socketio("websocket-server-c9-chau_vk.c9.io");
+    Timer t;
+    t.start();
+
+    bool c = socketio.connect(); // c is always false, (maybe because the connection is upgraded?)
+    DBG("Connect result: %s", c?"OK":"Failed");
+
+    while (1) {
+        int res = socketio.emit("mesage","[\"mbed SocketIO Hello World!\"]");
+        if (socketio.read(msg)) {
+            DBG("rcv: %s", msg);
+        }
+        wait(0.1);
+    }
+}
+
 int main()
 {
-    Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
+    //Thread testTask(websocket_test, NULL, osPriorityNormal, 1024 * 4);
+    Thread testTask(socketio_test, NULL, osPriorityNormal, 1024 * 4);
     DigitalOut led(LED); // on rev A you should reasign the signal to A0
     while(1) {
         led=!led;
--- a/mbed-rtos.lib	Wed Apr 09 20:14:57 2014 +0000
+++ b/mbed-rtos.lib	Tue Apr 22 21:12:07 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed-rtos/#cb1d43beeb70
+http://mbed.org/users/mbed_official/code/mbed-rtos/#4ef72665e2c8