Example program streaming accelerometer data to a websocket server over a Sprint Mobile Broadband connection
Dependencies: MMA7660 SprintUSBModem WebSocketClient mbed-rtos mbed
main.cpp
- Committer:
- chris
- Date:
- 2012-10-26
- Revision:
- 6:b3fc13de8f5e
- Parent:
- 5:5aed2f21d249
- Child:
- 7:e61aa764fba4
File content as of revision 6:b3fc13de8f5e:
#include "mbed.h" #include "SprintUSBModem.h" #include "Websocket.h" #include "MMA7660.h" MMA7660 MMA(p28, p27); void test(void const*) { SprintUSBModem modem; Websocket ws("ws://sockets.mbed.org/ws/sensors/wo"); char json_str[100]; Thread::wait(5000); printf("Switching power on\r\n"); int ret = modem.connect(); if(ret) { printf("Could not connect\r\n"); return; } bool c = ws.connect(); printf("Connect result: %s\r\n", c?"OK":"Failed"); 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); } } int main() { DBG_INIT(); DBG_SET_SPEED(115200); DBG_SET_NEWLINE("\r\n"); Thread testTask(test, NULL, osPriorityNormal, 1024 * 5); DigitalOut led(LED1); while(1) { led=!led; Thread::wait(1000); } return 0; }