au wot hackathon0314 test program

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServer_team4 by y ishida

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "SNIC_WifiInterface.h"
00003 #include "HTTPServer.h"
00004 
00005 #include "control_motors.h"
00006 
00007 /**
00008  * Wifi AP parameter
00009  */
00010 
00011 /* Set this */ 
00012 #define WIFI_SSID           "KDDI_hackathon04"
00013 #define WIFI_SECUTIRY_KEY   "123456789"
00014 #define WIFI_SECURITY_TYPE  e_SEC_WPA2_AES
00015 //#define WIFI_SECURITY_TYPE  e_SEC_OPEN
00016 //#define WIFI_SECURITY_TYPE  e_SEC_WEP
00017 //#define WIFI_SECURITY_TYPE  e_SEC_WPA_TKIP
00018 //#define WIFI_SECURITY_TYPE  e_SEC_WPA2_AES
00019 //#define WIFI_SECURITY_TYPE  e_SEC_WPA2_MIXED
00020 
00021 #define IP_ADDRESS      "192.168.100.149"
00022 #define NET_MASK        "255.255.255.0"
00023 #define DEFAULT_GATEWAY "192.168.100.1"
00024 
00025 #define PORT_NUMBER     80
00026 
00027 #define _DEBUG
00028 
00029 Serial pc(USBTX, USBRX);    // This is required when defined "_DEBUG"
00030 
00031 Serial tocos(p13, p14);     // TOCOS TWE-Lite (Serial)
00032 
00033 /** Wi-Fi SNIC UART Interface*/
00034 C_SNIC_WifiInterface     mSNICwifi( p9, p10, NC, NC, p30 );
00035 
00036 // Left motor
00037 PwmOut mPwmMotorL(p23);
00038 DigitalOut mDoutMotorL1(p15);
00039 DigitalOut mDoutMotorL2(p16);
00040 
00041 // Rigth motor
00042 PwmOut mPwmMotorR(p22);
00043 DigitalOut mDoutMotorR1(p18);
00044 DigitalOut mDoutMotorR2(p17);
00045 
00046 // Tail motor
00047 PwmOut mPwmMotorTail(p21);
00048 DigitalOut mDoutMotorTail1(p19);
00049 DigitalOut mDoutMotorTail2(p20);
00050 
00051 
00052 void wifi_connect()
00053 {
00054     // Initialize Wi-Fi interface
00055     if(mSNICwifi.init()!=0){
00056         printf("Wi-Fi initial failed\r\n");
00057         mbed_die();
00058     }
00059     wait(0.5);
00060     
00061     if(mSNICwifi.disconnect()!= 0 )
00062     {
00063         printf("on the disconnect state\r\n");
00064         mbed_die();
00065     } 
00066     wait(0.3);
00067 
00068     // Connect to AP
00069     if(mSNICwifi.connect( WIFI_SSID,strlen(WIFI_SSID), 
00070                           WIFI_SECURITY_TYPE, 
00071                           WIFI_SECUTIRY_KEY, 
00072                           strlen(WIFI_SECUTIRY_KEY))!=0)
00073     {
00074         printf("Connect AP is failed\r\n");
00075         mbed_die();
00076     }
00077     wait(0.5);
00078     
00079     int retIp = mSNICwifi.setIPConfig(false, IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY);
00080     
00081     printf("IP_ADDRESS:%s, NET_MASK:%s, DEFAULT_GATEWAY:%s\r\n",IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY);
00082     
00083 }
00084 
00085 void uart_callback() {
00086     // Note: you need to actually read from the serial to clear the RX interrupt
00087     sprintf("%c\n", pc.getc());
00088     led2 = !led2;
00089 }
00090 
00091 int main()
00092 {
00093     // for debug
00094     pc.baud( 115200 );
00095 
00096     pc.printf("program start.\r\n");
00097     
00098     tocos.attach(&uart_callback);
00099     
00100     mPwmMotorL.period_ms(20);
00101     mPwmMotorR.period_ms(20);
00102     mPwmMotorTail.period_ms(20);
00103 
00104     wifi_connect();
00105 
00106     HTTPServer srv;
00107     
00108     pc.printf("server init.\r\n");
00109     srv.init(PORT_NUMBER);
00110     
00111     wait(1);
00112     pc.printf("server running.\r\n");
00113     srv.run();
00114 }