目次

last update: 2024/04

FreeRTOS用BSPパッケージ
第7章: 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」フォルダはビルド対象外に設定しています。

「\_Exclude\IOT」フォルダ下の動作確認を行うテストサンプルファイルをビルド対象設定の「\Application」フォルダ下にコピーします。
各テストアプリケーションの動作確認方法はテストサンプルアプリケーションのヘッダのコメント情報を参照ください。プロジェクトを再ビルドし、評価ボードに接続してデバッグセッションを開始します。
デバッガのIOコンソールのログ画面から結果を確認します。

テスト環境の設定(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_GetRequest

File: IOT_HTTP_GetRequest.c (HOST設定)

void MainTask(void) {
      ....
  IOT_HTTP_AddHost   (&HTTP, "www.embitek.co.jp");
      ....

Debug IO Console:

5:024 IP_Task - DHCPc: Sending Request.
5:050 IP_Task - DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
Returned status code: 302

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://www.embitek.co.jp/">here</a>.</p>
</body></html>

STOP.

Sample: IOT_HTTP_RedirectRequest

Debug IO Console:

4:024 IP_Task - DHCPc: Sending Request.
4:033 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-04-03..
Current time is 11:19:39..
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 ファイルシステム