tes

Dependencies:   ASyncTicker EthernetInterface WebSocketClient mbed-rtos mbed MbedJSONValue xbee_lib

Files at this revision

API Documentation at this revision

Comitter:
ammanvedi
Date:
Tue Jan 28 14:38:37 2014 +0000
Parent:
1:6c1df6c9be4d
Child:
3:28cd6502dafd
Commit message:
sockets

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Jan 27 22:46:13 2014 +0000
+++ b/main.cpp	Tue Jan 28 14:38:37 2014 +0000
@@ -16,7 +16,9 @@
 const char dest_address[8] = {0x00, 0x13, 0xA2, 0x00, 0x40, 0x9B, 0x6D, 0xB0};
 char send_data[50] = "xbee string";
 
+void pull_requests(){
 
+}
 
 void pull_updates(){
          char str[100];
@@ -40,6 +42,14 @@
             printf("id :  %s  string: %s (original: %s) \n\r", id, new_msg, str);
             
             //send string to xbee HERE
+        if(strlen(new_msg) == 0)
+        {
+            printf("nothing to update, better luck next time! (svr response: %s)\n\r", id);
+            return;
+        }else{
+            //data was revieved
+            printf("id :  %s  string: %s (original: %s) \n\r", id, new_msg, str);
+        }
             
         char to_send[100];
         char* p = to_send;
@@ -52,7 +62,7 @@
             *p++ = *r++;
         *p = '\0';
         
-                char data_buf[50];    
+        char data_buf[50];    
         xbee.InitFrame();
         xbee.SetDestination((unsigned char *)dest_address);
         xbee.SetPayload(to_send);
@@ -102,14 +112,17 @@
         error("ethernet failed to connect: %d.\n\r", ret_val);
     }
     
+    int interval = 5;
     
     ws.connect();
     
     Timer timer;
     timer.start();
+
+    //every <interval> seconds call to the server to pull updates
     
     while(true){
-        if(timer.read() >= 5){
+        if(timer.read() >= interval){
             //perform checks
             pull_updates();
             timer.reset();
@@ -118,8 +131,6 @@
     }
     
     //pull_updates();
-    
-    
         ws.close();
 
 }