Web Camera for mbed-os. This sample works on GR-LYCHEE besides GR-PEACH. 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

Processing

Table of Contents

  1. Processing
  2. 処理の流れ

Information

Japanese version is available in lower part of this page.
このページの後半に日本語版が用意されています.

Processing

  1. At the time of a reset start.
    1. Data for Web pages written on "file_table_xxxx.h" is registered with FileSystem. ".htm" files and ".js" files are indicated on "file_table_xxxx.h "as binary data.
    2. The merit of the picture is begun from a camera using GR-PEACH_video library.
    3. To allow LED operation and Terminal output from the Web browser, registration with the mbed-rpc library is done.
    4. EthernetInterface is started and an IP address is acquired from DHCP Server. (It's possible to set a static IP address.)
      The after explanation assumes an IP address "192.168.0.2".
    5. SnapshotHandler (for pictures), FSHandler (for Web page indication) and RPCHandler (for operation) are registered with HTTPServer.

  2. At the time of "Web Camera" click.
    1. "http://192.168.0.2/camera.htm" is opened.
    2. The function in the JavaScript "http://192.168.0.2/camera.js" is called, and a picture acquisition request to SnapshotHandler occurs periodically.
    3. When GR-PEACH or GR-LYCHEE accept a picture acquisition order to SnapshotHandler, GR-PEACH or GR-LYCHEE change the camera picture acquired from GR-PEACH_video library to JPEG in JPEG Converter in a GraphicsFramework library and replies to a web browser.
      The picture size GR-PEACH or GR-LYCHEE send is QVGA (320 x 240). Even biggest VGA (640 x 480) is expanded on the web browser.

  3. At the time of "Setting by I2C" click.
    1. "http://192.168.0.2/i2c_set.htm" is opened.
    2. When you push the "Send" button, the function in the JavaScript "http://192.168.0.2/camera.js" is called, and a control acquisition request to SnapshotHandler occurs periodically.
    3. When GR-PEACH or GR-LYCHEE accept a control acquisition order to SnapshotHandler, GR-PEACH or GR-LYCHEE analyze the command part and execute the I2C communication using the I2C driver.

      The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window.
      In the writing format, GR-PEACH or GR-LYCHEE execute data writing by the I2C communication and displays the results of writing on the log window. In success, it is "OK run". In failure, it is "NG run".
      In the reading format, GR-PEACH or GR-LYCHEE execute data reading by the I2C communication and displays the results of writing on the log window. In success, it is "OK XX,YY,... run". In failure, it is "NG run".
      (XX and YY are the read data in accordance with the specified size.)

      Example of "Write successful example" screen
      /media/uploads/1050186/i2c_log_write.jpg

      Example of "Read successful example(read data=2Byte)" screen
      /media/uploads/1050186/i2c_log_read.jpg

      Also when you connect the "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14", etc., GR-PEACH or GR-LYCHEE execute the I2C communication. When you set the writing format to the command part of subsequent of "/run,", GR-PEACH or GR-LYCHEE execute data writing by the I2C communication and displays the results of writing on the web browser. In success, it is "OK run". In failure, it is "NG run".
      When you set the reading format to the command part of subsequent of "/run,", GR-PEACH or GR-LYCHEE execute data reading by the I2C communication and displays the results of writing on the web browser. In success, it is "OK XX,YY,... run". In failure, it is "NG run".
      (XX and YY are the read data in accordance with the specified size.)

      Example of "Write successful example" screen
      /media/uploads/1050186/i2c_write2.jpg

      Example of "Read successful example(read data=2Byte)" screen
      /media/uploads/1050186/i2c_read2.jpg


  4. At the time of "LED On/Off" click.
    1. "http://192.168.0.2/led.htm" is opened.
    2. When you push each switch, the function in the JavaScript "http://192.168.0.2/mbedrpc.js" is called, and a control acquisition request of "http://192.168.0.2/rpc/led1/write 1" etc. occurs to RPCHandler.
    3. When GR-PEACH or GR-LYCHEE accept a control acquisition order to RPCHandler, GR-PEACH or GR-LYCHEE operate an LED using mbed-rpc library.
    4. Then, an information acquisition request of "http://192.168.0.2/rpc/led1/write 1" etc. occurs to RPCHandler.
    5. When GR-PEACH or GR-LYCHEE accept an information acquisition order to RPCHandler, GR-PEACH or GR-LYCHEE get the current status of LED using mbed-rpc library, replies to a web browser.


File in the "file_table_xxxx.h"

It's modified by making reference to something introduced here about the RPC function ("led.htm" and "mbedrpc.js").
/users/yueee_yt/code/HttpServerSample/


When you enable the following thread startup process and thread process, you can set the device in the I2C at Terminal via as well as via a Web browser.
Command to be sent is the same as at the time through a Web browser.

main.cpp

int main(void) {
    printf("********* PROGRAM START ***********\r\n");

    /* Please enable this line when performing the setting from the Terminal side. */
//    Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);


i2c_setting.cpp

#if(0) /* Please enable this line when performing the setting from the Terminal side. */
Serial terminal(USBTX, USBRX);
static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];

void SetI2CfromTerm(void const *argument) {
    ... Skip ...
}
#endif





処理の流れ

  1. リセットスタート時
    1. "file_table_xxxx.h"に書かれたWeb page用データをFileSystemに登録します。 "file_table_xxxx.h"には".htm"ファイルと".js"ファイルがバイナリデータとして記載されています。
    2. GR-PEACH_videoライブラリを用いてCameraからの画像取得を開始します。
    3. WebブラウザからI2Cでの設定、LED操作、及び、Terminal出力ができるように、mbed-rpcライブラリへの登録を行います。
    4. EthernetInterfaceを起動し、DHCP ServerからIPアドレスを取得します。(固定アドレスを設定することもできます)
      以降は取得(設定)したIPアドレスが"192.168.0.2"として説明します。
    5. HTTPServerにSnapshotHandler(画像用)、FSHandler(Webページ表示用)、RPCHandler(操作用)を登録します。

  2. "Web Camera"クリック時
    1. "http://192.168.0.2/camera.htm"が開きます。
    2. JavaScript "http://192.168.0.2/camera.js"内の関数が実行され、定期的にSnapshotHandlerへの画像取得要求が発生します。
    3. GR-PEACH or GR-LYCHEEはSnapshotHandlerへの画像取得要求を受けると、GR-PEACH_videoライブラリから取得したCamera画像をGraphicsFrameworkライブラリのJPEG ConverterにてJPEGに変換し、Webブラウザに応答します。
      GR-PEACH or GR-LYCHEEが送信する画像サイズはQVGA(320 x 240)です。Webブラウザ上で最大VGA(640 x 480)まで拡大されます。

  3. "Setting by I2C"クリック時
    1. "http://192.168.0.2/i2c_set.htm"が開きます。
    2. "Send"ボタンを押すと、JavaScript "http://192.168.0.2/mbedrpc.js"内の関数が実行され、RPCHandlerへ "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14" などの操作要求が発生します。
    3. GR-PEACH or GR-LYCHEEはRPCHandlerへの操作要求を受けると、"/run,"以降のコマンド部分の解析を行い、I2Cドライバを用いてI2C通信を行います。

      "I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されます。
      書き込みフォーマットの場合、I2C通信でデータ書き込みを行ない、ログウィンドウに書き込み結果を表示します。成功の場合は"OK run"、失敗の場合は"NG run"となります。
      読み出しフォーマットの場合、I2C通信でデータ読み出し行ない、ログウィンドウに読み出し結果と読み出したデータを表示します。成功の場合は"OK XX,YY,... run"、失敗の場合は"NG run"となります。
      (XXやYYは指定サイズに応じた読み出したデータです。)

      "書き込み成功例"画面の例
      /media/uploads/1050186/i2c_log_write.jpg

      "読み出し成功例(読み出しデータ=2Byte)"画面の例
      /media/uploads/1050186/i2c_log_read.jpg

      また、 "http://192.168.0.2/rpc/SetI2CfromWeb/run,Wr:90,03,25,45,14" などで直接接続した場合でも、上記同様のI2C通信を行います。 "/run,"以降のコマンド部分を書き込みフォーマットにすると、I2C通信でデータ書き込みを行ない、ブラウザ上に書き込み結果を表示します。成功の場合は"OK run"、失敗の場合は"NG run"となります。
      "/run,"以降のコマンド部分を読み出しフォーマットにすると、I2C通信でデータ読み出しを行ない、ブラウザ上に読み出し結果と読み出したデータを表示します。成功の場合は"OK XX,YY,... run"、失敗の場合は"NG run"となります。
      (XXやYYは指定サイズに応じた読み出したデータです。)

      "書き込み成功例"画面の例
      /media/uploads/1050186/i2c_write2.jpg

      "読み出し成功例(読み出しデータ=2Byte)"画面の例
      /media/uploads/1050186/i2c_read2.jpg

  4. "LED On/Off"クリック時
    1. "http://192.168.0.2/led.htm"が開きます。
    2. 各スイッチを操作すると、JavaScript "http://192.168.0.2/mbedrpc.js"内の関数が実行され、RPCHandlerへ "http://192.168.0.2/rpc/led1/write 1" などの操作要求が発生します。
    3. GR-PEACH or GR-LYCHEEはRPCHandlerへの操作要求を受けると、mbed-rpcライブラリを通してLEDのOn/Off操作を行います。
    4. その後、RPCHandlerへ "http://192.168.0.2/rpc/led1/read" などの情報取得要求が発生します。
    5. GR-PEACH or GR-LYCHEEはRPCHandlerへの情報取得要求を受けると、mbed-rpcライブラリを通してLEDの現在の状態を取得し、Webブラウザに応答します。


"file_table_xxxx.h"内のファイル

RPC機能("led.htm"、"mbedrpc.js")については、こちらで紹介されているものを参考に一部変更しています。
/users/yueee_yt/code/HttpServerSample/


なお、サンプルプログラムにて、以下のスレッド起動処理とスレッド処理を有効すると、 Webブラウザ経由と同様にTerminal経由でもI2Cでのデバイス設定ができます。
送信するコマンドはWebブラウザ経由時と同じです。

main.cpp

int main(void) {
    printf("********* PROGRAM START ***********\r\n");

    /* Please enable this line when performing the setting from the Terminal side. */
//    Thread thread(SetI2CfromTerm, NULL, osPriorityBelowNormal, DEFAULT_STACK_SIZE);


i2c_setting.cpp

#if(0) /* Please enable this line when performing the setting from the Terminal side. */
Serial terminal(USBTX, USBRX);
static char recv_term_buffer[I2C_SETTING_STR_BUF_SIZE];

void SetI2CfromTerm(void const *argument) {
    ... 省略 ...
}
#endif




All wikipages