Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: GPRSInterface USBDevice mbed
Fork of Seeed_HTTPClient_GPRSInterface_HelloWorld by
Diff: main.cpp
- Revision:
- 0:cc0bec77f305
- Child:
- 1:16498811e319
--- /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;
+}
