Fx0 hackathon team4

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServerSample by KDDI Fx0 hackathon

Committer:
yi
Date:
Sun Feb 15 03:38:17 2015 +0000
Revision:
5:70c9f6045f2d
Parent:
4:99a67256b765
Child:
9:01aa69185ed8
delete unnecessary code

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
komoritan 0:998e2e00df0c 24 //#define WIFI_SECURITY_TYPE e_SEC_OPEN
komoritan 0:998e2e00df0c 25 //#define WIFI_SECURITY_TYPE e_SEC_WEP
komoritan 0:998e2e00df0c 26 //#define WIFI_SECURITY_TYPE e_SEC_WPA_TKIP
yi 1:e821c773d5f0 27 //#define WIFI_SECURITY_TYPE e_SEC_WPA2_AES
komoritan 0:998e2e00df0c 28 //#define WIFI_SECURITY_TYPE e_SEC_WPA2_MIXED
komoritan 0:998e2e00df0c 29
komoritan 0:998e2e00df0c 30
yi 1:e821c773d5f0 31 #define IP_ADDRESS "192.168.100.44"
komoritan 0:998e2e00df0c 32 #define NET_MASK "255.255.255.0"
komoritan 0:998e2e00df0c 33 #define DEFAULT_GATEWAY "192.168.0.1"
komoritan 0:998e2e00df0c 34 #define PORT_NUMBER 80
komoritan 0:998e2e00df0c 35
yi 1:e821c773d5f0 36 #define _DEBUG
komoritan 0:998e2e00df0c 37
komoritan 0:998e2e00df0c 38 Serial pc(USBTX, USBRX); // This is required when defined "_DEBUG"
komoritan 0:998e2e00df0c 39 /** Wi-Fi SNIC UART Interface*/
yi 1:e821c773d5f0 40 //C_SNIC_WifiInterface mSNICwifi( p13, p14, p12, p11, p20 );
yi 1:e821c773d5f0 41 C_SNIC_WifiInterface mSNICwifi( p9, p10, NC, NC, p30 );
komoritan 0:998e2e00df0c 42
oks486 4:99a67256b765 43 // Left motor
oks486 4:99a67256b765 44 PwmOut mPwmMotorL(p23);
oks486 4:99a67256b765 45 DigitalOut mDoutMotorL1(p15);
oks486 4:99a67256b765 46 DigitalOut mDoutMotorL2(p16);
oks486 4:99a67256b765 47
oks486 4:99a67256b765 48 // Rigth motor
oks486 4:99a67256b765 49 PwmOut mPwmMotorR(p22);
oks486 4:99a67256b765 50 DigitalOut mDoutMotorR1(p18);
oks486 4:99a67256b765 51 DigitalOut mDoutMotorR2(p17);
oks486 4:99a67256b765 52
oks486 4:99a67256b765 53 // Tail motor
oks486 4:99a67256b765 54 PwmOut mPwmMotorTail(p21);
oks486 4:99a67256b765 55 DigitalOut mDoutMotorTail1(p19);
oks486 4:99a67256b765 56 DigitalOut mDoutMotorTail2(p20);
komoritan 0:998e2e00df0c 57
komoritan 0:998e2e00df0c 58
komoritan 0:998e2e00df0c 59 void wifi_connect()
komoritan 0:998e2e00df0c 60 {
komoritan 0:998e2e00df0c 61 // Initialize Wi-Fi interface
komoritan 0:998e2e00df0c 62 if(mSNICwifi.init()!=0){
komoritan 0:998e2e00df0c 63 printf("Wi-Fi initial failed\r\n");
komoritan 0:998e2e00df0c 64 mbed_die();
komoritan 0:998e2e00df0c 65 }
komoritan 0:998e2e00df0c 66 wait(0.5);
komoritan 0:998e2e00df0c 67
komoritan 0:998e2e00df0c 68 if(mSNICwifi.disconnect()!= 0 )
komoritan 0:998e2e00df0c 69 {
komoritan 0:998e2e00df0c 70 printf("on the disconnect state\r\n");
komoritan 0:998e2e00df0c 71 mbed_die();
komoritan 0:998e2e00df0c 72 }
komoritan 0:998e2e00df0c 73 wait(0.3);
komoritan 0:998e2e00df0c 74
komoritan 0:998e2e00df0c 75 // Connect to AP
komoritan 0:998e2e00df0c 76 if(mSNICwifi.connect( WIFI_SSID,strlen(WIFI_SSID),
komoritan 0:998e2e00df0c 77 WIFI_SECURITY_TYPE,
komoritan 0:998e2e00df0c 78 WIFI_SECUTIRY_KEY,
komoritan 0:998e2e00df0c 79 strlen(WIFI_SECUTIRY_KEY))!=0)
komoritan 0:998e2e00df0c 80 {
komoritan 0:998e2e00df0c 81 printf("Connect AP is failed\r\n");
komoritan 0:998e2e00df0c 82 mbed_die();
komoritan 0:998e2e00df0c 83 }
komoritan 0:998e2e00df0c 84 wait(0.5);
komoritan 0:998e2e00df0c 85
komoritan 0:998e2e00df0c 86 int retIp = mSNICwifi.setIPConfig(false, IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY);
yi 1:e821c773d5f0 87
komoritan 0:998e2e00df0c 88 }
komoritan 0:998e2e00df0c 89
komoritan 0:998e2e00df0c 90
komoritan 0:998e2e00df0c 91 int main()
komoritan 0:998e2e00df0c 92 {
komoritan 0:998e2e00df0c 93 // for debug
komoritan 0:998e2e00df0c 94 pc.baud( 115200 );
oks486 4:99a67256b765 95
oks486 4:99a67256b765 96 mPwmMotorL.period_ms(20);
oks486 4:99a67256b765 97 mPwmMotorR.period_ms(20);
oks486 4:99a67256b765 98 mPwmMotorTail.period_ms(20);
komoritan 0:998e2e00df0c 99
komoritan 0:998e2e00df0c 100 wifi_connect();
yi 1:e821c773d5f0 101
komoritan 0:998e2e00df0c 102 HTTPServer srv;
komoritan 0:998e2e00df0c 103
komoritan 0:998e2e00df0c 104 pc.printf("server init.\r\n");
komoritan 0:998e2e00df0c 105 srv.init(PORT_NUMBER);
komoritan 0:998e2e00df0c 106
komoritan 0:998e2e00df0c 107 wait(1);
komoritan 0:998e2e00df0c 108 pc.printf("server running.\r\n");
komoritan 0:998e2e00df0c 109 srv.run();
komoritan 0:998e2e00df0c 110 }
yi 1:e821c773d5f0 111
yi 1:e821c773d5f0 112