![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Updated directories
Dependencies: EthernetInterface LM75B MMA7660 WebSocketClient mbed-rtos mbed
Fork of app-board-Ethernet-Websocket by
Uses updated libraries, working as of 28/4/14.
main.cpp@4:5b9a041b9d71, 2014-04-28 (annotated)
- Committer:
- jrichardson9
- Date:
- Mon Apr 28 12:42:05 2014 +0000
- Revision:
- 4:5b9a041b9d71
- Parent:
- 3:26f41c921c2d
Updated directories
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
samux | 2:1fae595547d5 | 1 | #include "mbed.h" |
samux | 2:1fae595547d5 | 2 | #include "EthernetInterface.h" |
samux | 2:1fae595547d5 | 3 | #include "Websocket.h" |
samux | 2:1fae595547d5 | 4 | #include "MMA7660.h" |
samux | 2:1fae595547d5 | 5 | #include "LM75B.h" |
samux | 2:1fae595547d5 | 6 | |
samux | 2:1fae595547d5 | 7 | // accelerometer |
samux | 2:1fae595547d5 | 8 | MMA7660 acc(p28, p27); |
samux | 2:1fae595547d5 | 9 | |
samux | 2:1fae595547d5 | 10 | // temperature sensor |
samux | 2:1fae595547d5 | 11 | LM75B tmp(p28,p27); |
samux | 2:1fae595547d5 | 12 | |
samux | 2:1fae595547d5 | 13 | DigitalOut l1(LED1); |
samux | 2:1fae595547d5 | 14 | |
samux | 2:1fae595547d5 | 15 | int main() { |
samux | 2:1fae595547d5 | 16 | char json_str[100]; |
samux | 2:1fae595547d5 | 17 | |
samux | 2:1fae595547d5 | 18 | if (acc.testConnection()) |
samux | 2:1fae595547d5 | 19 | l1 = 1; |
samux | 2:1fae595547d5 | 20 | |
samux | 2:1fae595547d5 | 21 | EthernetInterface eth; |
samux | 2:1fae595547d5 | 22 | eth.init(); //Use DHCP |
4180_1 | 3:26f41c921c2d | 23 | wait(2); |
4180_1 | 3:26f41c921c2d | 24 | eth.connect(60000); |
samux | 2:1fae595547d5 | 25 | printf("IP Address is %s\n\r", eth.getIPAddress()); |
samux | 2:1fae595547d5 | 26 | |
samux | 2:1fae595547d5 | 27 | // See the output on http://sockets.mbed.org/app-board/viewer |
jrichardson9 | 4:5b9a041b9d71 | 28 | Websocket ws("ws://sockets.mbed.org:443/ws/testing/wo"); |
samux | 2:1fae595547d5 | 29 | ws.connect(); |
jrichardson9 | 4:5b9a041b9d71 | 30 | |
jrichardson9 | 4:5b9a041b9d71 | 31 | |
samux | 2:1fae595547d5 | 32 | |
samux | 2:1fae595547d5 | 33 | while (1) { |
samux | 2:1fae595547d5 | 34 | // create json string with acc/tmp data |
samux | 2:1fae595547d5 | 35 | 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()); |
samux | 2:1fae595547d5 | 36 | |
samux | 2:1fae595547d5 | 37 | // send str |
samux | 2:1fae595547d5 | 38 | ws.send(json_str); |
samux | 2:1fae595547d5 | 39 | |
samux | 2:1fae595547d5 | 40 | wait(0.1); |
samux | 2:1fae595547d5 | 41 | } |
samux | 0:11bb5faeb547 | 42 | } |