HTTPClient Hello World with the WiflyInterface

Dependencies:   HTTPClient WiflyInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
samux
Date:
Fri Aug 24 15:21:55 2012 +0000
Commit message:
HTTPClient with the mbed_official WiflyInterface

Changed in this revision

HTTPClient.lib Show annotated file Show diff for this revision Revisions of this file
WiflyInterface.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
diff -r 000000000000 -r cba63cb4bbf9 HTTPClient.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Fri Aug 24 15:21:55 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#be61104f4e91
diff -r 000000000000 -r cba63cb4bbf9 WiflyInterface.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiflyInterface.lib	Fri Aug 24 15:21:55 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/WiflyInterface/#fb4494783863
diff -r 000000000000 -r cba63cb4bbf9 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 24 15:21:55 2012 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "WiflyInterface.h"
+#include "HTTPClient.h"
+
+/* wifly interface:
+*     - p9 and p10 are for the serial communication
+*     - p19 is for the reset pin
+*     - p26 is for the connection status
+*     - "mbed" is the ssid of the network
+*     - "password" is the password
+*     - WPA is the security
+*/
+WiflyInterface wifly(p9, p10, p19, p26, "mbed", "password", WPA);
+
+HTTPClient http;
+char str[512];
+
+int main()
+{
+    wifly.init(); //Use DHCP
+
+    wifly.connect();
+
+    //GET data
+    printf("Trying to fetch page...\n");
+    int 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);
+    } else {
+        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+    }
+
+    //POST data
+    HTTPMap map;
+    HTTPText text(str, 512);
+    map.put("Hello", "World");
+    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);
+    } else {
+        printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
+    }
+
+    wifly.disconnect();
+
+    while(1) {
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r cba63cb4bbf9 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 24 15:21:55 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/10b9abbe79a6
\ No newline at end of file