Example program streaming accelerometer data to a websocket server over a Sprint Mobile Broadband connection
Dependencies: MMA7660 SprintUSBModem WebSocketClient mbed-rtos mbed
Revision 6:b3fc13de8f5e, committed 2012-10-26
- Comitter:
- chris
- Date:
- Fri Oct 26 09:50:24 2012 +0000
- Parent:
- 5:5aed2f21d249
- Child:
- 7:e61aa764fba4
- Commit message:
- Example program streaming live accelerometer data to a web socket server over a Sprint CDMA conenction
Changed in this revision
| MMA7660.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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA7660.lib Fri Oct 26 09:50:24 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/MMA7660/#a8e20db7901e
--- a/main.cpp Wed Oct 10 15:03:06 2012 +0000
+++ b/main.cpp Fri Oct 26 09:50:24 2012 +0000
@@ -1,17 +1,18 @@
#include "mbed.h"
#include "SprintUSBModem.h"
#include "Websocket.h"
+#include "MMA7660.h"
+
+MMA7660 MMA(p28, p27);
void test(void const*)
{
- SprintUSBModem modem(p18);
- Websocket ws("ws://sockets.mbed.org:443/ws/demo/rw");
- char recv[128];
+ SprintUSBModem modem;
+ Websocket ws("ws://sockets.mbed.org/ws/sensors/wo");
+ char json_str[100];
Thread::wait(5000);
- printf("Switching power on\r\n");
-
- modem.power(true);
+ printf("Switching power on\r\n");
int ret = modem.connect();
if(ret)
@@ -23,36 +24,12 @@
bool c = ws.connect();
printf("Connect result: %s\r\n", c?"OK":"Failed");
- for(int i = 0; i < 10000; i++)
- {
- if(!(i%100))
- {
- int ret = ws.send("WebSocket Hello World!");
- if(ret<0)
- {
- printf("Timeout\r\n");
- ws.close();
- c = ws.connect();
- printf("Connect result: %s\r\n", c?"OK":"Failed");
- }
- }
-
- if (ws.read(recv)) {
- printf("rcv: %s\r\n", recv);
- }
-
+ 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);
}
- modem.disconnect();
-
- printf("Disconnected\r\n");
-
- modem.power(false);
-
- printf("Powered off\r\n");
-
- while(1) {
- }
}