Web Camera for mbed-os. When you use this program, we judge you have agreed to the following contents. https://developer.mbed.org/teams/Renesas/wiki/About-LICENSE
Dependencies: HttpServer_snapshot_mbed-os LWIPBP3595Interface_STA_for_mbed-os RomRamBlockDevice mbed-rpc
Fork of GR-Boards_WebCamera by
このサンプルは 「GR-LYCHEE」ではじめる電子工作 で紹介しています。
出版時と内容が異ならないよう、各ライブラリはアップデートせずに使用してください。
このサンプルの最新バージョンは下記から入手できます。最新バージョンは本の内容と一部処理が異なります。
https://github.com/d-kato/GR-Boards_WebCamera
Diff: main.cpp
- Revision:
- 17:2648bcf3f2cc
- Parent:
- 16:b5469a6226c7
- Child:
- 18:0461a79ced71
diff -r b5469a6226c7 -r 2648bcf3f2cc main.cpp --- a/main.cpp Thu Jun 02 05:39:35 2016 +0000 +++ b/main.cpp Fri Oct 28 06:33:08 2016 +0000 @@ -24,9 +24,10 @@ #endif #define NETWORK_TYPE (0) /* Select 0(EthernetInterface) or 1(GR_PEACH_WlanBP3595) */ #if (NETWORK_TYPE == 1) + #define SCAN_NETWORK (1) /* Select 0(Use WLAN_SSID, WLAN_PSK, WLAN_SECURITY) or 1(To select a network using the terminal.) */ #define WLAN_SSID ("SSIDofYourAP") /* SSID */ #define WLAN_PSK ("PSKofYourAP") /* PSK(Pre-Shared Key) */ - #define WLAN_SECURITY NSAPI_SECURITY_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA or NSAPI_SECURITY_WPA2 */ + #define WLAN_SECURITY NSAPI_SECURITY_WPA_WPA2 /* NSAPI_SECURITY_NONE, NSAPI_SECURITY_WEP, NSAPI_SECURITY_WPA, NSAPI_SECURITY_WPA2 or NSAPI_SECURITY_WPA_WPA2 */ #endif /** Camera setting **/ #define VIDEO_INPUT_METHOD (VIDEO_CMOS_CAMERA) /* Select VIDEO_CVBS or VIDEO_CMOS_CAMERA */ @@ -61,13 +62,14 @@ #include "EthernetInterface.h" EthernetInterface network; #elif (NETWORK_TYPE == 1) - #include "GR_PEACH_WlanBP3595.h" - GR_PEACH_WlanBP3595 network; + #include "LWIPBP3595Interface.h" + LWIPBP3595Interface network; DigitalOut usb1en(P3_8); #else #error NETWORK_TYPE error #endif /* NETWORK_TYPE */ RomRamFileSystem romramfs("romram"); +Serial pc(USBTX, USBRX); #if defined(__ICCARM__) #pragma data_alignment=16 @@ -382,6 +384,92 @@ } } +#if (SCAN_NETWORK == 1) +static void scan_network(void) { + int num; + int i; + int select_no; + bool loop_break; + char ch; + char pass[64]; + const uint8_t *wk_p; + WiFiAccessPoint point[8]; + + while (1) { + printf("scan...\n"); + num = network.scan(point, 8); + for (i = 0; i < num; i++) { + printf(" No.%d\n", i); + printf(" ssid :%s\n", point[i].get_ssid()); + wk_p = point[i].get_bssid(); + printf(" bssid :0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x\n", + wk_p[0],wk_p[1],wk_p[2],wk_p[3],wk_p[4],wk_p[5]); + printf(" security:"); + switch (point[i].get_security()) { + case NSAPI_SECURITY_NONE: + printf("NONE\n"); + break; + case NSAPI_SECURITY_WPA: + printf("WPA\n"); + break; + case NSAPI_SECURITY_WPA2: + printf("WPA2\n"); + break; + case NSAPI_SECURITY_WPA_WPA2: + printf("WPA_WPA2\n"); + break; + case NSAPI_SECURITY_UNKNOWN: + default: + printf("UNKNOWN\n"); + break; + } + printf(" rssi :%d\n", point[i].get_rssi()); + printf(" channel :%d\n", point[i].get_channel()); + } + if (num > 0) { + printf("\nPlease enter the number of the network you want to connect.\n"); + printf("Enter key:[0]-[%d], (If inputting the other key, it's scanned again.)\n", num - 1); + ch = (uint8_t)pc.getc(); + select_no = ch - 0x30; + if ((select_no >= 0) && (select_no < num)) { + printf("[%s] is selected.\n", point[select_no].get_ssid()); + printf("Please enter the PSK.\n"); + loop_break = false; + i = 0; + while (loop_break == false) { + ch = (uint8_t)pc.getc(); + switch (ch) { + case 0x0D: + pass[i] = '\0'; + pc.puts("\r\n"); + loop_break = true; + break; + case 0x08: + if (i > 0) { + pc.puts("\b \b"); + i--; + } + break; + case 0x0A: + break; + default: + if ((i + 1) < sizeof(pass)) { + pass[i] = ch; + i++; + pc.putc(ch); + } + break; + } + } + printf("connecting...\n"); + network.set_credentials(point[select_no].get_ssid(), pass, point[select_no].get_security()); + break; + } + } + } +} +#endif + int main(void) { printf("********* PROGRAM START ***********\r\n"); @@ -407,26 +495,31 @@ #endif printf("Network Setting up...\r\n"); -#if (USE_DHCP == 1) - if (network.init() != 0) { //for DHCP Server -#else - if (network.init(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway) -#endif - printf("Network Initialize Error \r\n"); +#if (USE_DHCP == 0) + network.set_dhcp(false); + if (network.set_network(IP_ADDRESS, SUBNET_MASK, DEFAULT_GATEWAY) != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway) + printf("Network Set Network Error \r\n"); return -1; } -#if (NETWORK_TYPE == 0) - if (network.connect() != 0) { +#endif + +#if (NETWORK_TYPE == 1) +#if (SCAN_NETWORK == 1) + scan_network(); #else - if (network.connect(WLAN_SSID, WLAN_PSK, WLAN_SECURITY) != 0) { + network.set_credentials(WLAN_SSID, WLAN_PSK, WLAN_SECURITY); +#endif #endif + + if (network.connect() != 0) { printf("Network Connect Error \r\n"); return -1; } - printf("MAC Address is %s\r\n", network.getMACAddress()); - printf("IP Address is %s\r\n", network.getIPAddress()); - printf("NetMask is %s\r\n", network.getNetworkMask()); - printf("Gateway Address is %s\r\n", network.getGateway()); + + printf("MbsAC Address is %s\r\n", network.get_mac_address()); + printf("IP Address is %s\r\n", network.get_ip_address()); + printf("NetMask is %s\r\n", network.get_netmask()); + printf("Gateway Address is %s\r\n", network.get_gateway()); printf("Network Setup OK\r\n"); SnapshotHandler::attach_req(&snapshot_req); @@ -434,5 +527,5 @@ FSHandler::mount("/romram", "/"); HTTPServerAddHandler<FSHandler>("/"); HTTPServerAddHandler<RPCHandler>("/rpc"); - HTTPServerStart(80); + HTTPServerStart(&network, 80); }