Test HTTPClient over WiFi

Dependencies:   HTTPClient WiflyInterface mbed

Files at this revision

API Documentation at this revision

Comitter:
bogdanm
Date:
Mon Mar 17 21:23:37 2014 +0000
Commit message:
Initial version

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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HTTPClient.lib	Mon Mar 17 21:23:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/donatien/code/HTTPClient/#1f743885e7de
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/WiflyInterface.lib	Mon Mar 17 21:23:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/mbed-official/code/WiflyInterface/#c77799a03294
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Mar 17 21:23:37 2014 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "WiflyInterface.h"
+#include "HTTPClient.h"
+
+// WiFi configuration (edit this)
+#define WIFI_SSID               ""
+#define WIFI_SECURITY           WPA    // NONE, WEP_128 or WPA
+#define WIFI_PASSWORD           ""
+             
+// ****************************************************************************
+// WiFi initialization
+
+static WiflyInterface wifly(p9, p10, p30, p29, WIFI_SSID, WIFI_PASSWORD, WIFI_SECURITY);
+
+int main(void)
+{
+    HTTPClient http;
+    char str[512];
+    
+    printf("\n******************************************************************\n");
+    wifly.init();
+    if(wifly.connect() == 0)
+        printf("Connect OK\n\r");
+    printf("IP Address is %s\n\r", wifly.getIPAddress());
+    
+    //POST data
+    HTTPText text(str, 512);
+    // LONG AND SHORT REQUESTS
+    HTTPText data("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n");
+    //HTTPText data("23123123lala\n");
+    printf("Trying to post data...\n");
+    int ret = http.post("http://vps.eluaproject.net:8888/", data, &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();
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 17 21:23:37 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/8e73be2a2ac1
\ No newline at end of file