目次

last update: 2024/05

RI600V4 (ITRON) RTOS用BSPパッケージ
第4章: TCP/IPネットワーク通信
評価ボード:RX72N Envision Kit




テストサンプル

Demo Sample Application Folder:

Application
 └ _Exclude
     ├ IP  ..... TCP/IPネットワーク通信機能のデモサンプル

emNet (IP/UDP/TCP/TELNET/TFTP/mDNS/VLAN)

Sample説明
IP_ACD_StartACD(Address Collision Detection)機能の動作を確認します
IP_AUTOIP_StartAutoIPプロトコールを使用してIPアドレスの自動設定を確認します
IP_DHCPServerDHCPサーバー機能の実装方法を示すデモサンプル
IP_DNSClientネットワークホスト名を IP アドレスに解決する方法を示します
IP_MDNS_ServerSamplemDNSサーバー機能の実装方法を示すデモサンプル
IP_NETBIOS_StartNETBIOS Nameサービスクライアント機能を確認します
IP_NonBlockingConnectTCPソケットをノンブロッキングモードで実装します
IP_NTPClientNTPクライアント機能の実装方法を示すデモサンプル
IP_PingネットワークPINGテストでICMPプロトコールの動作を確認します
IP_SendMailSMTPクライアント機能の実装方法を示すデモサンプル
IP_SHELL_StartTELNETサーバー(emNet Shellコンソール)を実装します
IP_SimpleServer簡単なTELNETサーバーを実装します
IP_SNMP_AGENT_StartSNMPエージェントの実装方法を示すデモサンプル
IP_SNTPClientSNTPクライアント機能を使用してNTPサーバーからタイムスタンプを取得します
IP_SpeedClient_TCPTCPデータパケットの送受信速度パフォーマンスを確認できるサンプルプログラム
IP_StartemNet TCP/IPスタックの基本的なスタートアップ手順を示すサンプル
IP_TCP_TasklessServer専用タスク無しで簡単なTELNETサーバー機能を実装します
IP_UDPDiscoverUDPポート経由でターゲットデバイスの情報を確認します
IP_VLAN_StartVLANインターフェースを実装します
IP_TFTPClientSampleTFTPクライアント機能の実装方法を示すデモサンプル
IP_TFTPServerSampleTFTPサーバー機能の実装方法を示すデモサンプル

emNet CoAP

Sample説明
IP_COAP_ClientSampleCoAPクライアントの実装方法を示すデモサンプル
IP_COAP_ServerSampleCoAPサーバーの実装方法を示すデモサンプル

emNet MQTT

Sample説明
IP_MQTT_CLIENT_PublisherMQTT クライアントパブリッシャーの実装方法を示すデモサンプル
IP_MQTT_CLIENT_PublisherSubscriber_2TasksMQTT クライアントサブスクライバとパブリッシャー機能を同時に動かします
IP_MQTT_CLIENT_SubscriberMQTT クライアントサブスクライバの実装方法を示すデモサンプル

emNet WebSocket

Sample説明
IP_WEBSOCKET_printf_Clientサーバーにタイムスタンプメッセージを発行する簡単なWEBSOCKETクライアントターミナル
IP_WEBSOCKET_printf_Serverクライアントからタイムスタンプメッセージを受信する簡単なWEBSOCKETサーバートターミナル

emNet FTP

Sample説明
IP_FTPClientSampleFTPクライアントのデモサンプル
IP_FTPServerSampleFTPサーバーのデモサンプル

関連設定ファイル:

BSP
 |- BSP_IP.c  ..................... LANドライバのボード依存の初期化設定ファイル
 |
 |- Setup
     |- IP_Config_RX72N_ETH.c  .... LANドライバインターフェース設定ファイル

Config
 |- IP_Conf.h  ............... emNet IPコンフィグレーション設定ファイル
 |- IP_COAP_Conf.h  .......... emNet CoAPコンフィグレーション設定ファイル
 |- IP_MQTT_CLIENT_Conf.h  ... emNet MQTTコンフィグレーション設定ファイル
 |- FTPC_Conf.h  ............. emNet FTPcコンフィグレーション設定ファイル
 |- SMTPC_Conf.h  ............ emNet SMTP Clientコンフィグレーション設定ファイル
 |- IP_FTP_SERVER_Conf.h  .... emNet FTP Serverコンフィグレーション設定ファイル
 |- IP_SNMP_AGENT_Conf.h  .... emNet SNMP Agentコンフィグレーション設定ファイル
 |
 |- IO
 |   |- IP_ConfigIO.c  ....... デバッグコンソールIOインターフェース設定ファイル
 |
 |- OS
 |   |- libRI600V4_OSLayer_RXv3_L.lib  ....... OSインターフェース設定ファイル
 |
 |- SYS   .................... SYS インターフェース設定(ソース・ヘッダ)

ビルド・動作確認方法

プロジェクト設定では「\Application\_Exclude\IP」フォルダはビルド対象外に設定しています。

「\_Exclude\IP」フォルダ下の動作確認を行うテストサンプルファイルをビルド対象設定の「\Application」フォルダ下にコピーします。
各テストアプリケーションの動作確認方法はテストサンプルアプリケーションのヘッダのコメント情報を参照ください。

テスト環境の設定:

評価ボードの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)

テストレポート(TCP/IP)

Sample: IP_Ping

Debug IO Console:

SEGGER Software Evaluation Sample
Eval Board: RX72N Envision Kit
Base: Renesas RI600V4 RTOS
------------------------------------------------
0:022 INIT: emNet init started. Version 3.52.0
0:024 *********************************************************************
0:026 *                        emNet Configuration                        *
0:028 *********************************************************************
0:030 * IP_DEBUG: 2
0:032 * Memory added: 40952 bytes
0:034 * Buffer configuration:
0:036 *   12 buffers of 256 bytes
0:038 *   10 buffers of 1516 bytes
0:040 * TCP Tx/Rx window size per socket: 11680/8760 bytes
0:042 * Number of interfaces added: 1
0:044 * Interface #0 configuration:
0:046 *   Type: ETH
0:048 *   MTU: 1500
0:050 *   HW addr.: 00:22:C7:FF:FF:FF
0:052 *   IPv4 static addr.: 192.168.0.4
0:054 *   IPv4 default gateway addr.: 192.168.0.11
0:056 *   IPv4 DNS server #0: 192.168.0.11
0:058 *********************************************************************
0:062 INIT: Link is down
0:064 DRIVER: Found PHY with Id 0x22 at addr 0x1
0:136 INIT: Init completed
0:138 INIT: IP_Task started
2:136 LINK: Link state changed: Full duplex, 100MHz
2:525 NDP: Link-local IPv6 addr.: FE80:0000:0000:0000:0222:C7FF:FEFF:FFFF added to IFace: 0
7:189 Sending PING to IP addr 192.168.0.11
7:191 ICMP echo reply received!
8:191 Sending PING to IP addr 192.168.0.11
8:194 ICMP echo reply received!
9:193 Sending PING to IP addr 192.168.0.11
9:196 ICMP echo reply received!
10:195 Sending PING to IP addr 192.168.0.11
10:198 ICMP echo reply received!
11:197 Sending PING to IP addr 192.168.0.11
11:200 ICMP echo reply received!
12:199 Sending PING to IP addr 192.168.0.11
12:201 ICMP echo reply received!
13:201 Sending PING to IP addr 192.168.0.11
13:204 ICMP echo reply received!
14:203 Sending PING to IP addr 192.168.0.11
14:206 ICMP echo reply received!
15:205 Sending PING to IP addr 192.168.0.11
15:208 ICMP echo reply received!
16:207 Sending PING to IP addr 192.168.0.11
16:210 ICMP echo reply received!
17:209 Sending PING to IP addr 192.168.0.11
17:212 ICMP echo reply received!
18:211 Sending PING to IP addr 192.168.0.11
18:215 ICMP echo reply received!
19:213 Sending PING to IP addr 192.168.0.11
19:216 ICMP echo reply received!
20:215 Sending PING to IP addr 192.168.0.11
20:218 ICMP echo reply received!
21:217 Sending PING to IP addr 192.168.0.11
21:220 ICMP echo reply received!
22:219 Sending PING to IP addr 192.168.0.11
22:222 ICMP echo reply received!

Sample: IP_SpeedClient_TCP

パソコン側に「SpeedTestServer.exe」サーバープログラムを起動して評価ボードのTCP速度パフォーマンスを確認します。
LAN HUB: NETGEAR 100Mbps

File: IP_SpeedClient_TCP.c (サーバーIPアドレス設定)

#define   SERVER_IP_ADDR          IP_BYTES2ADDR(192, 168, 0, 11)

Debug IO Console:

SEGGER Software Evaluation Sample
Eval Board: RX72N Envision Kit
Base: Renesas RI600V4 RTOS
------------------------------------------------
0:022 INIT: emNet init started. Version 3.52.0
0:024 *********************************************************************
0:026 *                        emNet Configuration                        *
0:028 *********************************************************************
0:030 * IP_DEBUG: 2
0:032 * Memory added: 40952 bytes
0:034 * Buffer configuration:
0:036 *   12 buffers of 256 bytes
0:038 *   10 buffers of 1516 bytes
0:040 * TCP Tx/Rx window size per socket: 11680/8760 bytes
0:042 * Number of interfaces added: 1
0:044 * Interface #0 configuration:
0:046 *   Type: ETH
0:048 *   MTU: 1500
0:050 *   HW addr.: 00:22:C7:FF:FF:FF
0:052 *   IPv4 static addr.: 192.168.0.4
0:054 *   IPv4 default gateway addr.: 192.168.0.11
0:056 *   IPv4 DNS server #0: 192.168.0.11
0:058 *********************************************************************
0:062 INIT: Link is down
0:063 DRIVER: Found PHY with Id 0x22 at addr 0x1
0:152 INIT: Init completed
0:154 INIT: IP_Task started
3:153 LINK: Link state changed: Full duplex, 100MHz
3:524 NDP: Link-local IPv6 addr.: FE80:0000:0000:0000:0222:C7FF:FEFF:FFFF added to IFace: 0

4:542 4194304 Bytes sent (without headers) in 412 ms.
4:544 4349446 Bytes sent (with headers) in 412 ms.
4:546 Average transfer speed (without headers): 10180000 Bytes/s
4:548 Average transfer speed (with headers): 10556000 Bytes/s

4:985 4194304 Bytes received (without headers) in 384 ms.
4:987 4349446 Bytes received (with headers) in 384 ms.
4:989 Average transfer speed (without headers): 10922000 Bytes/s
4:991 Average transfer speed (with headers): 11326000 Bytes/s

5:403 4194304 Bytes sent (without headers) in 409 ms.
5:404 4349446 Bytes sent (with headers) in 409 ms.
5:406 Average transfer speed (without headers): 10255000 Bytes/s
5:408 Average transfer speed (with headers): 10634000 Bytes/s

5:846 4194304 Bytes received (without headers) in 385 ms.
5:848 4349446 Bytes received (with headers) in 385 ms.
5:850 Average transfer speed (without headers): 10894000 Bytes/s
5:851 Average transfer speed (with headers): 11297000 Bytes/s

6:288 4194304 Bytes sent (without headers) in 434 ms.
6:291 4349446 Bytes sent (with headers) in 434 ms.
6:292 Average transfer speed (without headers): 9664000 Bytes/s
6:294 Average transfer speed (with headers): 10021000 Bytes/s

6:729 4194304 Bytes received (without headers) in 382 ms.
6:730 4349446 Bytes received (with headers) in 382 ms.
6:732 Average transfer speed (without headers): 10979000 Bytes/s
6:734 Average transfer speed (with headers): 11385000 Bytes/s

7:145 4194304 Bytes sent (without headers) in 408 ms.
7:148 4349446 Bytes sent (with headers) in 408 ms.
7:149 Average transfer speed (without headers): 10280000 Bytes/s
7:151 Average transfer speed (with headers): 10660000 Bytes/s

7:621 4194304 Bytes received (without headers) in 417 ms.
7:623 4349446 Bytes received (with headers) in 417 ms.
7:625 Average transfer speed (without headers): 10058000 Bytes/s
7:627 Average transfer speed (with headers): 10430000 Bytes/s

8:034 4194304 Bytes sent (without headers) in 404 ms.
8:036 4349446 Bytes sent (with headers) in 404 ms.
8:038 Average transfer speed (without headers): 10381000 Bytes/s
8:040 Average transfer speed (with headers): 10765000 Bytes/s

8:465 4194304 Bytes received (without headers) in 372 ms.
8:467 4349446 Bytes received (with headers) in 372 ms.
8:469 Average transfer speed (without headers): 11275000 Bytes/s
8:471 Average transfer speed (with headers): 11692000 Bytes/s

8:875 4194304 Bytes sent (without headers) in 400 ms.
8:876 4349446 Bytes sent (with headers) in 400 ms.
8:878 Average transfer speed (without headers): 10485000 Bytes/s
8:880 Average transfer speed (with headers): 10873000 Bytes/s

9:304 4194304 Bytes received (without headers) in 371 ms.
9:306 4349446 Bytes received (with headers) in 371 ms.
9:308 Average transfer speed (without headers): 11305000 Bytes/s
9:310 Average transfer speed (with headers): 11723000 Bytes/s

9:713 4194304 Bytes sent (without headers) in 399 ms.
9:715 4349446 Bytes sent (with headers) in 399 ms.
9:717 Average transfer speed (without headers): 10512000 Bytes/s
9:719 Average transfer speed (with headers): 10900000 Bytes/s

10:143 4194304 Bytes received (without headers) in 372 ms.
10:145 4349446 Bytes received (with headers) in 372 ms.
10:147 Average transfer speed (without headers): 11275000 Bytes/s
10:149 Average transfer speed (with headers): 11692000 Bytes/s

10:559 4194304 Bytes sent (without headers) in 406 ms.
10:561 4349446 Bytes sent (with headers) in 406 ms.
10:563 Average transfer speed (without headers): 10330000 Bytes/s
10:565 Average transfer speed (with headers): 10712000 Bytes/s

10:991 4194304 Bytes received (without headers) in 373 ms.
10:993 4349446 Bytes received (with headers) in 373 ms.
10:996 Average transfer speed (without headers): 11244000 Bytes/s
10:998 Average transfer speed (with headers): 11660000 Bytes/s

Sample: IP_SNTPClient

Debug IO Console:

4:026 DHCPc: Sending Request.
4:032 DHCPc: IFace 0: Using IP: 192.168.0.4, Mask: 255.255.255.0, GW: 192.168.0.1.
4:048 Requesting time stamp from us.pool.ntp.org:
4:333 Timestamp received: 3923776523 seconds passed since January 1st 1900.
9:474 Timestamp received: 3923776528 seconds passed since January 1st 1900.
14:615 Timestamp received: 3923776533 seconds passed since January 1st 1900.
19:756 Timestamp received: 3923776538 seconds passed since January 1st 1900.
24:897 Timestamp received: 3923776544 seconds passed since January 1st 1900.

Sample: IP_NTPClient

Debug IO Console:

4:025 DHCPc: Sending Request.
4:031 DHCPc: IFace 0: Using IP: 192.168.0.4, Mask: 255.255.255.0, GW: 192.168.0.1.
9:053 --- UTC time: 2024.05.04  02:00:05 ---
14:048 --- UTC time: 2024.05.04  02:00:10 ---
19:054 --- UTC time: 2024.05.04  02:00:15 ---
24:049 --- UTC time: 2024.05.04  02:00:20 ---
29:055 --- UTC time: 2024.05.04  02:00:25 ---
34:050 --- UTC time: 2024.05.04  02:00:30 ---
39:056 --- UTC time: 2024.05.04  02:00:35 ---
44:051 --- UTC time: 2024.05.04  02:00:40 ---
49:057 --- UTC time: 2024.05.04  02:00:45 ---
54:052 --- UTC time: 2024.05.04  02:00:50 ---
59:058 --- UTC time: 2024.05.04  02:00:55 ---

テストレポート(MQTT)

Sample: IP_MQTT_CLIENT_Publisher

Debug IO Console:

3:025 DHCPc: Sending Request.
3:030 DHCPc: IFace 0: Using IP: 192.168.0.4, Mask: 255.255.255.0, GW: 192.168.0.1.
3:575 APP: Connected to 91.121.93.94, port 1883.
4:380 APP: --------
4:381 APP: Message No. 1:
4:383 APP:   Topic  : "eMQTT"
4:385 APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
5:884 APP: --------
5:885 APP: Message No. 2:
5:887 APP:   Topic  : "eMQTT"
5:889 APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
7:383 APP: --------
7:385 APP: Message No. 3:
7:387 APP:   Topic  : "eMQTT"
7:389 APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
8:884 APP: --------
8:885 APP: Message No. 4:
8:887 APP:   Topic  : "eMQTT"
8:889 APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"
10:422 APP: --------
10:424 APP: Message No. 5:
10:426 APP:   Topic  : "eMQTT"
10:428 APP:   Payload: "www.SEGGER.com MQTT_HelloWorld_Sample"

Sample: IP_MQTT_CLIENT_Subscriber

Debug IO Console:

3:025 DHCPc: Sending Request.
3:031 DHCPc: IFace 0: Using IP: 192.168.0.4, Mask: 255.255.255.0, GW: 192.168.0.1.
3:326 APP: Connected to 91.121.93.94, port 1883.
3:574 APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0.
3:576 APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0.
3:824 APP: Message (Type: SUBACK, Id: 3578) received. Reason Code: IP_MQTT_REASON_SUCCESS.
3:826 APP: ----
3:828 APP: IN: Message with (Id: 0 | QoS: 0 | Retain: 1 | Duplicate: 0) received for topic "eMQTT"
3:830 APP: IN:   Payload: "Client eMQTT client has disconnected ungracefully"
3:832 APP: ----
94:120 IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer.
94:122 _Disconnect: closing socket 1
94:124 APP: Done.
99:376 APP: Connected to 91.121.93.94, port 1883.
99:625 APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0.
99:627 APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0.
99:876 APP: Message (Type: SUBACK, Id: 34093) received. Reason Code: IP_MQTT_REASON_SUCCESS.
99:878 APP: ----
99:880 APP: IN: Message with (Id: 0 | QoS: 0 | Retain: 1 | Duplicate: 0) received for topic "eMQTT"
99:882 APP: IN:   Payload: "Client eMQTT client has disconnected ungracefully"
99:884 APP: ----
190:052 IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer.
190:054 _Disconnect: closing socket 2
190:056 APP: Done.
195:734 APP: Connected to 91.121.93.94, port 1883.
195:990 APP: Received Property IP_MQTT_PROP_TYPE_TOPIC_ALIAS_MAXIMUM for CONNACK with PacketID 0.
195:992 APP: Received Property IP_MQTT_PROP_TYPE_RECEIVE_MAXIMUM for CONNACK with PacketID 0.
196:245 APP: Message (Type: SUBACK, Id: 64922) received. Reason Code: IP_MQTT_REASON_SUCCESS.
196:247 APP: ----
196:250 APP: IN: Message with (Id: 0 | QoS: 0 | Retain: 1 | Duplicate: 0) received for topic "eMQTT"
196:252 APP: IN:   Payload: "Client eMQTT client has disconnected ungracefully"
196:254 APP: ----
286:960 IP_MQTT_CLIENT_Exec: Connection gracefully closed by peer.
286:963 _Disconnect: closing socket 3
286:965 APP: Done.

テストレポート(CoAP)

Sample: IP_COAP_ClientSample

File: IP_COAP_ClientSample.c (サーバーIPアドレス設定)

#define COAP_PORT     IP_COAP_DEFAULT_PORT
#define COAP_SERVER   "192.168.1.19"

Debug IO Console:

6:026 DHCPc: Sending Request.
6:036 DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
6:087 
Test 0: Sending PING
6:088 Test 0: Success!
6:090 
Test 1: Sending Discover
6:100 /obs: Simple observable data.
/test: test entry
/separate: simple variable with GET with LATE reply
/BlockTransfer/ObsData: Observable data block.
/ObsSensor: 
6:102 Test 1: Success!
6:104 
Test 2: Sending GET separate
6:106 
  00:00:00
6:108 Test 2: Success!
6:110 
Test 3: Sending NON GET block of 16 bytes
6:177 
  Test data
6:179 Test 3: Success!
6:181 
Test 4: PUT test
6:183 Test 4: Success!
6:186 
Test 5: PUT that should fail
6:187 received error: 4.05
6:189 Test 5: Success!
6:191 
Test 6: DELETE test
6:193 Test 6: Success!
6:195 
Test 7: POST test
6:198 Test 7: Success!
6:199 
Test 8: Observe
6:201 
  Obs data
6:203 
  GET 1 from Observe completed
16:197 
  Obs data
16:200 
  GET 2 from Observe completed
26:197 
  Obs data
26:198 
  GET 3 from Observe completed
36:194 
  Obs data
36:196 
  GET 4 from Observe completed
46:193 
  Obs data
46:195 
  GET 5 from Observe completed
46:197 Test 8: Success!

Sample: IP_COAP_ServerSample

Debug IO Console:

5:026 DHCPc: Sending Request.
5:036 DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
26:893 Getting with LATE reply.
26:897 Getting with LATE reply.
26:899 Getting Test.
26:901 Putting Test.
26:903 Putting Test.
26:906 Deleting Test.
26:909 Putting Test.
26:910 Putting Test.
26:913 Getting Observer.
36:915 Getting Observer.
46:917 Getting Observer.
56:919 Getting Observer.
66:921 Getting Observer.
66:923 Getting Observer.

テストレポート(WebSocket)

Sample: IP_WEBSOCKET_printf_Client

File: IP_WEBSOCKET_printf_Client.c (サーバーIPアドレス設定)

//
// WebSocket sample configuration.
//
#define SERVER_HOST      "192.168.1.19"   // Host to connect to.

Debug IO Console:

4:026 DHCPc: Sending Request.
4:065 DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
4:087 APP: Connected to 192.168.1.19:8181.

4:089 WebSocket successfully opened.

Sample: IP_WEBSOCKET_printf_Server

Debug IO Console:

5:026 DHCPc: Sending Request.
5:046 DHCPc: IFace 0: Using IP: 192.168.1.12, Mask: 255.255.255.0, GW: 192.168.1.1.
29:182 WebSocket client connected.

30:179 Client: OS time: 6025

31:378 Client: OS time: 7227

32:578 Client: OS time: 8430

33:778 Client: OS time: 9633

34:978 Client: OS time: 10836

36:179 Client: OS time: 12039

37:379 Client: OS time: 13242

38:579 Client: OS time: 14444

39:790 Client: OS time: 15658
前の章

MODBUS通信(TCP経由)

次の章

HTTPクライアント、JSONパーサー