Test HTTPClient over WiFi
Dependencies: HTTPClient WiflyInterface mbed
main.cpp
00001 #include "mbed.h" 00002 #include "WiflyInterface.h" 00003 #include "HTTPClient.h" 00004 00005 // WiFi configuration (edit this) 00006 #define WIFI_SSID "" 00007 #define WIFI_SECURITY WPA // NONE, WEP_128 or WPA 00008 #define WIFI_PASSWORD "" 00009 00010 // **************************************************************************** 00011 // WiFi initialization 00012 00013 static WiflyInterface wifly(p9, p10, p30, p29, WIFI_SSID, WIFI_PASSWORD, WIFI_SECURITY); 00014 00015 int main(void) 00016 { 00017 HTTPClient http; 00018 char str[512]; 00019 00020 printf("\n******************************************************************\n"); 00021 wifly.init(); 00022 if(wifly.connect() == 0) 00023 printf("Connect OK\n\r"); 00024 printf("IP Address is %s\n\r", wifly.getIPAddress()); 00025 00026 //POST data 00027 HTTPText text(str, 512); 00028 // LONG AND SHORT REQUESTS 00029 HTTPText data("1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\n"); 00030 //HTTPText data("23123123lala\n"); 00031 printf("Trying to post data...\n"); 00032 int ret = http.post("http://vps.eluaproject.net:8888/", data, &text); 00033 00034 if (!ret) { 00035 printf("Executed POST successfully - read %d characters\n", strlen(str)); 00036 printf("Result: %s\n", str); 00037 } else { 00038 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); 00039 } 00040 00041 wifly.disconnect(); 00042 return 0; 00043 }
Generated on Thu Jul 14 2022 19:18:52 by 1.7.2