Main Content

WiFi TCP/IP Receive

Receive data over TCP/IP network from remote host on wireless network

Add-On Required: This feature requires the Simulink Support Package for Arduino Hardware add-on.

  • WiFi TCP/IP Receive block

Libraries:
Simulink Support Package for Arduino Hardware / WiFi

Description

The WiFi TCP/IP Receive block receives data from a remote host or other hardware over a wireless network. When you set Connection mode to Server, you must provide the Local IP port. The Local IP port acts as a listening port on the TCP/IP server. When you set Connection mode to Client, you must provide the Remote IP address and the Remote IP port of the TCP/IP server to receive data.

The block accepts data either in Blocking Mode or in Non-Blocking Mode. The block has two output ports, Data and Status. The Data port outputs requested data at each time step. The Status port indicates whether the new data at the specified time step is received.

You can run a Simulink® model containing WiFi TCP/IP Receive block in Connected IO mode on Arduino® boards.

Note

ESP32 and ESP8266 boards are not supported in Connected IO mode.

For more information about the fixed ports and the allocated pins for the block, see Pin Mapping for Arduino Timer Independent Blocks.

Note

If you are having trouble using TCP to communicate with a computer, antivirus or firewall software might be blocking TCP traffic. If so, configure the software to allow the traffic for a specific IP port number.

Supported Hardware

You can use the WiFi TCP/IP Receive block only with the following hardware:

  • ESP8266

  • WiFi Shield

  • MKR1000

  • MKR WIFI 1010

  • Nano 33 IoT

  • Arduino compatible ESP32 – WROOM board

  • Arduino compatible ESP32 – WROVER board

Limitations

  • When using ESP8266 hardware, a model can have only one WiFi TCP Receive, WiFi TCP Send, WiFi UDP Receive, or WiFi UDP Send block.

  • When using WiFi Shield, the Connection mode set for all the WiFi TCP Send blocks and WiFi TCP Receive blocks in a model must be same. The WiFi TCP blocks cannot act as servers and clients in a model simultaneously.

  • The maximum number of connections allowed for different ports on WiFi TCP Receive blocks and WiFi TCP Send blocks in a model is two for WiFi shield, seven for MKR1000, and one for ESP8266. If the model uses External mode over Wi-Fi® or includes a WiFi ThingSpeak Read block or WiFi ThingSpeak Write block, one TCP port is reserved for each from the maximum allowed connections.

Ports

Output

expand all

At each time step, the port outputs data as a vector of the size specified in the Data size (N) parameter. The data is received in little-endian format. To convert it to a big-endian format, do any of the following:

  • Place a Byte Reversal block immediately after the WiFi TCP/IP Receive block.

  • Apply the swapbytes function in a MATLAB Function block, and place the block immediately after the WiFi TCP/IP Receive block.

For more information, see Blocking Mode and Non-Blocking Mode.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | Boolean

At each time step, when the length of data received is greater than or equal to the length specified in the Data size (N) parameter, the port outputs 1. Otherwise, it outputs 0, indicating that no new data is received.

For more information, see Blocking Mode and Non-Blocking Mode.

Data Types: int8

Parameters

expand all

Main Tab

Set the block as a TCP/IP server or client.

When you set this parameter to Server, you must provide a Local IP port. The local port acts as the listening port on the TCP/IP server.

When you set this parameter to Client, you must provide a Remote IP address and the Remote IP port on the TCP/IP server from which you want to receive the data. Before you deploy a model that includes a client WiFi TCP/IP Receive block, ensure that the server is up and running.

This local port number acts as a listening port on the TCP/IP server. Match the local port number with the remote port number of the sending host.

Dependencies

This parameter appears only when you set the Connection mode parameter to Server.

Specify IP address of the server from which the data is received.

Dependencies

This parameter appears only when you set the Connection mode parameter to Client.

Specify port number on the server from which data is received.

Dependencies

This parameter appears only when you set the Connection mode to Client.

Specify the type of data the block receives from the sending host. The size of each element depends on its data type.

The number of bytes to receive at each time step.

The maximum number of bytes that can be received by this block at each time step is shown in the table.

Target Hardware

ESP8266

WiFi Shield

MKR1000

Maximum Number of Received Bytes

40641400

When you set this parameter to -1, Simulink determines the best sample time for the block based on the block context within the model. When the hardware is ESP8266, the minimum sample time allowed is 0.01 seconds. Otherwise, it is 0.000001 seconds (1 microsecond).

Advanced Tab
  • When you select this option, the read operation runs in Blocking Mode. The read operation is blocked while waiting for the requested data to be available. When waiting for the data, the Status port displays same values from the previous time step. When the data become available, the Data port outputs data bytes, and the Status port changes to 1.

    A task overrun occurs if the target hardware is still waiting for the data to be available when the next read operation is scheduled to begin.

    To fix overruns:

    • Increase the time step by using the Sample time parameter.

    • Reduce the length of data requested by using the Data size (N) parameter.

  • When you clear this option, the read operation runs in Non-Blocking Mode. When reading data, if data is not available, the Data port outputs data as a vector of the size specified in the Data size (N) parameter filled with zeros. The Status port outputs 0. In this mode, the block does not wait for the requested data to be available.

Specify the amount of time that the block waits for the data during each time step. If timeout occurs, the read operation is aborted.

Note

When simulating a model in External mode, we recommend you to specify Timeout in seconds less than 3 seconds.

Dependencies

This parameter appears only when you select the Wait until data received parameter.

More About

expand all

Version History

Introduced in R2014a