An example program that uses a Wifly module to send messages over web sockets
Dependencies: WebSocketClient WiflyInterface mbed LM75B MMA7660
Fork of Websocket_Wifly_HelloWorld by
Diff: main.cpp
- Revision:
- 4:79f9caf3d109
- Parent:
- 3:d1d4b7d317d1
- Child:
- 5:ab84dbbe7366
--- a/main.cpp Fri Oct 26 12:39:09 2012 +0000 +++ b/main.cpp Fri Feb 08 12:09:33 2013 +0000 @@ -1,6 +1,8 @@ #include "mbed.h" #include "WiflyInterface.h" #include "Websocket.h" +#include "LM75B.h" +#include "MMA7660.h" /* wifly interface: @@ -14,26 +16,34 @@ WiflyInterface wifly(p9, p10, p30, p29, "mbed", "password", WPA); +// accelerometer +MMA7660 acc(p28, p27); + +// temperature sensor +LM75B tmp(p28,p27); + + int main() { - int i=0; - char mystr[32]; + char json_str[100]; wifly.init(); //Use DHCP while (!wifly.connect()); printf("IP Address is %s\n\r", wifly.getIPAddress()); - Websocket ws("ws://sockets.mbed.org:443/ws/app-board/wo"); // See the output on http://sockets.mbed.org/app-board/viewer + Websocket ws("ws://sockets.mbed.org:443/ws/sensors/wo"); + + // connect WS server while (!ws.connect()); - ws.send("mbed application board"); - ws.send("Hello world!"); - while (1) { - sprintf(mystr,"%d",i); - ws.send(mystr); - wait(1.0); - i++; + // create json string with acc/tmp data + sprintf(json_str, "{\"id\":\"app_board_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); } } \ No newline at end of file