Work with nodejs server: https://github.com/bjo3rn/idd-examples/tree/ben-node-demo/web/nodeServerHTTPSocket

Dependencies:   HTTPClient WebSocketClient cc3000_hostdriver_mbedsocket mbed

Fork of CC3000_demo by Ben Zhang

Files at this revision

API Documentation at this revision

Comitter:
antoni0
Date:
Fri Oct 10 23:38:09 2014 +0000
Parent:
6:149ce47889e9
Child:
8:594cb3bc6f0f
Commit message:
first working version

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
NVIC_set_all_priorities.lib Show annotated file Show diff for this revision Revisions of this file
cc3000_hostdriver_mbedsocket.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
main.h Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.lib	Tue Jun 03 09:32:29 2014 +0000
+++ b/HTTPClient.lib	Fri Oct 10 23:38:09 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
+http://mbed.org/users/donatien/code/HTTPClient/#277279a1891e
--- a/NVIC_set_all_priorities.lib	Tue Jun 03 09:32:29 2014 +0000
+++ b/NVIC_set_all_priorities.lib	Fri Oct 10 23:38:09 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#01504ecd2025
+http://mbed.org/users/frankvnk/code/NVIC_set_all_priorities/#6c8e950d8037
--- a/cc3000_hostdriver_mbedsocket.lib	Tue Jun 03 09:32:29 2014 +0000
+++ b/cc3000_hostdriver_mbedsocket.lib	Fri Oct 10 23:38:09 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/#50ab13d8f2dc
+http://mbed.org/users/Kojto/code/cc3000_hostdriver_mbedsocket/#ca8c234997c0
--- a/main.cpp	Tue Jun 03 09:32:29 2014 +0000
+++ b/main.cpp	Fri Oct 10 23:38:09 2014 +0000
@@ -33,88 +33,67 @@
 Serial pc(USBTX, USBRX);
 #else
 
+//KL25Z 149 connection
+cc3000 wifi(D3, D5, D10, SPI(D11, D12, D13), "antonio", "0123456789", WPA2, false);
+Serial pc(USBTX, USBRX);
 #endif
 
 HTTPClient http;
-char str[512];
+char str[10];
+int num_emails;
+
+DigitalOut led_red(LED_RED);
+DigitalOut led_green(LED_GREEN); 
+
+#define MAIL_URL "http://www.eecs.berkeley.edu/~antonio/149_count.txt"
+
 /**
- *  \brief HTTP client demo
+ *  \brief EECS149 demo
  *  \param  none
  *  \return int
  */
 int main() {
     init(); /* board dependent init */
     pc.baud(115200);
+    
+    led_red = 1;
+    led_green = 0;
 
-    printf("cc3000 HTTP client demo. \r\n");
+    printf("EECS149 email notifier. \r\n");
     wifi.init();
-    if (wifi.connect() == -1) {
-        printf("Failed to connect. Please verify connection details and try again. \r\n");
-        while(1);
-    } else {
-        printf("IP address: %s \r\n",wifi.getIPAddress());
-    }
     
-    //GET data
-    printf("\r\nTrying to fetch page... \r\n");
-    int ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
-    if (!ret)
-    {
-      printf("Page fetched successfully - read %d characters \r\n", strlen(str));
-      printf("Result: %s \r\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d \r\n", ret, http.getHTTPResponseCode());
-    }
-
-    //POST data
-    HTTPMap map;
-    HTTPText inText(str, 512);
-    map.put("Hello", "World");
-    map.put("test", "1234");
-    printf(" \r\nTrying to post data... \r\n");
-    ret = http.post("http://httpbin.org/post", map, &inText);
-    if (!ret)
-    {
-      printf("Executed POST successfully - read %d characters \r\n", strlen(str));
-      printf("Result: %s \r\n", str);
+    while(1) {
+        if(wifi.is_connected() == false) {
+            if (wifi.connect() == -1) {
+                printf("Failed to connect. Please verify connection details and try again. \r\n");
+            } else {
+                printf("IP address: %s \r\n",wifi.getIPAddress());
+            }
+        } else {
+            //GET mail data
+            printf("\r\nTrying to fetch mail info... \r\n");
+            int ret = http.get(MAIL_URL, str, 128);
+            if (!ret) {
+                printf("Page fetched successfully - read %d characters \r\n", strlen(str));
+                printf("Result: %s \r\n", str);
+                
+                num_emails = atoi(str);
+                
+                if(num_emails == 0) {
+                    led_red = 1;
+                    led_green = 0;    
+                } else {
+                    led_red = 0;
+                    led_green = 1;    
+                }
+                
+                
+            } else {
+                printf("Error - ret = %d - HTTP return code = %d \r\n", ret, http.getHTTPResponseCode());
+            }
+        }
+        wait(10.0);
     }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d \r\n", ret, http.getHTTPResponseCode());
-    }
+            
 
-    //PUT data
-    strcpy(str, "This is a PUT test!");
-    HTTPText outText(str);
-    //HTTPText inText(str, 512);
-    printf(" \r\nTrying to put resource... \r\n");
-    ret = http.put("http://httpbin.org/put", outText, &inText);
-    if (!ret)
-    {
-      printf("Executed PUT successfully - read %d characters \r\n", strlen(str));
-      printf("Result: %s \r\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d \r\n", ret, http.getHTTPResponseCode());
-    }
-
-    //DELETE data
-    //HTTPText inText(str, 512);
-    printf(" \r\nTrying to delete resource... \r\n");
-    ret = http.del("http://httpbin.org/delete", &inText);
-    if (!ret)
-    {
-      printf("Executed DELETE successfully - read %d characters \r\n", strlen(str));
-      printf("Result: %s \r\n", str);
-    }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d \r\n", ret, http.getHTTPResponseCode());
-    }
-
-    printf("Demo completed. \r\n");
-    wifi.disconnect();
 }
--- a/main.h	Tue Jun 03 09:32:29 2014 +0000
+++ b/main.h	Fri Oct 10 23:38:09 2014 +0000
@@ -21,7 +21,7 @@
 #define MBED_BOARD_EXAMPLE 3
 #define UNDEFINED          4
 
-#define MY_BOARD WIGO
+#define MY_BOARD UNDEFINED
 
 void init();