This is a demo to show how to use Arch Link and dweet.io

Dependencies:   BLE_API DHT HTTPClient SDFileSystem WIZnet_Library mbed nRF51822

Fork of archlink_Temperture_ethernet_http by Kevin Lee

Files at this revision

API Documentation at this revision

Comitter:
Kevin_Lee
Date:
Tue Jun 30 07:28:24 2015 +0000
Parent:
1:0f6a216263aa
Child:
3:cfc6ff08a668
Commit message:
backup

Changed in this revision

HTTPClient.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Tue Jun 30 07:28:24 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
--- a/main.cpp	Tue Jun 30 05:41:58 2015 +0000
+++ b/main.cpp	Tue Jun 30 07:28:24 2015 +0000
@@ -2,9 +2,9 @@
 #include "SDFileSystem.h"
 #include "BLE.h"
 #include "WIZnetInterface.h"
-
+#include "HTTPClient.h"
 
-#define USE_DHCP 1
+#define USE_DHCP 0
 #define LOOPBACKPORT  5000
 int W5500_Test(void);
 
@@ -29,34 +29,63 @@
     wait(1);
     printf("helloworld\r\n");
     
-    if(W5500_Test() == 0) {
+    if(W5500_Test() == 0) {                  // Internet is ok
         printf("W5500 tested OK \r\n");
         
-        TCPSocketServer server;
+    char str[512];
+    char get_msg[128]= "";
+    
+    /*
+        http://dweet.io/follow/nameYouWant
+    */
+    char nameYouWant[] = "nameYouWant";
+    while(1)
+    {
+//        sprintf(get_msg,"http://dweet.io/dweet/for/%s?a0=%d",nameYouWant,(int)(1000));
+
+        sprintf(get_msg,"http://seeedmsvps.cloudapp.net:10080/plantbox/upload_iot/");
+        HTTPClient http;
         
-        server.bind(LOOPBACKPORT);
-        server.listen();
-        while(1) {
-            printf("\nWait for new connection...\r\n");
-            TCPSocketConnection client;
-            server.accept(client);
-            client.set_blocking(false,0); // Timeout = 0.
-            printf("Connection from: %s\r\n",client.get_address());
-            while (client.is_connected() == true) {
-                int n = client.receive(buffer,sizeof(buffer));
-                if (n > 0) {
-                    client.send_all(buffer,n);
-                } else {
-                }
-                if (client.is_fin_received()) {
-                    client.close();
-                } else {
-                }
+        pc.printf("Send post message to dweet.io\r\n");
+        pc.printf("msg : %s\r\n",get_msg);
+        ret = http.get(get_msg, str, sizeof(str));
+        if(!ret)
+        {
+          pc.printf("\r\nPage fetched successfully - read %d characters\r\n", strlen(str));
+          pc.printf("Result: %s\r\n", str);
+        }
+        else
+        {
+          pc.printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+        }
+        wait(10);
+    }
+    
+        
+        // TCPSocketServer server;
+        // server.bind(LOOPBACKPORT);
+        // server.listen();
+        // while(1) {
+            // printf("\nWait for new connection...\r\n");
+            // TCPSocketConnection client;
+            // server.accept(client);
+            // client.set_blocking(false,0); // Timeout = 0.
+            // printf("Connection from: %s\r\n",client.get_address());
+            // while (client.is_connected() == true) {
+                // int n = client.receive(buffer,sizeof(buffer));
+                // if (n > 0) {
+                    // client.send_all(buffer,n);
+                // } else {
+                // }
+                // if (client.is_fin_received()) {
+                    // client.close();
+                // } else {
+                // }
                 
-            }
-            printf("Disconnected.\r\n");
+            // }
+            // printf("Disconnected.\r\n");
             
-        }
+        // }
     }
     
     while(1) {