Test HTTPClient over WiFi
Dependencies: HTTPClient WiflyInterface mbed
main.cpp
- Committer:
- bogdanm
- Date:
- 2014-03-17
- Revision:
- 0:fac87adbcc27
File content as of revision 0:fac87adbcc27:
#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; }