Websocket demo for app board by C. Styles with updated libraries. DHCP service and a network cable is required.
Dependencies: C12832 EthernetInterface HTTPServer LM75B MMA7660 WebSocketClient mbed-rtos mbed
Fork of app-board-Ethernet-Websocket by
Revision 4:bcc028e40b63, committed 2014-05-22
- Comitter:
- geekymartian
- Date:
- Thu May 22 14:51:50 2014 +0000
- Parent:
- 3:26f41c921c2d
- Commit message:
- First publish
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Thu May 22 14:51:50 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/components/code/C12832/#1c3011afe95d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPServer.lib Thu May 22 14:51:50 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbeduet2013/code/HTTPServer/#d753966e4d97
--- a/main.cpp Tue Oct 01 20:17:19 2013 +0000 +++ b/main.cpp Thu May 22 14:51:50 2014 +0000 @@ -1,5 +1,6 @@ #include "mbed.h" #include "EthernetInterface.h" +#include "C12832.h" #include "Websocket.h" #include "MMA7660.h" #include "LM75B.h" @@ -10,11 +11,32 @@ // temperature sensor LM75B tmp(p28,p27); +// rgb led +PwmOut r (p23); +PwmOut g (p24); +PwmOut b (p25); + +// lcd +C12832 lcd(p5, p7, p6, p8, p11); + +// speaker +DigitalIn fire(p14); +PwmOut spkr(p26); + +// led DigitalOut l1(LED1); int main() { char json_str[100]; + for(float i = 0.0; i < 1.0 ; i += 0.001) { + float p = 3 * i; + r = 1.0 - ((p < 1.0) ? 1.0 - p : (p > 2.0) ? p - 2.0 : 0.0); + g = 1.0 - ((p < 1.0) ? p : (p > 2.0) ? 0.0 : 2.0 - p); + b = 1.0 - ((p < 1.0) ? 0.0 : (p > 2.0) ? 3.0 - p : p - 1.0); ; + wait (0.01); + } + if (acc.testConnection()) l1 = 1; @@ -25,16 +47,35 @@ 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"); + // you need to specify a channel! otherwise this shit won't work! + // "the /ws is important!" + Websocket ws("ws://192.168.0.101:8001/ws"); ws.connect(); - + char recv[50]; + lcd.printf("SF1 Dev Week, here we go!"); + ws.send(json_str); 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()); + //sprintf(json_str, "{\"id\":\"geekymartianboard\",\"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); + //ws.send(json_str); + + wait(5.0); - wait(0.1); + if(ws.read(recv)) { + printf(recv); + lcd.printf("Received a message:\n"); + lcd.printf(recv); + + for (float i=2000.0; i<10000.0; i+=100) { + spkr.period(1.0/i); + spkr=0.5; + wait(0.1); + } + spkr=0.0; + while(!fire) {} + + } } } \ No newline at end of file