this is a demo code for HTTPClient_GPRS library
Dependencies: GPRSInterface HTTPClient_GPRS mbed USBDevice
Fork of Seeed_HTTPClient_GPRSInterface_HelloWorld by
Revision 0:cc0bec77f305, committed 2014-02-27
- Comitter:
- lawliet
- Date:
- Thu Feb 27 07:39:48 2014 +0000
- Child:
- 1:16498811e319
- Commit message:
- Initial Version of Seeed_HTTPClient_GPRSInterface_HelloWorld
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GPRSInterface.lib Thu Feb 27 07:39:48 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/lawliet/code/GPRSInterface/#1142bdd07989
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/HTTPClient_GPRS.lib Thu Feb 27 07:39:48 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/lawliet/code/HTTPClient_GPRS/#f22357c94c81
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Feb 27 07:39:48 2014 +0000 @@ -0,0 +1,86 @@ +#include "mbed.h" +#include "GPRSInterface.h" +#include "HTTPClient.h" + +#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 + +GPRSInterface gprs(PIN_TX,PIN_RX,19200,"cmnet",NULL,NULL); +HTTPClient http; +char str[512]; + +int main() +{ + gprs.init(); + + while(false == gprs.connect()) { + printf("gprs connect error\n"); + wait(2); + } + + // successful DHCP + printf("IP Address is %s\n", gprs.getIPAddress()); + + int ret; + HTTPMap map; + HTTPText inText(str, 512); + HTTPText outText(str); + +#if TEST_HTTP_GET + //GET data + printf("\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); + } else { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } +#endif + +#if TEST_HTTP_POST + //POST data + map.put("Hello", "World"); + map.put("test", "1234"); + printf("\nTrying to post data...\n"); + ret = http.post("http://httpbin.org/post", map, &inText); + if (!ret) { + printf("Executed POST successfully\n"); + } else { + printf("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"); + 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); + } else { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } +#endif + +#if TEST_HTTP_DELETE + //DELETE data + printf("\nTrying to delete resource...\n"); + ret = http.del("http://httpbin.org/delete", &inText); + if (!ret) { + printf("Executed DELETE successfully\n"); + } else { + printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); + } +#endif + + gprs.disconnect(); + + return 0; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Feb 27 07:39:48 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1 \ No newline at end of file