Websocket demo for app board by C. Styles with updated libraries. DHCP service and a network cable is required.

Dependencies:   C12832 EthernetInterface HTTPServer LM75B MMA7660 WebSocketClient mbed-rtos mbed

Fork of app-board-Ethernet-Websocket by jim hamblen

Revision:
2:1fae595547d5
Parent:
1:1ca9c7ae7e0b
Child:
3:26f41c921c2d
--- a/main.cpp	Fri Oct 26 09:27:16 2012 +0000
+++ b/main.cpp	Fri Feb 08 12:46:02 2013 +0000
@@ -1,30 +1,39 @@
-#include "mbed.h"
-#include "EthernetInterface.h"
-#include "Websocket.h"
-#include "MMA7660.h"
-
-MMA7660 MMA(p28, p27);
-
-DigitalOut l1(LED1);
- 
-int main() {
-    char json_str[100];
-    
-    if (MMA.testConnection())
-        l1 = 1;
- 
-    EthernetInterface eth;
-    eth.init(); //Use DHCP
-    eth.connect();
-    printf("IP Address is %s\n\r", eth.getIPAddress());
-    
-    Websocket ws("ws://sockets.mbed.org/ws/sensors/wo");
-    // visit http://tools.mbed.org/iot/ to see the realtime graph
-    ws.connect();
- 
-    while (1) {
-        sprintf(json_str, "{\"id\":\"mbed-app-board\",\"ax\":\"%d\",\"ay\":\"%d\",\"az\":\"%d\"}", (int)(MMA.x()*200), (int)(MMA.y()*200), (int)(MMA.z()*200));
-        ws.send(json_str);
-        wait(0.2);
-    }
+#include "mbed.h"
+#include "EthernetInterface.h"
+#include "Websocket.h"
+#include "MMA7660.h"
+#include "LM75B.h"
+
+// accelerometer
+MMA7660 acc(p28, p27);
+
+// temperature sensor
+LM75B tmp(p28,p27);
+
+DigitalOut l1(LED1);
+ 
+int main() {
+    char json_str[100];
+    
+    if (acc.testConnection())
+        l1 = 1;
+ 
+    EthernetInterface eth;
+    eth.init(); //Use DHCP
+    eth.connect();
+    printf("IP Address is %s\n\r", eth.getIPAddress());
+    
+    // See the output on http://sockets.mbed.org/app-board/viewer
+    Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo");
+    ws.connect();
+ 
+    while (1) {
+        // create json string with acc/tmp data
+        sprintf(json_str, "{\"id\":\"app_board_eth_EW2013\",\"ax\":%d,\"ay\":%d,\"az\":%d, \"tmp\":%d}", (int)(acc.x()*360), (int)(acc.y()*360), (int)(acc.z()*360), (int)tmp.read());
+        
+        // send str
+        ws.send(json_str);
+        
+        wait(0.1);
+    }
 }
\ No newline at end of file