easy connect wnc added to http request with debug mode enabled. traces collected for AT%CGEQOS, AT%MEAS, AT%PCONI

Dependencies:   easy-connect-httpmodified mbed-http

Fork of http-example-wnc-modified by Tyler Davis

Files at this revision

API Documentation at this revision

Comitter:
nrithya
Date:
Thu Dec 14 00:34:03 2017 +0000
Parent:
20:1c3499729772
Commit message:
easy connect wnc added to http request with debug mode enabled. traces collected for AT%CGEQOS, AT%MEAS, AT%PCONI

Changed in this revision

easy-connect.lib Show annotated file Show diff for this revision Revisions of this file
mbed-http.lib Show annotated file Show diff for this revision Revisions of this file
source/main-http.cpp Show annotated file Show diff for this revision Revisions of this file
source/main-https.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 1c3499729772 -r 92bdf75ae72b easy-connect.lib
--- a/easy-connect.lib	Mon Nov 13 18:53:10 2017 +0000
+++ b/easy-connect.lib	Thu Dec 14 00:34:03 2017 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/users/JMF/code/easy-connect/#daf182af022b
+https://os.mbed.com/users/nrithya/code/easy-connect-httpmodified/#54ac58ec99d5
diff -r 1c3499729772 -r 92bdf75ae72b mbed-http.lib
--- a/mbed-http.lib	Mon Nov 13 18:53:10 2017 +0000
+++ b/mbed-http.lib	Thu Dec 14 00:34:03 2017 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/sandbox/code/mbed-http/#3004056e4661
+https://developer.mbed.org/teams/sandbox/code/mbed-http/#a5371b71de6f
diff -r 1c3499729772 -r 92bdf75ae72b source/main-http.cpp
--- a/source/main-http.cpp	Mon Nov 13 18:53:10 2017 +0000
+++ b/source/main-http.cpp	Thu Dec 14 00:34:03 2017 +0000
@@ -7,7 +7,7 @@
 #include "http_request.h"
 
 Serial pc(USBTX, USBRX);
-
+Timer t;
 void dump_response(HttpResponse* res) {
     printf("Status: %d - %s\n", res->get_status_code(), res->get_status_message().c_str());
 
@@ -18,12 +18,19 @@
     printf("\nBody (%d bytes):\n\n%s\n", res->get_body_length(), res->get_body_as_string().c_str());
 }
 
+void body_callback(const char* data, size_t data_len) {
+    // simply return, leading to the data being lost.
+    // Necessary for large sizes in order to ensure that there isn't an 
+    // exhaustion of memory with the large video test.
+    return;
+}
+
 int main() {
     pc.baud(115200);
     // Connect to the network (see mbed_app.json for the connectivity method used)
-    while(1) {
+    for(int i=1;i<10;i++) {
         printf("Hello?\n");
-    }
+}
     NetworkInterface *network = easy_connect(true);
     if (!network) {
         printf("Cannot connect to the network, see serial output");
@@ -33,12 +40,18 @@
     printf("See if it gives any debug info");
 
     // Do a GET request to httpbin.org
+    //while(1)
     {
         // By default the body is automatically parsed and stored in a buffer, this is memory heavy.
         // To receive chunked response, pass in a callback as last parameter to the constructor.
+        t.start();
+        // HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "https://www.google.com/search?q=%E2%80%9CTrading+Structure+for+Randomness+in+Wireless+Opportunistic+Routing%E2%80%9D&oq=%E2%80%9CTrading+Structure+for+Randomness+in+Wireless+Opportunistic+Routing%E2%80%9D&aqs=chrome..69i57j0j69i60.1298j0j8&sourceid=chrome&ie=UTF-8");
         HttpRequest* get_req = new HttpRequest(network, HTTP_GET, "http://httpbin.org/status/418");
-
         HttpResponse* get_res = get_req->send();
+        t.stop();
+        printf("loading time: %f \n",t.read());
+        printf("Body_length: %d \n", get_res->get_body_length());
+        
         if (!get_res) {
             printf("HttpRequest failed (error code %d)\n", get_req->get_error());
             return 1;
@@ -46,28 +59,29 @@
 
         printf("\n----- HTTP GET response -----\n");
         dump_response(get_res);
+        t.reset();
 
         delete get_req;
     }
 
     // POST request to httpbin.org
-    {
-        HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
-        post_req->set_header("Content-Type", "application/json");
-
-        const char body[] = "{\"hello\":\"world\"}";
-
-        HttpResponse* post_res = post_req->send(body, strlen(body));
-        if (!post_res) {
-            printf("HttpRequest failed (error code %d)\n", post_req->get_error());
-            return 1;
-        }
-
-        printf("\n----- HTTP POST response -----\n");
-        dump_response(post_res);
-
-        delete post_req;
-    }
+    //{
+//        HttpRequest* post_req = new HttpRequest(network, HTTP_POST, "http://httpbin.org/post");
+//        post_req->set_header("Content-Type", "application/json");
+//
+//        const char body[] = "{\"hello\":\"world\"}";
+//
+//        HttpResponse* post_res = post_req->send(body, strlen(body));
+//        if (!post_res) {
+//            printf("HttpRequest failed (error code %d)\n", post_req->get_error());
+//            return 1;
+//        }
+//
+//        printf("\n----- HTTP POST response -----\n");
+//        dump_response(post_res);
+//
+//        delete post_req;
+//    }
 
     Thread::wait(osWaitForever);
 }
diff -r 1c3499729772 -r 92bdf75ae72b source/main-https.cpp
--- a/source/main-https.cpp	Mon Nov 13 18:53:10 2017 +0000
+++ b/source/main-https.cpp	Thu Dec 14 00:34:03 2017 +0000
@@ -7,7 +7,7 @@
 #include "https_request.h"
 
 Serial pc(USBTX, USBRX);
-
+Timer load_timer;
 /* List of trusted root CA certificates
  * currently two: GlobalSign, the CA for developer.mbed.org and Let's Encrypt, the CA for httpbin.org
  *
@@ -60,6 +60,47 @@
     "X4Po1QYz+3dszkDqMp4fklxBwXRsW10KXzPMTZ+sOPAveyxindmjkW8lGy+QsRlG\n"
     "PfZ+G6Z6h7mjem0Y+iWlkYcV4PIWL1iwBi8saCbGS5jN2p8M+X+Q7UNKEkROb3N6\n"
     "KOqkqm57TH2H3eDJAkSnh6/DNFu0Qg==\n"
+    "-----END CERTIFICATE-----\n"
+    "-----BEGIN CERTIFICATE-----\n"
+    "MIIDfDCCAmSgAwIBAgIQGKy1av1pthU6Y2yv2vrEoTANBgkqhkiG9w0BAQUFADBY\n"
+    "MQswCQYDVQQGEwJVUzEWMBQGA1UEChMNR2VvVHJ1c3QgSW5jLjExMC8GA1UEAxMo\n"
+    "R2VvVHJ1c3QgUHJpbWFyeSBDZXJ0aWZpY2F0aW9uIEF1dGhvcml0eTAeFw0wNjEx\n"
+    "MjcwMDAwMDBaFw0zNjA3MTYyMzU5NTlaMFgxCzAJBgNVBAYTAlVTMRYwFAYDVQQK\n"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fOEVEiIuCl6rYVSAlk6l5PdPcF\n"
+    "PseKUgzbFbS9bZvlxrFUaKnjaZC2mqUPuLk/IH2uSrW4nOQdtqvmlKXBx4Ot2/Un\n"
+    "hw4EbNX/3aBd7YdStysVAq45pmp06drE57xNNB6pXE0zX5IJL4hmXXeXxx12E6nV\n"
+    "5fEWCRE11azbJHFwLJhWC9kXtNHjUStedejV0NxPNO3CBWaAocvmMw==\n"
     "-----END CERTIFICATE-----\n";
 
 void dump_response(HttpResponse* res) {
@@ -84,10 +125,16 @@
     {
         printf("\n----- HTTPS GET request -----\n");
 
-        HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://developer.mbed.org/media/uploads/mbed_official/hello.txt");
+        load_timer.start();
+
+        HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://os.mbed.com/media/uploads/mbed_official/hello.txt");
+        // HttpsRequest* get_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_GET, "https://www.youtube.com/watch?v=0Z6anghBKzQ");
+        
         get_req->set_debug(true);
+        HttpResponse* get_res = get_req->send();
+        load_timer.stop();
+        printf("loading time: %f",load_timer.read());
 
-        HttpResponse* get_res = get_req->send();
         if (!get_res) {
             printf("HttpRequest failed (error code %d)\n", get_req->get_error());
             return 1;
@@ -99,26 +146,26 @@
     }
 
     // POST request to httpbin.org
-    {
-        printf("\n----- HTTPS POST request -----\n");
-
-        HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://httpbin.org/post");
-        post_req->set_debug(true);
-        post_req->set_header("Content-Type", "application/json");
-
-        const char body[] = "{\"hello\":\"world\"}";
-
-        HttpResponse* post_res = post_req->send(body, strlen(body));
-        if (!post_res) {
-            printf("HttpRequest failed (error code %d)\n", post_req->get_error());
-            return 1;
-        }
-
-        printf("\n----- HTTPS POST response -----\n");
-        dump_response(post_res);
-
-        delete post_req;
-    }
+//    {
+//        printf("\n----- HTTPS POST request -----\n");
+//
+//        HttpsRequest* post_req = new HttpsRequest(network, SSL_CA_PEM, HTTP_POST, "https://httpbin.org/post");
+//        post_req->set_debug(true);
+//        post_req->set_header("Content-Type", "application/json");
+//
+//        const char body[] = "{\"hello\":\"world\"}";
+//
+//        HttpResponse* post_res = post_req->send(body, strlen(body));
+//        if (!post_res) {
+//            printf("HttpRequest failed (error code %d)\n", post_req->get_error());
+//            return 1;
+//        }
+//
+//        printf("\n----- HTTPS POST response -----\n");
+//        dump_response(post_res);
+//
+//        delete post_req;
+//    }
 
     Thread::wait(osWaitForever);
 }