test

Dependencies:   C027 HTTPClient UbloxUSBModem mbed

Fork of C027_HTTPClientTest by u-blox

Revision:
7:c558c74ceb0f
Parent:
6:77c131006c67
Child:
8:95a97898084a
--- a/main.cpp	Mon Oct 21 08:50:06 2013 +0000
+++ b/main.cpp	Mon Oct 21 15:42:24 2013 +0000
@@ -5,32 +5,28 @@
 
 #include "HTTPClient.h"
 
-void test(void const*) 
+void test(void const*)
 {
     UbloxUSBGSMModem modem; // for LISA-C use the UbloxUSBCDMAModem instead
     HTTPClient http;
     char str[512];
-    
-    int ret = modem.connect(); // eventaully set a apn here
-    if(ret)
-    {
-      printf("Could not connect\n");
-      return;
+
+    int ret = modem.connect("internet"); // eventaully set another apn here
+    if(ret) {
+        printf("Could not connect\n");
+        return;
     }
-    
+
     //GET data
     printf("Trying to fetch page...\n");
     ret = http.get("http://mbed.org/media/uploads/donatien/hello.txt", str, 128);
-    if (!ret)
-    {
-      printf("Page fetched successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
+    if (!ret) {
+        printf("Page fetched successfully - read %d characters\n", strlen(str));
+        printf("Result: %s\n", str);
+    } else {
+        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
+
     //POST data
     HTTPMap map;
     HTTPText text(str, 512);
@@ -38,17 +34,14 @@
     map.put("test", "1234");
     printf("Trying to post data...\n");
     ret = http.post("http://httpbin.org/post", map, &text);
-    if (!ret)
-    {
-      printf("Executed POST successfully - read %d characters\n", strlen(str));
-      printf("Result: %s\n", str);
+    if (!ret) {
+        printf("Executed POST successfully - read %d characters\n", strlen(str));
+        printf("Result: %s\n", str);
+    } else {
+        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
-    else
-    {
-      printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
-    }
-    
-    modem.disconnect();  
+
+    modem.disconnect();
 
     while(1) {
     }
@@ -57,13 +50,12 @@
 
 int main()
 {
-  Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
-  DigitalOut led(A0);
-  while(1)
-  {
-    led=!led;
-    Thread::wait(1000);  
-  }
+    Thread testTask(test, NULL, osPriorityNormal, 1024 * 4);
+    DigitalOut led(A0);
+    while(1) {
+        led=!led;
+        Thread::wait(1000);
+    }
 
-  return 0;
+    return 0;
 }