Fx0 hackathon team4

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServerSample by KDDI Fx0 hackathon

Committer:
yi
Date:
Sun Feb 15 00:18:07 2015 +0000
Revision:
1:e821c773d5f0
Parent:
0:998e2e00df0c
Child:
4:99a67256b765
add parse_request()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
komoritan 0:998e2e00df0c 1 #include "mbed.h"
komoritan 0:998e2e00df0c 2 #include "SNIC_WifiInterface.h"
komoritan 0:998e2e00df0c 3 #include "HTTPServer.h"
komoritan 0:998e2e00df0c 4
komoritan 0:998e2e00df0c 5 /**
komoritan 0:998e2e00df0c 6 * Wifi AP parameter
komoritan 0:998e2e00df0c 7 */
komoritan 0:998e2e00df0c 8
komoritan 0:998e2e00df0c 9 /* Set this */
yi 1:e821c773d5f0 10 //#define WIFI_SSID ""
yi 1:e821c773d5f0 11 //#define WIFI_SECUTIRY_KEY ""
yi 1:e821c773d5f0 12
yi 1:e821c773d5f0 13 /*
yi 1:e821c773d5f0 14 #define WIFI_SSID "2ndguests"
yi 1:e821c773d5f0 15 #define WIFI_SECUTIRY_KEY "Sepkddi0077"
yi 1:e821c773d5f0 16 #define WIFI_SECURITY_TYPE e_SEC_WPA2_AES
yi 1:e821c773d5f0 17 */
yi 1:e821c773d5f0 18
yi 1:e821c773d5f0 19 //#define WIFI_SSID "Team3_4"
yi 1:e821c773d5f0 20 #define WIFI_SSID "Team11_12"
yi 1:e821c773d5f0 21 #define WIFI_SECUTIRY_KEY "123456789"
yi 1:e821c773d5f0 22 #define WIFI_SECURITY_TYPE e_SEC_WPA2_AES
yi 1:e821c773d5f0 23
yi 1:e821c773d5f0 24
yi 1:e821c773d5f0 25
komoritan 0:998e2e00df0c 26 //#define WIFI_SECURITY_TYPE e_SEC_OPEN
komoritan 0:998e2e00df0c 27 //#define WIFI_SECURITY_TYPE e_SEC_WEP
komoritan 0:998e2e00df0c 28 //#define WIFI_SECURITY_TYPE e_SEC_WPA_TKIP
yi 1:e821c773d5f0 29 //#define WIFI_SECURITY_TYPE e_SEC_WPA2_AES
komoritan 0:998e2e00df0c 30 //#define WIFI_SECURITY_TYPE e_SEC_WPA2_MIXED
komoritan 0:998e2e00df0c 31
komoritan 0:998e2e00df0c 32
yi 1:e821c773d5f0 33 #define IP_ADDRESS "192.168.100.44"
komoritan 0:998e2e00df0c 34 #define NET_MASK "255.255.255.0"
komoritan 0:998e2e00df0c 35 #define DEFAULT_GATEWAY "192.168.0.1"
komoritan 0:998e2e00df0c 36 #define PORT_NUMBER 80
komoritan 0:998e2e00df0c 37
yi 1:e821c773d5f0 38 #define _DEBUG
komoritan 0:998e2e00df0c 39
komoritan 0:998e2e00df0c 40 Serial pc(USBTX, USBRX); // This is required when defined "_DEBUG"
komoritan 0:998e2e00df0c 41 /** Wi-Fi SNIC UART Interface*/
yi 1:e821c773d5f0 42 //C_SNIC_WifiInterface mSNICwifi( p13, p14, p12, p11, p20 );
yi 1:e821c773d5f0 43 C_SNIC_WifiInterface mSNICwifi( p9, p10, NC, NC, p30 );
komoritan 0:998e2e00df0c 44
komoritan 0:998e2e00df0c 45
komoritan 0:998e2e00df0c 46
komoritan 0:998e2e00df0c 47 void wifi_connect()
komoritan 0:998e2e00df0c 48 {
komoritan 0:998e2e00df0c 49 // Initialize Wi-Fi interface
komoritan 0:998e2e00df0c 50 if(mSNICwifi.init()!=0){
komoritan 0:998e2e00df0c 51 printf("Wi-Fi initial failed\r\n");
komoritan 0:998e2e00df0c 52 mbed_die();
komoritan 0:998e2e00df0c 53 }
komoritan 0:998e2e00df0c 54 wait(0.5);
komoritan 0:998e2e00df0c 55
komoritan 0:998e2e00df0c 56 if(mSNICwifi.disconnect()!= 0 )
komoritan 0:998e2e00df0c 57 {
komoritan 0:998e2e00df0c 58 printf("on the disconnect state\r\n");
komoritan 0:998e2e00df0c 59 mbed_die();
komoritan 0:998e2e00df0c 60 }
komoritan 0:998e2e00df0c 61 wait(0.3);
komoritan 0:998e2e00df0c 62
komoritan 0:998e2e00df0c 63 // Connect to AP
komoritan 0:998e2e00df0c 64 if(mSNICwifi.connect( WIFI_SSID,strlen(WIFI_SSID),
komoritan 0:998e2e00df0c 65 WIFI_SECURITY_TYPE,
komoritan 0:998e2e00df0c 66 WIFI_SECUTIRY_KEY,
komoritan 0:998e2e00df0c 67 strlen(WIFI_SECUTIRY_KEY))!=0)
komoritan 0:998e2e00df0c 68 {
komoritan 0:998e2e00df0c 69 printf("Connect AP is failed\r\n");
komoritan 0:998e2e00df0c 70 mbed_die();
komoritan 0:998e2e00df0c 71 }
komoritan 0:998e2e00df0c 72 wait(0.5);
komoritan 0:998e2e00df0c 73
komoritan 0:998e2e00df0c 74 int retIp = mSNICwifi.setIPConfig(false, IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY);
yi 1:e821c773d5f0 75
komoritan 0:998e2e00df0c 76 }
komoritan 0:998e2e00df0c 77
komoritan 0:998e2e00df0c 78
komoritan 0:998e2e00df0c 79 int main()
komoritan 0:998e2e00df0c 80 {
komoritan 0:998e2e00df0c 81 // for debug
komoritan 0:998e2e00df0c 82 pc.baud( 115200 );
komoritan 0:998e2e00df0c 83
komoritan 0:998e2e00df0c 84 wifi_connect();
yi 1:e821c773d5f0 85
komoritan 0:998e2e00df0c 86 HTTPServer srv;
komoritan 0:998e2e00df0c 87
komoritan 0:998e2e00df0c 88 pc.printf("server init.\r\n");
komoritan 0:998e2e00df0c 89 srv.init(PORT_NUMBER);
komoritan 0:998e2e00df0c 90
komoritan 0:998e2e00df0c 91 srv.add_request_handler("GET", new GetRequestHandler());
komoritan 0:998e2e00df0c 92 srv.add_request_handler("DELETE", new DeleteRequestHandler());
komoritan 0:998e2e00df0c 93 srv.add_request_handler("POST", new PostRequestHandler());
komoritan 0:998e2e00df0c 94
komoritan 0:998e2e00df0c 95 wait(1);
komoritan 0:998e2e00df0c 96 pc.printf("server running.\r\n");
komoritan 0:998e2e00df0c 97 srv.run();
komoritan 0:998e2e00df0c 98 }
yi 1:e821c773d5f0 99
yi 1:e821c773d5f0 100