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

You are viewing an older revision! See the latest version

Homepage

Information

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

What is this ?

Web Camera sample program using GR-PEACH and Audio/Camera Shield. When you access GR-PEACH from a web browser, the following contents is indicated.

  • Camera input picture
  • Control screen of devices connected to the I2C bus
  • LED control screen

When importing this programming, please put a check in "Update all libraries to the latest version".
I consulted this about HTTPServer and RPC./users/yueee_yt/code/HttpServerSample/

Please refer to following link about Audio/Camera Shield.
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

Composition

GR-PEACH, Audio/Camera Shield, Camera, PC and ethernet cable.
/media/uploads/dkato/grpeachaudiocamera4_whiteback.jpg
MT9V111 is being used for a camera by this sample program. When using a camera besides MT9V111, please change the setting according to the used camera.

main.cpp (camera input config 1)

/**** User Selection *********/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
/*****************************/

main.cpp (camera input config 2)

    /* MT9V111 camera input config */
    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
    ext_in_config.cap_width      = 640;                                   /* Capture width  */
    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */


The IP address is acquired from DHCP Server by this sample program. When you'd like to use a static IP address, please change the below.

main.cpp (IP address config)

    printf("EthernetInterface Setting up...\r\n");
//    if (eth.init() != 0) {                             //for DHCP Server
    if (eth.init("192.168.0.2","255.255.255.0","192.168.0.3") != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
        printf("EthernetInterface Initialize Error \r\n");
        return -1;
    }


To specify MAC address, add fllowing function to main.cpp.

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}


How to use

  1. Please turn on the power to GR-PEACH and start terminal software.
  2. Please connect an ethernet cable and press the reset button of GR-PEACH.
  3. An IP address is output on terminal.
    The after explanation assumes an IP address "192.168.0.2".
  4. When "http://192.168.0.2/web_top.htm" is opened by a web browser, top screen is indicated.
    The configuration of the top screen is a menu screen on the left side, a description screen of the sample program on the right side.
    If you click on each menu on the left side of the screen, the screen along the menu is indicated on the right screen.
  5. When you click the "Web camera" in the menu screen, the pictures of a camera is indicated.
    It can be changed at a slider bar in "Wait time" at the timing of a renewal of a camera picture. (Defaults are 500ms.)
  6. When you click the "Setting by I2C" of the menu screen, the control screen of the device connected to the I2C bus is indicated.
    By sending a command of a format listed below("Format of the device set by I2C") in Direct input or File reference, data transmission and reception is possible with respect to devices connected to I2C_SDA and I2C_SCL terminals of I2C.
    (In this configuration, you can execute the camera settings such as white balance and automatic exposure with respect to Camera(MT9V111).)
    The communication log of transmission and reception by "Format of the device set by I2C" is displayed in the log window. Please use for the debug.
    Clear and save of the communication log is also available.
  7. When you click the "LED On/Off" of the menu screen, the LED control screen is indicated.
    Each switch switches the LED1 ~ LED3 of GR-PEACH to ON or OFF.
    Each switch indicates the current LED state. When the LED is On, the color of switch will change the LED color.
  8. When you click the "Top Page" of the menu screen, the top screen is indicated.


The Terminal indication when being a reset start.

********* PROGRAM START ***********
EthernetInterface Setting up...
IP Address is 192.168.0.2
NetMask is 255.255.255.0
Gateway Address is 192.168.0.3
Ethernet Setup OK




”Page Top” screen
/media/uploads/1050186/web_top2.jpg


”Web Camera” screen
/media/uploads/1050186/camera3.jpg


”Setting by I2C” screen
/media/uploads/1050186/setting_i2c3.jpg

Format of the device set by I2C

Method:I2C addr,data length,data1,data2,data3,...

The details of each parameter is shown below.
For specific settings, check on the specifications of the connected device, you must create a command along the format.

MethodPlease specify one of the following:
"Wr" ・・・ Write functions in I2C
"Rd" ・・・ Read functions in I2C
"WrNoP" ・・・ Write functions in I2C(No STOP condition)
"RdNoP" ・・・ Read functions in I2C(No STOP condition)
I2C addrSet the I2C address of device in hexadecimal.
Ex: If the address is 0x90, set the "90"
data lengthIf Method is "Wr" or "WrNoP", set write size(the size of the data portion) in hexadecimal.
Ex: If the write size is 2 byte(data1, data2), set the "02".
If Method is "Rd" or "RdNoP", set read size in hexadecimal.
Ex: If the read size is 10 byte, set the "0A".
dataIf Method is "Wr" or "WrNoP", set write data in 1 byte unit in hexadecimal.
Ex: If the write data is 0x01 0x02, set "01" in the data1 and "02" in the data2.
If Method is "Rd" or "RdNoP", this parameter is omitted.

An example of the format is shown below.

Wr:90,03,25,45,14

To the device of the I2C address 0x90, the data write of 3Byte(0x25 0x45 0x14)

Rd:90,02

To the device of the I2C address 0x90, the data read of 2Byte


Some of the camera settings commands for MT9V111 is shown below.
In the case of direct input, after writing the commands in a text box, press the "Send" button.
In the case of file reference, after selecting file in the "Choose a text file" button, press the "Send" button.
In MT9V111, the setting value is valid until you shut off the power supply disconnect the USB cable.



”LED On/Off” screen
/media/uploads/1050186/led2.jpg

Processing

  1. At the time of a reset start.
    1. Data for Web pages written on file_"table.h" is registered with FileSystem. ".htm" files and ".js" files are indicated on "file_table.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 accepts a picture acquisition order to SnapshotHandler, GR-PEACH changes 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 sends 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 accepts a control acquisition order to SnapshotHandler, GR-PEACH analyzes 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 executes 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 executes 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.)

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

      "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 executes the I2C communication. When you set the writing format to the command part of subsequent of "/run,", GR-PEACH executes 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 executes 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.)

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

      "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 accepts a control acquisition order to RPCHandler, GR-PEACH operates 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 accepts an information acquisition order to RPCHandler, GR-PEACH gets the current status of LED using mbed-rpc library, replies to a web browser.


File in the "file_table.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





概要

GR-PEACHとAudio/Camera Shieldを使ったWeb Cameraサンプルプログラムです。
WebブラウザからGR-PEACHにアクセスすると以下が表示されます。

  • Camera入力画像
  • I2Cバスに繋がっているデバイスの制御画面
  • LED操作画面

Importの際は"Update all libraries to the latest version"にチェックを入れてください。
HTTPServer、および、RPCについて、こちらを参考にさせていただきました。/users/yueee_yt/code/HttpServerSample/

Audio/Camera Shieldについては下記を参照ください。
https://developer.mbed.org/teams/Renesas/wiki/Audio_Camera-shield

構成

GR-PEACH、Audio/Camera Shield、Camera、PC、イーサーネットケーブル。
/media/uploads/dkato/grpeachaudiocamera4_whiteback.jpg
サンプルプログラムではCameraにMT9V111を使用しています。MT9V111以外のCameraを使用する際は使用するCameraにあわせて設定を変更して下さい。

main.cpp (camera input config 1)

/**** User Selection *********/
#define VIDEO_INPUT_METHOD     (VIDEO_CMOS_CAMERA) /* Select  VIDEO_CVBS or VIDEO_CMOS_CAMERA                       */
#define VIDEO_INPUT_FORMAT     (VIDEO_YCBCR422)    /* Select  VIDEO_YCBCR422 or VIDEO_RGB888 or VIDEO_RGB565        */
#define USE_VIDEO_CH           (0)                 /* Select  0 or 1            If selecting VIDEO_CMOS_CAMERA, should be 0.)               */
#define VIDEO_PAL              (0)                 /* Select  0(NTSC) or 1(PAL) If selecting VIDEO_CVBS, this parameter is not referenced.) */
/*****************************/

main.cpp (camera input config 2)

    /* MT9V111 camera input config */
    ext_in_config.inp_format     = DisplayBase::VIDEO_EXTIN_FORMAT_BT601; /* BT601 8bit YCbCr format */
    ext_in_config.inp_pxd_edge   = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing data          */
    ext_in_config.inp_vs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Vsync signals */
    ext_in_config.inp_hs_edge    = DisplayBase::EDGE_RISING;              /* Clock edge select for capturing Hsync signals */
    ext_in_config.inp_endian_on  = DisplayBase::OFF;                      /* External input bit endian change on/off       */
    ext_in_config.inp_swap_on    = DisplayBase::OFF;                      /* External input B/R signal swap on/off         */
    ext_in_config.inp_vs_inv     = DisplayBase::SIG_POL_NOT_INVERTED;     /* External input DV_VSYNC inversion control     */
    ext_in_config.inp_hs_inv     = DisplayBase::SIG_POL_INVERTED;         /* External input DV_HSYNC inversion control     */
    ext_in_config.inp_f525_625   = DisplayBase::EXTIN_LINE_525;           /* Number of lines for BT.656 external input */
    ext_in_config.inp_h_pos      = DisplayBase::EXTIN_H_POS_CRYCBY;       /* Y/Cb/Y/Cr data string start timing to Hsync reference */
    ext_in_config.cap_vs_pos     = 6;                                     /* Capture start position from Vsync */
    ext_in_config.cap_hs_pos     = 150;                                   /* Capture start position form Hsync */
    ext_in_config.cap_width      = 640;                                   /* Capture width  */
    ext_in_config.cap_height     = 468u;                                  /* Capture height Max 468[line]
                                                                             Due to CMOS(MT9V111) output signal timing and VDC5 specification */


サンプルプログラムではDHCP ServerからIPアドレスを取得します。固定IPアドレスを使用する場合は以下を変更してください。

main.cpp (IP address config)

    printf("EthernetInterface Setting up...\r\n");
//    if (eth.init() != 0) {                             //for DHCP Server
    if (eth.init("192.168.0.2","255.255.255.0","192.168.0.3") != 0) { //for Static IP Address (IPAddress, NetMasks, Gateway)
        printf("EthernetInterface Initialize Error \r\n");
        return -1;
    }


main.cppの最後にの下記のように関数を追加し、用意したMACアドレスを設定してください。

Specify MAC address

// set mac address
void mbed_mac_address(char *mac) {
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xF7;
    mac[3] = 0xF0;
    mac[4] = 0x00;
    mac[5] = 0x00;
}


使い方

  1. GR-PEACHに電源を入れ、Terminalソフトを立ち上げます。
  2. イーサーネットケーブルを接続し、GR-PEACHのリセットボタンを押します。
  3. Terminal上にIPアドレスが出力されます。
    以降は取得(設定)したIPアドレスが"192.168.0.2"として説明します。
  4. PCのWebブラウザで”http://192.168.0.2/web_top.htm”を開くと、トップ画面が表示されます。
    トップ画面は、左側にメニュー画面、右側にサンプルプログラムの説明画面という構成になっており、
    左画面の各メニューをクリックすると、メニューに沿った画面が右画面に表示されます。
  5. メニュー画面の”Web Camera”をクリックすると、Camera画像が表示されます。
    "Wait time"のスライダーバーでCamera画像の更新タイミングが変更できます。(初期値は500msです)
  6. メニュー画面の"Setting by I2C"をクリックすると、I2Cバスに繋がっているデバイスの制御画面が表示されます。
    直接入力(Direct input)欄又はファイル参照(File reference)欄にて、下記("I2Cによるデバイス設定のフォーマット")に記載されているフォーマットのコマンドを送信する事で、I2CのI2C_SDA,I2C_SCL端子に繋がっているデバイスに対して、データの送受信が可能です。
    (今回の構成ではCamera(MT9V111)に対して、ホワイトバランスや自動露出といったカメラ設定が行えます。)
    "I2Cによるデバイス設定のフォーマット"による送受信の通信ログは、ログウィンドウに表示されますので、デバッグ用にご利用下さい。
    通信ログのクリアと保存もできます。
  7. メニュー画面の"LED On/Off"をクリックすると、LED操作画面が表示されます。
    各スイッチはGR-PEACHのLED1~LED3をON/OFF切り替えます。
    スイッチはそれぞれGR-PEACHのLED1~LED3の現在の状態を表しており、ONにすると対応するLEDの色になります。
  8. メニュー画面の"Top Page"をクリックすると、 トップ画面が表示されます。


リセットスタート時のTerminal表示

********* PROGRAM START ***********
EthernetInterface Setting up...
IP Address is 192.168.0.2
NetMask is 255.255.255.0
Gateway Address is 192.168.0.3
Ethernet Setup OK



”Page Top”画面
/media/uploads/1050186/web_top2.jpg


”Web Camera”画面
/media/uploads/1050186/camera3.jpg


”Setting by I2C”画面
/media/uploads/1050186/setting_i2c3.jpg

I2Cによるデバイス設定のフォーマット

Method:I2C addr,data length,data1,data2,data3,...

各パラメータの詳細を以下に示します。
具体的な設定値については、接続先のデバイスの仕様をご確認のうえ、フォーマットに沿ってコマンドを作成して下さい。

Method以下のいづれかを指定して下さい
"Wr" ・・・ I2Cでの書き込み
"Rd" ・・・ I2Cでの読み出し
"WrNoP" ・・・ I2Cでの書き込み(STOPコンディション省略)
"RdNoP" ・・・ I2Cでの読み出し(STOPコンディション省略)
I2C addr接続先デバイスのI2Cアドレスを16進数で設定して下さい。
(例) アドレスが0x90の場合、"90"を設定
data lengthMethodが"Wr"又は"WrNoP"の場合、書き込むサイズ(data部分のサイズ)を16進数で設定して下さい。
(例) 書き込むサイズが2Byte(data1,data2)の場合、"02"を設定
Methodが"Rd"又は"RdNoP"の場合は読み取るサイズを16進数で設定して下さい。
(例) 読み取りサイズが10Byteの場合、"0A"を設定
dataMethodが"Wr"又は"WrNoP"の場合、書き込むデータを16進数で1Byte単位で設定して下さい。
(例) 書き込みデータが0x01,0x02の場合、data1に"01"、data2に"02"を設定
"Rd"又は"RdNoP"の場合は省略して下さい。

フォーマットの例を以下に示します。

Wr:90,03,25,45,14

I2Cアドレス0x90のデバイスに対して0x25 0x45 0x14の計3Byteのデータ書き込み

Rd:90,02

I2Cアドレス0x90のデバイスに対して2Byteのデータ読み出し


また、MT9V111用のカメラ設定コマンドをいくつか用意しました。
直接入力(Direct input)の場合は、テキストボックスにコマンドを書いた後、"Send"ボタンを押して下さい。
ファイル参照(File reference)の場合は、"Choose a text file"ボタンをクリックしてファイルを選択した後、"Send"ボタンを押して下さい。
MT9V111の場合、USBケーブルを抜き電源供給を遮断するまで設定値が有効になります。



”LED On/Off”画面
/media/uploads/1050186/led2.jpg

処理の流れ

  1. リセットスタート時
    1. "file_table.h"に書かれたWeb page用データをFileSystemに登録します。 "file_table.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はSnapshotHandlerへの画像取得要求を受けると、GR-PEACH_videoライブラリから取得したCamera画像をGraphicsFrameworkライブラリのJPEG ConverterにてJPEGに変換し、Webブラウザに応答します。
      GR-PEACHが送信する画像サイズは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は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はRPCHandlerへの操作要求を受けると、mbed-rpcライブラリを通してLEDのOn/Off操作を行います。
    4. その後、RPCHandlerへ "http://192.168.0.2/rpc/led1/read" などの情報取得要求が発生します。
    5. GR-PEACHはRPCHandlerへの情報取得要求を受けると、mbed-rpcライブラリを通してLEDの現在の状態を取得し、Webブラウザに応答します。


"file_table.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