Simple example using WebSocket to send accelerometer data
Dependencies: EthernetInterface MMA7660 WebSocketClient mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "EthernetInterface.h" 00003 #include "Websocket.h" 00004 #include "MMA7660.h" 00005 00006 MMA7660 MMA(p28, p27); 00007 00008 DigitalOut l1(LED1); 00009 00010 int main() { 00011 char json_str[100]; 00012 00013 if (MMA.testConnection()) 00014 l1 = 1; 00015 00016 EthernetInterface eth; 00017 eth.init(); //Use DHCP 00018 eth.connect(); 00019 printf("IP Address is %s\n\r", eth.getIPAddress()); 00020 00021 Websocket ws("ws://sockets.mbed.org/ws/demo/wo"); 00022 ws.connect(); 00023 00024 while (1) { 00025 sprintf(json_str, "{\"id\":\"app_board_acc\",\"ax\":\"%d\",\"ay\":\"%d\",\"az\":\"%d\"}", (int)(MMA.x()*200), (int)(MMA.y()*200), (int)(MMA.z()*200)); 00026 ws.send(json_str); 00027 wait(0.2); 00028 } 00029 }
Generated on Wed Jul 20 2022 10:10:43 by 1.7.2