Donavan Martin
/
Web_suck_et
Websocket example
Fork of Websocket_Ethernet_HelloWorld by
main.cpp
- Committer:
- Dontydonty
- Date:
- 2017-12-03
- Revision:
- 8:1b4bf6e5e029
- Parent:
- 6:2fae6e37c5ca
File content as of revision 8:1b4bf6e5e029:
#include "mbed.h" #include "config.h" #include "seg.h" #include "ATcommand.h" LocalFileSystem local("local"); Serial xbee(p9, p10); /*tx, rx */ DigitalOut rst(p5); Serial pc(USBTX, USBRX); Serial seg(p28, p27); DigitalOut btnState(p20); char url[256]; // Check connection #define TIMEOUT 1000 #define RETRY_DELAY 100 int connectionTimeout = TIMEOUT; char *packet = NULL; #include "EthernetInterface.h" #include "Websocket.h" int main() { display_dot(&seg); pc.printf("------Application Start------"); rst = 0; wait_ms(1000); rst = 1; wait_ms(1000); flush(&xbee, &pc); int result = configFromFile("/local/config.txt", &xbee, &pc, url); pc.printf("OK Start receiving data"); char d[4]; // Create a network interface and connect //EthernetInterface eth; //eth.connect(); //printf("IP Address is %s\n\r", eth.get_ip_address()); // Create a websocket instance Websocket ws("ws://localhost.com:8080/"); int connect_error = ws.connect(); // begin main loop while (true) { wait(0.5); int error_c = ws.send("Hello World\r\n"); } /*while(1){ while(xbee.readable()) { if(0 == isStartDelimiter(&xbee, &pc)){ int len = getLenght(&xbee, &pc); packet = readFrame(&xbee, &pc); pc.printf("\n\rPacket type 0x%x",packet[0]); if(packet[0]== 0x90){ char * params= NULL; params = readParam(&xbee, &pc); displayAngle(&seg,params); free(params); }else if(packet[0]== 0x92){ char * params= NULL; params = readParam(&xbee, &pc); pc.printf("\n\r\tButtonState 0x%x",params[4]); if(params[4]== 0x10){ btnState = 1; }else if(params[4]== 0x00){ btnState = 0; } free(params); }else if(decodePacket(&xbee, &pc, packet, len)==-1){ toggleError(&xbee, &pc, 200, "Packet Error"); } free(packet); }else{ toggleError(&xbee, &pc, 200, "Error in FrameID"); } flush(&xbee, &pc); } }*/ }