Team 6

Dependencies:   HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed

Fork of HTTPClient_WiFi_HelloWorld by KDDI Fx0 hackathon

Committer:
MACRUM
Date:
Fri Jan 23 09:56:32 2015 +0000
Revision:
3:837766adc429
Parent:
2:270e2d0bb85a
Child:
5:3dbedd084f79
Initial release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
donatien 0:0e0debc29569 1 #include "mbed.h"
MACRUM 3:837766adc429 2 #include "SNIC_WifiInterface.h"
donatien 0:0e0debc29569 3 #include "HTTPClient.h"
donatien 0:0e0debc29569 4
MACRUM 3:837766adc429 5 #if defined(TARGET_LPC1768)
MACRUM 3:837766adc429 6 #include "PowerControl/EthernetPowerControl.h"
MACRUM 3:837766adc429 7 #endif
MACRUM 3:837766adc429 8
MACRUM 3:837766adc429 9 #define DEMO_AP_SSID "SSID"
MACRUM 3:837766adc429 10 #define DEMO_AP_SECURITY_TYPE e_SEC_WPA2_AES
MACRUM 3:837766adc429 11 #define DEMO_AP_SECUTIRY_KEY "PASSWORD"
MACRUM 3:837766adc429 12
MACRUM 3:837766adc429 13 C_SNIC_WifiInterface wifi( p9, p10, NC, NC, p30 );
MACRUM 3:837766adc429 14
donatien 1:d263603373ac 15 HTTPClient http;
donatien 1:d263603373ac 16 char str[512];
donatien 1:d263603373ac 17
donatien 0:0e0debc29569 18 int main()
donatien 0:0e0debc29569 19 {
MACRUM 3:837766adc429 20 #if defined(TARGET_LPC1768)
MACRUM 3:837766adc429 21 PHY_PowerDown();
MACRUM 3:837766adc429 22 #endif
MACRUM 3:837766adc429 23
MACRUM 3:837766adc429 24 wifi.init(); //Use DHCP
donatien 0:0e0debc29569 25
MACRUM 3:837766adc429 26 wait(0.5);
MACRUM 3:837766adc429 27 int s = wifi.disconnect();
MACRUM 3:837766adc429 28 if( s != 0 ) {
MACRUM 3:837766adc429 29 return -1;
MACRUM 3:837766adc429 30 }
MACRUM 3:837766adc429 31
MACRUM 3:837766adc429 32 wait(0.3);
MACRUM 3:837766adc429 33 // Connect AP
MACRUM 3:837766adc429 34 wifi.connect( DEMO_AP_SSID
MACRUM 3:837766adc429 35 , strlen(DEMO_AP_SSID)
MACRUM 3:837766adc429 36 , DEMO_AP_SECURITY_TYPE
MACRUM 3:837766adc429 37 , DEMO_AP_SECUTIRY_KEY
MACRUM 3:837766adc429 38 , strlen(DEMO_AP_SECUTIRY_KEY) );
MACRUM 3:837766adc429 39 wait(0.5);
MACRUM 3:837766adc429 40 wifi.setIPConfig( true );
MACRUM 3:837766adc429 41 wait(0.5);
MACRUM 3:837766adc429 42 printf("IP Address is %s\n", wifi.getIPAddress());
donatien 0:0e0debc29569 43
donatien 0:0e0debc29569 44 //GET data
donatien 2:270e2d0bb85a 45 printf("\nTrying to fetch page...\n");
MACRUM 3:837766adc429 46 int ret = http.get("http://developer.mbed.org/media/uploads/donatien/hello.txt", str, 128);
donatien 0:0e0debc29569 47 if (!ret)
donatien 0:0e0debc29569 48 {
donatien 0:0e0debc29569 49 printf("Page fetched successfully - read %d characters\n", strlen(str));
donatien 0:0e0debc29569 50 printf("Result: %s\n", str);
donatien 0:0e0debc29569 51 }
donatien 0:0e0debc29569 52 else
donatien 0:0e0debc29569 53 {
donatien 0:0e0debc29569 54 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
donatien 0:0e0debc29569 55 }
donatien 1:d263603373ac 56
donatien 0:0e0debc29569 57 //POST data
donatien 0:0e0debc29569 58 HTTPMap map;
donatien 2:270e2d0bb85a 59 HTTPText inText(str, 512);
donatien 0:0e0debc29569 60 map.put("Hello", "World");
donatien 0:0e0debc29569 61 map.put("test", "1234");
donatien 2:270e2d0bb85a 62 printf("\nTrying to post data...\n");
donatien 2:270e2d0bb85a 63 ret = http.post("http://httpbin.org/post", map, &inText);
donatien 0:0e0debc29569 64 if (!ret)
donatien 0:0e0debc29569 65 {
donatien 0:0e0debc29569 66 printf("Executed POST successfully - read %d characters\n", strlen(str));
donatien 0:0e0debc29569 67 printf("Result: %s\n", str);
donatien 0:0e0debc29569 68 }
donatien 0:0e0debc29569 69 else
donatien 0:0e0debc29569 70 {
donatien 0:0e0debc29569 71 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
donatien 0:0e0debc29569 72 }
donatien 0:0e0debc29569 73
donatien 2:270e2d0bb85a 74 //PUT data
donatien 2:270e2d0bb85a 75 strcpy(str, "This is a PUT test!");
donatien 2:270e2d0bb85a 76 HTTPText outText(str);
donatien 2:270e2d0bb85a 77 //HTTPText inText(str, 512);
donatien 2:270e2d0bb85a 78 printf("\nTrying to put resource...\n");
donatien 2:270e2d0bb85a 79 ret = http.put("http://httpbin.org/put", outText, &inText);
donatien 2:270e2d0bb85a 80 if (!ret)
donatien 2:270e2d0bb85a 81 {
donatien 2:270e2d0bb85a 82 printf("Executed PUT successfully - read %d characters\n", strlen(str));
donatien 2:270e2d0bb85a 83 printf("Result: %s\n", str);
donatien 2:270e2d0bb85a 84 }
donatien 2:270e2d0bb85a 85 else
donatien 2:270e2d0bb85a 86 {
donatien 2:270e2d0bb85a 87 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
donatien 2:270e2d0bb85a 88 }
donatien 2:270e2d0bb85a 89
donatien 2:270e2d0bb85a 90 //DELETE data
donatien 2:270e2d0bb85a 91 //HTTPText inText(str, 512);
donatien 2:270e2d0bb85a 92 printf("\nTrying to delete resource...\n");
donatien 2:270e2d0bb85a 93 ret = http.del("http://httpbin.org/delete", &inText);
donatien 2:270e2d0bb85a 94 if (!ret)
donatien 2:270e2d0bb85a 95 {
donatien 2:270e2d0bb85a 96 printf("Executed DELETE successfully - read %d characters\n", strlen(str));
donatien 2:270e2d0bb85a 97 printf("Result: %s\n", str);
donatien 2:270e2d0bb85a 98 }
donatien 2:270e2d0bb85a 99 else
donatien 2:270e2d0bb85a 100 {
donatien 2:270e2d0bb85a 101 printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode());
donatien 2:270e2d0bb85a 102 }
donatien 2:270e2d0bb85a 103
MACRUM 3:837766adc429 104 wifi.disconnect();
donatien 0:0e0debc29569 105
donatien 0:0e0debc29569 106 while(1) {
donatien 0:0e0debc29569 107 }
donatien 0:0e0debc29569 108 }