目次

last update: 2024/04

embOS RTOS用BSPパッケージ
第8章: HTTPクライアント、JSONパーサー
評価ボード:Renesas RX72N Envision Kit




テストサンプル

Demo Sample Application Folder:

Application
 └ _Exclude
     ├ IOT  ..... HTTPクライアント、JSONパーサー機能のデモサンプル

HTTP Client Sample

Sample説明
IOT_HTTP_GetRequestHTTPクライアントのGETコマンドを実行して内容をコンソールに表示します
IOT_HTTP_RedirectRequestHTTPクライアントのGETコマンドを実行して、リダイレクトリクエストを処理します
IOT_HTTP_SecureGetHTTPクライアントのセキュアGETコマンドを実行して内容をコンソールに表示します

JSON Parser Sample

Sample説明
IOT_JSON_IncrementalParseサンプル JSON オブジェクトを文字ごとに解析して結果をコンソールに表示します
IOT_JSON_MakeTreeサンプル JSON オブジェクトを解析して結果をツリー形式で表示します
IOT_JSON_PlainTraceサンプル JSON オブジェクトを解析して結果をコンソールに表示します
IOT_JSON_PrettyTraceサンプル JSON オブジェクトを解析して結果をツリー形式で表示します

関連設定ファイル:

Config
 |- IOT_Conf.h  ............. コンフィグレーション設定ファイル 
 |
 |- IO
 |   |- IOT_ConfigIO.c  ..... デバッグコンソールIOインターフェース設定ファイル
 |
 |- SYS   ................... SYS インターフェース設定(ソース・ヘッダ)

ビルド・動作確認方法

プロジェクト設定では「\Application\_Exclude\IOT」フォルダはビルド対象外に設定しています。以下のどちらかの方法で動作確認を行うサンプルアプリケーションを選択します。

  1. 「\_Exclude\IOT」フォルダ下の対象テストサンプルファイルをビルド対象設定の「\Application」フォルダ下にコピーします。
  2. 「\_Exclude\IOT」フォルダ下の対象テストサンプルファイルのみ「ビルド対象外」の設定を解除します。

各テストアプリケーションの動作確認方法はテストサンプルアプリケーションのヘッダのコメント情報を参照ください。

テスト環境の設定(HTTP Client):

評価ボードのLANポートをテスト用パソコンに接続して、TCP/IPネットワーク通信が正常にできることを確認してください。

PC Setup

ネットワーク環境に合わせて評価ボード側のemNetスタックのコンフィグレーション設定を編集してください。

File: BSP\Setup\IP_Config_RX72N_ETH.c

#define USE_DHCP     1    // Use DHCP client or static IP configuration.

//
// The following parameters are only used when the DHCP client is not active.
//
#define IP_ADDR      IP_BYTES2ADDR(192, 168,  11,  8)
#define SUBNET_MASK  IP_BYTES2ADDR(255, 255, 255,  0)
#define GW_ADDR      IP_BYTES2ADDR(192, 168,  11,  1)
#define DNS_ADDR     IP_BYTES2ADDR(192, 168,  11,  1)

テストレポート(HTTP Client)

Sample: IOT_HTTP_RedirectRequest

Debug IO Console:

4:025 IP_Task - DHCPc: Sending Request.
4:035 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
Returned status code: 301

Redirect to https://www.segger.com/

Cannot handle scheme https!

STOP.

Sample: IOT_HTTP_SecureGet

Read HTTP contents from www.segger.com/emssl-testpage.php

Debug IO Console:

Sample Setup HOST = www.segger.com
             PATH = /emssl-testpage.php
-----------------------------
Connecting to HOST www.segger.com:80 !
Returned status code: 301

Redirect to https://www.segger.com/emssl-testpage.php

Connecting to HOST www.segger.com:443 !
Returned status code: 200

Welcome to www.segger.com/emssl-testpage.php!..
Successfully connected via SSL..
Current date is 2024-03-27..
Current time is 05:06:44..
STOP.

テストレポート(JSONパーサー)

IOT_JSON_IncrementalParse

Debug IO Console:

Begin object
Key = "name"
String = "My TV"
Key = "resolutions"
Begin array
Begin object
Key = "width"
Number = "1280"
Key = "height"
Number = "720"
End object
Begin object
Key = "width"
Number = "1920"
Key = "height"
Number = "1080"
End object
Begin object
Key = "width"
Number = "3840"
Key = "height"
Number = "2160"
End object
End array
End object

Parse OK

IOT_JSON_PrettyTrace

Debug IO Console:

Begin object
  Key = "name"
  String = "My TV"
  Key = "resolutions"
  Begin array
    Begin object
      Key = "width"
      Number = "1280"
      Key = "height"
      Number = "720"
    End object
    Begin object
      Key = "width"
      Number = "1920"
      Key = "height"
      Number = "1080"
    End object
    Begin object
      Key = "width"
      Number = "3840"
      Key = "height"
      Number = "2160"
    End object
  End array
End object

Parse OK
前の章

暗号・サイファーライブラリ

次の章

FAT32 ファイルシステム