Team 6

Dependencies:   HTTPClient PowerControl SNICInterface_mod mbed-rtos mbed

Fork of HTTPClient_WiFi_HelloWorld by KDDI Fx0 hackathon

main.cpp

Committer:
daisukekmr
Date:
2015-02-14
Revision:
6:1273e99a6058
Parent:
5:3dbedd084f79
Child:
7:bf74da76618b

File content as of revision 6:1273e99a6058:

#include "mbed.h"

#include "SNIC_WifiInterface.h"
#include "HTTPClient.h"
#if defined(TARGET_LPC1768)
#include "PowerControl/EthernetPowerControl.h"
#endif

#define DEMO_AP_SSID                  "nad11-10e168"
#define DEMO_AP_SECURITY_TYPE         e_SEC_WPA2_AES
#define DEMO_AP_SECUTIRY_KEY          "18e36c5e791f9"

C_SNIC_WifiInterface     wifi( p9, p10, NC, NC, p30 );

#if defined(_DEBUG)
Serial pc(USBTX, USBRX);
#endif

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());
    }
    
    wifi.disconnect();  

    while(1) {
    }
}