this is a demo code for HTTPClient_GPRS library

Dependencies:   GPRSInterface HTTPClient_GPRS mbed USBDevice

Fork of Seeed_HTTPClient_GPRSInterface_HelloWorld by wei zou

Files at this revision

API Documentation at this revision

Comitter:
yihui
Date:
Fri Mar 06 08:07:55 2015 +0000
Parent:
0:cc0bec77f305
Child:
2:ecc68e79d692
Commit message:
add code for Arch GPRS

Changed in this revision

GPRSInterface.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice.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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/GPRSInterface.lib	Thu Feb 27 07:39:48 2014 +0000
+++ b/GPRSInterface.lib	Fri Mar 06 08:07:55 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/lawliet/code/GPRSInterface/#1142bdd07989
+http://mbed.org/users/lawliet/code/GPRSInterface/#180feb3ebe62
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice.lib	Fri Mar 06 08:07:55 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/USBDevice/#4f589e246b9e
--- 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
 
--- a/mbed.bld	Thu Feb 27 07:39:48 2014 +0000
+++ b/mbed.bld	Fri Mar 06 08:07:55 2015 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/7e07b6fb45cf
\ No newline at end of file