Example program streaming accelerometer data to a websocket server over a Sprint Mobile Broadband connection
Dependencies: MMA7660 SprintUSBModem WebSocketClient mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "SprintUSBModem.h" 00003 #include "Websocket.h" 00004 #include "MMA7660.h" 00005 00006 MMA7660 MMA(p28, p27); 00007 00008 void test(void const*) 00009 { 00010 SprintUSBModem modem(p18); 00011 Websocket ws("ws://sockets.mbed.org:443/ws/sensors/wo"); 00012 // View the output at : 00013 // http://tools.mbed.org/iot/ 00014 // Click "show all" 00015 char json_str[100]; 00016 Thread::wait(5000); 00017 printf("Switching power on\r\n"); 00018 00019 modem.power(true); 00020 00021 int ret = modem.connect(); 00022 if(ret) 00023 { 00024 printf("Could not connect\r\n"); 00025 return; 00026 } 00027 00028 bool c = ws.connect(); 00029 printf("Connect result: %s\r\n", c?"OK":"Failed"); 00030 00031 while (1) { 00032 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)); 00033 ws.send(json_str); 00034 wait(0.2); 00035 } 00036 00037 } 00038 00039 00040 int main() 00041 { 00042 DBG_INIT(); 00043 DBG_SET_SPEED(115200); 00044 DBG_SET_NEWLINE("\r\n"); 00045 Thread testTask(test, NULL, osPriorityNormal, 1024 * 5); 00046 DigitalOut led(LED1); 00047 while(1) 00048 { 00049 led=!led; 00050 Thread::wait(1000); 00051 } 00052 00053 return 0; 00054 }
Generated on Fri Jul 15 2022 21:29:08 by 1.7.2