webrocket program
Dependencies: EthernetInterface WebSocketClient mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:48b13b1064ba
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Dec 13 08:18:12 2016 +0000 @@ -0,0 +1,68 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "Websocket.h" + + +DigitalOut myled(LED1); +DigitalOut myled2(LED2); +DigitalOut myled3(LED3); +DigitalOut myled4(LED4); +Serial pc (USBTX,USBRX); + char mess[100]; + +int main() { + + EthernetInterface ether; + ether.init(); + ether.connect(); + + + + + myled=1; + + Websocket ws("ws://sockets.mbed.org:443/ws/fadel/rw"); + ws.connect(); + myled2=1; + + pc.printf("\n connected %s\n\r"); + // TCPSocketConnection ggg; + // char ip[4]; + // ip[0] = 192; + // ip[1] = 168; + // ip[2] = 1; + // ip[3] = 2; + + // ggg.connect(ip,3000); + // myled = 1; + + while(1) { + + +if(ws.is_connected()) + myled3=1; + else if(!ws.is_connected()) + myled3=0; + + + // ws.send("FADEL :)"); + if( ws.read(mess)) + { + pc.printf("\n received %s\n\r"); + myled4 = 1; + pc.printf(mess); + // pc.printf("\n IP Address is %s\n\r", ether.getIPAddress()); + // ws.close(); + myled4 = 0; + } + + // wait(1); + // if(ggg.is_connected()) + // myled3=1; + // pc.printf("IP Address is %s\n\r", ether.getIPAddress()); + // pc.printf("\n\r Network mask is %s\n\r", ether.getNetworkMask()); + // pc.printf("\n\r Gatewa ip Address is %s\n\r", ether.getGateway()); + // myled4 = 0; + // wait(1); + } +}