Fx0 hackathon team4

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServerSample by KDDI Fx0 hackathon

Committer:
yi
Date:
Sun Feb 15 13:18:24 2015 +0000
Revision:
9:01aa69185ed8
Parent:
5:70c9f6045f2d
fixed

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