au wot hackathon0314 test program

Dependencies:   NySNICInterface mbed-rtos mbed

Fork of RESTServer_team4 by y ishida

Committer:
kanpapa
Date:
Sat Mar 14 10:58:45 2015 +0000
Revision:
10:1caf4a3ce823
Parent:
9:01aa69185ed8
beta version

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 */
kanpapa 10:1caf4a3ce823 12 #define WIFI_SSID "KDDI_hackathon04"
kanpapa 10:1caf4a3ce823 13 #define WIFI_SECUTIRY_KEY "123456789"
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
kanpapa 10:1caf4a3ce823 21 #define IP_ADDRESS "192.168.100.149"
kanpapa 10:1caf4a3ce823 22 #define NET_MASK "255.255.255.0"
kanpapa 10:1caf4a3ce823 23 #define DEFAULT_GATEWAY "192.168.100.1"
komoritan 0:998e2e00df0c 24
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"
kanpapa 10:1caf4a3ce823 30
kanpapa 10:1caf4a3ce823 31 Serial tocos(p13, p14); // TOCOS TWE-Lite (Serial)
kanpapa 10:1caf4a3ce823 32
komoritan 0:998e2e00df0c 33 /** Wi-Fi SNIC UART Interface*/
yi 1:e821c773d5f0 34 C_SNIC_WifiInterface mSNICwifi( p9, p10, NC, NC, p30 );
komoritan 0:998e2e00df0c 35
oks486 4:99a67256b765 36 // Left motor
oks486 4:99a67256b765 37 PwmOut mPwmMotorL(p23);
oks486 4:99a67256b765 38 DigitalOut mDoutMotorL1(p15);
oks486 4:99a67256b765 39 DigitalOut mDoutMotorL2(p16);
oks486 4:99a67256b765 40
oks486 4:99a67256b765 41 // Rigth motor
oks486 4:99a67256b765 42 PwmOut mPwmMotorR(p22);
oks486 4:99a67256b765 43 DigitalOut mDoutMotorR1(p18);
oks486 4:99a67256b765 44 DigitalOut mDoutMotorR2(p17);
oks486 4:99a67256b765 45
oks486 4:99a67256b765 46 // Tail motor
oks486 4:99a67256b765 47 PwmOut mPwmMotorTail(p21);
oks486 4:99a67256b765 48 DigitalOut mDoutMotorTail1(p19);
oks486 4:99a67256b765 49 DigitalOut mDoutMotorTail2(p20);
komoritan 0:998e2e00df0c 50
komoritan 0:998e2e00df0c 51
komoritan 0:998e2e00df0c 52 void wifi_connect()
komoritan 0:998e2e00df0c 53 {
komoritan 0:998e2e00df0c 54 // Initialize Wi-Fi interface
komoritan 0:998e2e00df0c 55 if(mSNICwifi.init()!=0){
komoritan 0:998e2e00df0c 56 printf("Wi-Fi initial failed\r\n");
komoritan 0:998e2e00df0c 57 mbed_die();
komoritan 0:998e2e00df0c 58 }
komoritan 0:998e2e00df0c 59 wait(0.5);
komoritan 0:998e2e00df0c 60
komoritan 0:998e2e00df0c 61 if(mSNICwifi.disconnect()!= 0 )
komoritan 0:998e2e00df0c 62 {
komoritan 0:998e2e00df0c 63 printf("on the disconnect state\r\n");
komoritan 0:998e2e00df0c 64 mbed_die();
komoritan 0:998e2e00df0c 65 }
komoritan 0:998e2e00df0c 66 wait(0.3);
komoritan 0:998e2e00df0c 67
komoritan 0:998e2e00df0c 68 // Connect to AP
komoritan 0:998e2e00df0c 69 if(mSNICwifi.connect( WIFI_SSID,strlen(WIFI_SSID),
komoritan 0:998e2e00df0c 70 WIFI_SECURITY_TYPE,
komoritan 0:998e2e00df0c 71 WIFI_SECUTIRY_KEY,
komoritan 0:998e2e00df0c 72 strlen(WIFI_SECUTIRY_KEY))!=0)
komoritan 0:998e2e00df0c 73 {
komoritan 0:998e2e00df0c 74 printf("Connect AP is failed\r\n");
komoritan 0:998e2e00df0c 75 mbed_die();
komoritan 0:998e2e00df0c 76 }
komoritan 0:998e2e00df0c 77 wait(0.5);
komoritan 0:998e2e00df0c 78
komoritan 0:998e2e00df0c 79 int retIp = mSNICwifi.setIPConfig(false, IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY);
yi 1:e821c773d5f0 80
kanpapa 10:1caf4a3ce823 81 printf("IP_ADDRESS:%s, NET_MASK:%s, DEFAULT_GATEWAY:%s\r\n",IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY);
kanpapa 10:1caf4a3ce823 82
komoritan 0:998e2e00df0c 83 }
komoritan 0:998e2e00df0c 84
kanpapa 10:1caf4a3ce823 85 void uart_callback() {
kanpapa 10:1caf4a3ce823 86 // Note: you need to actually read from the serial to clear the RX interrupt
kanpapa 10:1caf4a3ce823 87 sprintf("%c\n", pc.getc());
kanpapa 10:1caf4a3ce823 88 led2 = !led2;
kanpapa 10:1caf4a3ce823 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 );
kanpapa 10:1caf4a3ce823 95
kanpapa 10:1caf4a3ce823 96 pc.printf("program start.\r\n");
kanpapa 10:1caf4a3ce823 97
kanpapa 10:1caf4a3ce823 98 tocos.attach(&uart_callback);
oks486 4:99a67256b765 99
oks486 4:99a67256b765 100 mPwmMotorL.period_ms(20);
oks486 4:99a67256b765 101 mPwmMotorR.period_ms(20);
oks486 4:99a67256b765 102 mPwmMotorTail.period_ms(20);
komoritan 0:998e2e00df0c 103
komoritan 0:998e2e00df0c 104 wifi_connect();
yi 1:e821c773d5f0 105
komoritan 0:998e2e00df0c 106 HTTPServer srv;
komoritan 0:998e2e00df0c 107
komoritan 0:998e2e00df0c 108 pc.printf("server init.\r\n");
komoritan 0:998e2e00df0c 109 srv.init(PORT_NUMBER);
komoritan 0:998e2e00df0c 110
komoritan 0:998e2e00df0c 111 wait(1);
komoritan 0:998e2e00df0c 112 pc.printf("server running.\r\n");
komoritan 0:998e2e00df0c 113 srv.run();
kanpapa 10:1caf4a3ce823 114 }