testing

Dependencies:   HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed

Fork of Fx0Hackson by Daisuke Kimura

Committer:
MACRUM
Date:
Sat Jan 31 13:49:47 2015 +0000
Revision:
5:3dbedd084f79
Parent:
3:837766adc429
Child:
6:1273e99a6058
Updated latest libraries

Who changed what in which revision?

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