各ピンへのread/writeを提供するサーバサンプル
Dependencies: NySNICInterface mbed-rtos mbed
main.cpp
00001 #include "mbed.h" 00002 #include "SNIC_WifiInterface.h" 00003 #include "HTTPServer.h" 00004 00005 /** 00006 * Wifi AP parameter 00007 */ 00008 00009 /* Set this */ 00010 #define WIFI_SSID "" 00011 #define WIFI_SECUTIRY_KEY "" 00012 //#define WIFI_SECURITY_TYPE e_SEC_OPEN 00013 //#define WIFI_SECURITY_TYPE e_SEC_WEP 00014 //#define WIFI_SECURITY_TYPE e_SEC_WPA_TKIP 00015 #define WIFI_SECURITY_TYPE e_SEC_WPA2_AES 00016 //#define WIFI_SECURITY_TYPE e_SEC_WPA2_MIXED 00017 //#define WIFI_SECURITY_TYPE e_SEC_WPA_AES 00018 00019 00020 #define IP_ADDRESS "192.168.0.44" 00021 #define NET_MASK "255.255.255.0" 00022 #define DEFAULT_GATEWAY "192.168.0.1" 00023 #define PORT_NUMBER 80 00024 00025 00026 Serial pc(USBTX, USBRX); // This is required when defined "_DEBUG" 00027 /** Wi-Fi SNIC UART Interface*/ 00028 C_SNIC_WifiInterface mSNICwifi( p13, p14, p12, p11, p20 ); 00029 00030 00031 00032 00033 void wifi_connect() 00034 { 00035 // Initialize Wi-Fi interface 00036 if(mSNICwifi.init()!=0){ 00037 printf("Wi-Fi initial failed\r\n"); 00038 mbed_die(); 00039 } 00040 wait(0.5); 00041 00042 if(mSNICwifi.disconnect()!= 0 ) 00043 { 00044 printf("on the disconnect state\r\n"); 00045 mbed_die(); 00046 } 00047 wait(0.3); 00048 00049 // Connect to AP 00050 if(mSNICwifi.connect( WIFI_SSID,strlen(WIFI_SSID), 00051 WIFI_SECURITY_TYPE, 00052 WIFI_SECUTIRY_KEY, 00053 strlen(WIFI_SECUTIRY_KEY))!=0) 00054 { 00055 printf("Connect AP is failed\r\n"); 00056 mbed_die(); 00057 } 00058 wait(0.5); 00059 00060 int retIp = mSNICwifi.setIPConfig(false, IP_ADDRESS, NET_MASK, DEFAULT_GATEWAY); 00061 } 00062 00063 00064 int main() 00065 { 00066 // for debug 00067 pc.baud( 115200 ); 00068 00069 wifi_connect(); 00070 00071 HTTPServer srv; 00072 00073 pc.printf("server init.\r\n"); 00074 srv.init(PORT_NUMBER); 00075 00076 srv.add_request_handler("GET", new GetRequestHandler()); 00077 srv.add_request_handler("DELETE", new DeleteRequestHandler()); 00078 srv.add_request_handler("POST", new PostRequestHandler()); 00079 00080 wait(1); 00081 pc.printf("server running.\r\n"); 00082 srv.run(); 00083 }
Generated on Sun Jul 17 2022 16:34:37 by 1.7.2