Websocket demo for app board by C. Styles with updated libraries. DHCP service and a network cable is required.
Dependencies: EthernetInterface LM75B MMA7660 WebSocketClient mbed-rtos mbed
Fork of app-board-Ethernet-Websocket by
main.cpp
- Committer:
- 4180_1
- Date:
- 2013-10-01
- Revision:
- 3:26f41c921c2d
- Parent:
- 2:1fae595547d5
File content as of revision 3:26f41c921c2d:
#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 wait(2); eth.connect(60000); 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); } }