Donavan Martin
/
Web_suck_et
Websocket example
Fork of Websocket_Ethernet_HelloWorld by
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 #include "mbed.h" 00002 #include "config.h" 00003 #include "seg.h" 00004 #include "ATcommand.h" 00005 00006 LocalFileSystem local("local"); 00007 Serial xbee(p9, p10); /*tx, rx */ 00008 DigitalOut rst(p5); 00009 Serial pc(USBTX, USBRX); 00010 Serial seg(p28, p27); 00011 DigitalOut btnState(p20); 00012 00013 char url[256]; 00014 00015 // Check connection 00016 #define TIMEOUT 1000 00017 #define RETRY_DELAY 100 00018 int connectionTimeout = TIMEOUT; 00019 char *packet = NULL; 00020 00021 #include "EthernetInterface.h" 00022 #include "Websocket.h" 00023 00024 int main() { 00025 display_dot(&seg); 00026 pc.printf("------Application Start------"); 00027 rst = 0; 00028 wait_ms(1000); 00029 rst = 1; 00030 wait_ms(1000); 00031 flush(&xbee, &pc); 00032 00033 int result = configFromFile("/local/config.txt", &xbee, &pc, url); 00034 pc.printf("OK Start receiving data"); 00035 char d[4]; 00036 00037 00038 00039 // Create a network interface and connect 00040 //EthernetInterface eth; 00041 //eth.connect(); 00042 //printf("IP Address is %s\n\r", eth.get_ip_address()); 00043 00044 // Create a websocket instance 00045 Websocket ws("ws://localhost.com:8080/"); 00046 int connect_error = ws.connect(); 00047 00048 // begin main loop 00049 while (true) { 00050 wait(0.5); 00051 int error_c = ws.send("Hello World\r\n"); 00052 } 00053 00054 00055 00056 00057 /*while(1){ 00058 while(xbee.readable()) { 00059 if(0 == isStartDelimiter(&xbee, &pc)){ 00060 int len = getLenght(&xbee, &pc); 00061 packet = readFrame(&xbee, &pc); 00062 00063 pc.printf("\n\rPacket type 0x%x",packet[0]); 00064 00065 if(packet[0]== 0x90){ 00066 char * params= NULL; 00067 params = readParam(&xbee, &pc); 00068 displayAngle(&seg,params); 00069 free(params); 00070 00071 }else if(packet[0]== 0x92){ 00072 char * params= NULL; 00073 params = readParam(&xbee, &pc); 00074 pc.printf("\n\r\tButtonState 0x%x",params[4]); 00075 if(params[4]== 0x10){ 00076 btnState = 1; 00077 }else if(params[4]== 0x00){ 00078 btnState = 0; 00079 } 00080 free(params); 00081 00082 }else if(decodePacket(&xbee, &pc, packet, len)==-1){ 00083 toggleError(&xbee, &pc, 200, "Packet Error"); 00084 } 00085 free(packet); 00086 }else{ 00087 toggleError(&xbee, &pc, 200, "Error in FrameID"); 00088 } 00089 flush(&xbee, &pc); 00090 } 00091 }*/ 00092 }
Generated on Sat Jul 16 2022 18:21:49 by 1.7.2