![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
testing
Dependencies: HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed
Fork of Fx0Hackson by
main.cpp
- Committer:
- MACRUM
- Date:
- 2015-01-23
- Revision:
- 3:837766adc429
- Parent:
- 2:270e2d0bb85a
- Child:
- 5:3dbedd084f79
File content as of revision 3:837766adc429:
#include "mbed.h" #include "SNIC_WifiInterface.h" #include "HTTPClient.h" #if defined(TARGET_LPC1768) #include "PowerControl/EthernetPowerControl.h" #endif #define DEMO_AP_SSID "SSID" #define DEMO_AP_SECURITY_TYPE e_SEC_WPA2_AES #define DEMO_AP_SECUTIRY_KEY "PASSWORD" C_SNIC_WifiInterface wifi( p9, p10, NC, NC, p30 ); HTTPClient http; char str[512]; int main() { #if defined(TARGET_LPC1768) PHY_PowerDown(); #endif wifi.init(); //Use DHCP wait(0.5); int s = wifi.disconnect(); if( s != 0 ) { return -1; } wait(0.3); // Connect AP wifi.connect( DEMO_AP_SSID , strlen(DEMO_AP_SSID) , DEMO_AP_SECURITY_TYPE , DEMO_AP_SECUTIRY_KEY , strlen(DEMO_AP_SECUTIRY_KEY) ); wait(0.5); wifi.setIPConfig( true ); wait(0.5); printf("IP Address is %s\n", wifi.getIPAddress()); //GET data printf("\nTrying to fetch page...\n"); int ret = http.get("http://developer.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 inText(str, 512); 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 - read %d characters\n", strlen(str)); printf("Result: %s\n", str); } else { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); } //PUT data strcpy(str, "This is a PUT test!"); HTTPText outText(str); //HTTPText inText(str, 512); 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()); } //DELETE data //HTTPText inText(str, 512); printf("\nTrying to delete resource...\n"); ret = http.del("http://httpbin.org/delete", &inText); if (!ret) { printf("Executed DELETE 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()); } wifi.disconnect(); while(1) { } }