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 Renesas

このサンプルは 「GR-LYCHEE」ではじめる電子工作 で紹介しています。
出版時と内容が異ならないよう、各ライブラリはアップデートせずに使用してください。

このサンプルの最新バージョンは下記から入手できます。最新バージョンは本の内容と一部処理が異なります。
https://github.com/d-kato/GR-Boards_WebCamera

Revision:
21:c7de71ccb5ca
Parent:
18:0461a79ced71
Child:
23:165d08a7e3db
diff -r 7b5753609952 -r c7de71ccb5ca main.cpp
--- a/main.cpp	Thu Feb 23 08:20:51 2017 +0000
+++ b/main.cpp	Tue May 16 04:44:07 2017 +0000
@@ -4,7 +4,8 @@
 #include "JPEG_Converter.h"
 #include "HTTPServer.h"
 #include "mbed_rpc.h"
-#include "RomRamFileSystem.h"
+#include "FATFileSystem.h"
+#include "RomRamBlockDevice.h"
 #include "file_table.h"        //Binary data of web pages
 #include "i2c_setting.h"
 
@@ -68,7 +69,8 @@
 #else
   #error NETWORK_TYPE error
 #endif /* NETWORK_TYPE */
-RomRamFileSystem romramfs("romram");
+FATFileSystem fs("storage");
+RomRamBlockDevice romram_bd(512000, 512);
 Serial pc(USBTX, USBRX);
 
 #if defined(__ICCARM__)
@@ -315,50 +317,52 @@
 static void mount_romramfs(void) {
     FILE * fp;
 
-    romramfs.format();
+    romram_bd.SetRomAddr(0x18000000, 0x1FFFFFFF);
+    fs.format(&romram_bd, 512);
+    fs.mount(&romram_bd);
 
     //index.htm
-    fp = fopen("/romram/index.htm", "w");
+    fp = fopen("/storage/index.htm", "w");
     fwrite(index_htm_tbl, sizeof(char), sizeof(index_htm_tbl), fp);
     fclose(fp);
 
     //camera.js
-    fp = fopen("/romram/camera.js", "w");
+    fp = fopen("/storage/camera.js", "w");
     fwrite(camaera_js_tbl, sizeof(char), sizeof(camaera_js_tbl), fp);
     fclose(fp);
 
     //camera.htm
-    fp = fopen("/romram/camera.htm", "w");
+    fp = fopen("/storage/camera.htm", "w");
     fwrite(camera_htm_tbl, sizeof(char), sizeof(camera_htm_tbl), fp);
     fclose(fp);
 
     //mbedrpc.js
-    fp = fopen("/romram/mbedrpc.js", "w");
+    fp = fopen("/storage/mbedrpc.js", "w");
     fwrite(mbedrpc_js_tbl, sizeof(char), sizeof(mbedrpc_js_tbl), fp);
     fclose(fp);
 
     //led.htm
-    fp = fopen("/romram/led.htm", "w");
+    fp = fopen("/storage/led.htm", "w");
     fwrite(led_htm_tbl, sizeof(char), sizeof(led_htm_tbl), fp);
     fclose(fp);
 
     //i2c_set.htm
-    fp = fopen("/romram/i2c_set.htm", "w");
+    fp = fopen("/storage/i2c_set.htm", "w");
     fwrite(i2c_set_htm_tbl, sizeof(char), sizeof(i2c_set_htm_tbl), fp);
     fclose(fp);
 
     //web_top.htm
-    fp = fopen("/romram/web_top.htm", "w");
+    fp = fopen("/storage/web_top.htm", "w");
     fwrite(web_top_htm_tbl, sizeof(char), sizeof(web_top_htm_tbl), fp);
     fclose(fp);
 
     //menu.htm
-    fp = fopen("/romram/menu.htm", "w");
+    fp = fopen("/storage/menu.htm", "w");
     fwrite(menu_htm_tbl, sizeof(char), sizeof(menu_htm_tbl), fp);
     fclose(fp);
 
     //window.htm
-    fp = fopen("/romram/window.htm", "w");
+    fp = fopen("/storage/window.htm", "w");
     fwrite(window_htm_tbl, sizeof(char), sizeof(window_htm_tbl), fp);
     fclose(fp);
 }
@@ -390,88 +394,88 @@
 }
 
 #if (SCAN_NETWORK == 1)
-static void scan_network(void) {
-    int num;
+static const char *sec2str(nsapi_security_t sec) {
+    switch (sec) {
+        case NSAPI_SECURITY_NONE:
+            return "None";
+        case NSAPI_SECURITY_WEP:
+            return "WEP";
+        case NSAPI_SECURITY_WPA:
+            return "WPA";
+        case NSAPI_SECURITY_WPA2:
+            return "WPA2";
+        case NSAPI_SECURITY_WPA_WPA2:
+            return "WPA/WPA2";
+        case NSAPI_SECURITY_UNKNOWN:
+        default:
+            return "Unknown";
+    }
+}
+
+static bool scan_network(WiFiInterface *wifi) {
+    WiFiAccessPoint *ap;
+    bool ret = false;
     int i;
-    int select_no;
-    bool loop_break;
-    char ch;
-    char pass[64];
-    const uint8_t *wk_p;
-    WiFiAccessPoint point[8];
+    int count = 8;    /* Limit number of network arbitrary to 8 */
+
+    printf("Scan:\r\n");
+    ap = new WiFiAccessPoint[count];
+    count = wifi->scan(ap, count);
+    for (i = 0; i < count; i++) {
+        printf("No.%d Network: %s secured: %s BSSID: %hhX:%hhX:%hhX:%hhx:%hhx:%hhx RSSI: %hhd Ch: %hhd\r\n", i, ap[i].get_ssid(),
+               sec2str(ap[i].get_security()), ap[i].get_bssid()[0], ap[i].get_bssid()[1], ap[i].get_bssid()[2],
+               ap[i].get_bssid()[3], ap[i].get_bssid()[4], ap[i].get_bssid()[5], ap[i].get_rssi(), ap[i].get_channel());
+    }
+    printf("%d networks available.\r\n", count);
 
-    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;
+    if (count > 0) {
+        char c;
+        char pass[64];
+        int select_no;
+        bool loop_break = false;;
+
+        printf("\nPlease enter the number of the network you want to connect.\r\n");
+        printf("Enter key:[0]-[%d], (If inputting the other key, it's scanned again.)\r\n", count - 1);
+        c = (uint8_t)pc.getc();
+        select_no = c - 0x30;
+        if ((select_no >= 0) && (select_no < count)) {
+            printf("[%s] is selected.\r\n", ap[select_no].get_ssid());
+            printf("Please enter the PSK.\r\n");
+            i = 0;
+            while (loop_break == false) {
+                c = (uint8_t)pc.getc();
+                switch (c) {
+                    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] = c;
+                            i++;
+                            pc.putc(c);
+                        }
+                        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;
-            }
+            printf("connecting...\r\n");
+            wifi->set_credentials(ap[select_no].get_ssid(), pass, ap[select_no].get_security());
+            ret = true;
         }
     }
+
+    delete[] ap;
+
+    return ret;
 }
 #endif
 
@@ -509,7 +513,7 @@
 #endif
 #if (NETWORK_TYPE == 1)
 #if (SCAN_NETWORK == 1)
-    scan_network();
+    while (!scan_network(&network));
 #else
     network.set_credentials(WLAN_SSID, WLAN_PSK, WLAN_SECURITY);
 #endif
@@ -526,7 +530,7 @@
 
     SnapshotHandler::attach_req(&snapshot_req);
     HTTPServerAddHandler<SnapshotHandler>("/camera"); //Camera
-    FSHandler::mount("/romram", "/");
+    FSHandler::mount("/storage", "/");
     HTTPServerAddHandler<FSHandler>("/");
     HTTPServerAddHandler<RPCHandler>("/rpc");
     HTTPServerStart(&network, 80);