this is a demo code for HTTPClient_GPRS library

Dependencies:   GPRSInterface HTTPClient_GPRS mbed USBDevice

Fork of Seeed_HTTPClient_GPRSInterface_HelloWorld by wei zou

Revision:
1:16498811e319
Parent:
0:cc0bec77f305
Child:
2:ecc68e79d692
--- a/main.cpp	Thu Feb 27 07:39:48 2014 +0000
+++ b/main.cpp	Fri Mar 06 08:07:55 2015 +0000
@@ -2,29 +2,72 @@
 #include "GPRSInterface.h"
 #include "HTTPClient.h"
 
+#ifdef TARGET_ARCH_GPRS
+#include "USBSerial.h"
+#define LOG(args...)    pc.printf(args)
+USBSerial pc;
+#else
+#define LOG(args...)    pc.printf(args)
+Serial pc(USBTX, USBRX);
+#endif
+
 #define TEST_HTTP_GET       1
 #define TEST_HTTP_POST      1
 #define TEST_HTTP_PUT       1
 #define TEST_HTTP_DELETE    1
 
-#define PIN_TX              P0_0
-#define PIN_RX              P0_1
+#define PIN_TX              P1_27
+#define PIN_RX              P1_26
 
-GPRSInterface gprs(PIN_TX,PIN_RX,19200,"cmnet",NULL,NULL);
+
+GPRSInterface gprs(PIN_TX, PIN_RX, 115200, "uninet", NULL, NULL);
 HTTPClient http;
 char str[512];
 
+#ifdef TARGET_ARCH_GPRS
+DigitalOut power(P1_2);
+DigitalOut powerKey(P1_7);
+
+/* power pin: low enable
+     ___
+        |___
+
+   powerKey pin: you can also power up by long press the powerKey.
+
+        ___
+    ___|   |___
+
+*/
+void gprsPowerUp(void)
+{
+    power = 1;
+    wait(2);
+    power = 0;
+    wait(2);
+
+    powerKey = 0;
+    wait(1);
+    powerKey = 1;
+    wait(2);
+    powerKey = 0;
+    wait(3);
+}
+#endif
+
 int main()
 {
+#ifdef TARGET_ARCH_GPRS
+    gprsPowerUp();
+#endif
     gprs.init();
 
     while(false == gprs.connect()) {
-        printf("gprs connect error\n");
+        LOG("gprs connect error\n");
         wait(2);
     }
 
     // successful DHCP
-    printf("IP Address is %s\n", gprs.getIPAddress());
+    LOG("IP Address is %s\n", gprs.getIPAddress());
 
     int ret;
     HTTPMap map;
@@ -33,13 +76,13 @@
 
 #if TEST_HTTP_GET
     //GET data
-    printf("\nTrying to fetch page...\n");
+    LOG("\nTrying to fetch page...\n");
     ret = http.get("http://mbed.org/media/uploads/mbed_official/hello.txt", str, 512);
     if (!ret) {
-        printf("Page fetched successfully - read %d characters\n", strlen(str));
-        printf("Result: %s\n", str);
+        LOG("Page fetched successfully - read %d characters\n", strlen(str));
+        LOG("Result: %s\n", str);
     } else {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+        LOG("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
 #endif
 
@@ -47,36 +90,36 @@
     //POST data
     map.put("Hello", "World");
     map.put("test", "1234");
-    printf("\nTrying to post data...\n");
+    LOG("\nTrying to post data...\n");
     ret = http.post("http://httpbin.org/post", map, &inText);
     if (!ret) {
-        printf("Executed POST successfully\n");
+        LOG("Executed POST successfully\n");
     } else {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+        LOG("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
 #endif
 
 #if TEST_HTTP_PUT
     //PUT data
     strcpy(str, "This is a PUT test!");
-    printf("\nTrying to put resource...\n");
+    LOG("\nTrying to put resource...\n");
     ret = http.put("http://httpbin.org/put", outText, &inText);
     if (!ret) {
-        printf("Executed PUT successfully - read %d characters\n", strlen(str));
-        printf("Result: %s\n", str);
+        LOG("Executed PUT successfully - read %d characters\n", strlen(str));
+        LOG("Result: %s\n", str);
     } else {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+        LOG("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
 #endif
 
 #if TEST_HTTP_DELETE
     //DELETE data
-    printf("\nTrying to delete resource...\n");
+    LOG("\nTrying to delete resource...\n");
     ret = http.del("http://httpbin.org/delete", &inText);
     if (!ret) {
-        printf("Executed DELETE successfully\n");
+        LOG("Executed DELETE successfully\n");
     } else {
-        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+        LOG("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
     }
 #endif