Websocket example

Dependencies:   WebSocketClient

Fork of Websocket_Ethernet_HelloWorld by mbed_example

Revision:
8:1b4bf6e5e029
Parent:
6:2fae6e37c5ca
--- a/main.cpp	Fri Jun 23 14:05:26 2017 -0500
+++ b/main.cpp	Sun Dec 03 18:19:22 2017 +0000
@@ -1,51 +1,92 @@
-/* Copyright C2014 ARM, MIT License
- *
- * Author: Doug Anson (doug.anson@arm.com)
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
- * and associated documentation files the "Software", to deal in the Software without restriction,
- * including without limitation the rights to use, copy, modify, merge, publish, distribute,
- * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all copies or
- * substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
- * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- */
+#include "mbed.h"
+#include "config.h"
+#include "seg.h"
+#include "ATcommand.h"
 
-#include "mbed.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"
 
-// Blinky
-DigitalOut led(LED1);
-
-int main() {   
+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];
+    
+    
 
-    // announce
-    printf("Websocket Example v1.0.0\r\n");
-    
     // Create a network interface and connect
-    EthernetInterface eth;
-    eth.connect();
-    printf("IP Address is %s\n\r", eth.get_ip_address());
+    //EthernetInterface eth;
+    //eth.connect();
+    //printf("IP Address is %s\n\r", eth.get_ip_address());
 
     // Create a websocket instance
-    Websocket ws("ws://example.com:8080/", &eth);
+    Websocket ws("ws://localhost.com:8080/");
     int connect_error = ws.connect();
     
     // begin main loop
     while (true) {
-
-        // blink... 
-        led = !led; 
         wait(0.5);
-        
         int error_c = ws.send("Hello World\r\n");
     }
-}
\ No newline at end of file
+    
+    
+    
+    
+    /*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);
+        }
+    }*/
+}