主要内容

WiFi UDP Receive

R2026b

Receive data from UDP host on wireless network

  • WiFi UDP Receive block

Libraries:
Simulink Support Package for Arduino Hardware / WiFi

Description

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

The WiFi UDP Receive block receives data from a UDP host on a wireless network. At each sample time, the block outputs data as a vector of the size specified in the Data size (N) parameter. The block receives data on the port number specified in the Local IP Port parameter. Match the port number specified in the Local IP Port parameter with the remote port number on the sending host.

The block supports reception of both fixed and variable-length UDP packets. The block also supports blocking mode, allowing you to wait for incoming UDP data up to a specified timeout.

Note

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

You can run a model containing WiFi UDP Receive block in connected IO mode on Arduino® boards.

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

Supported Hardware

You can use the WiFi UDP Receive block only with the following hardware:

  • ESP8266

  • WiFi Shield

  • MKR1000

  • MKR WIFI 1010

  • Nano 33 IoT

  • ESP32–S3 series (Arduino compatible)

  • ESP32–WROOM (Arduino compatible)

  • ESP32–WROVER (Arduino compatible)

Limitations

  • When using ESP8266 hardware, a model can have only one of these blocks: WiFi TCP/IP Receive, WiFi TCP/IP Send, WiFi UDP Send, WiFi UDP Receive block.

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

Ports

Output

expand all

In fixed-length mode, the block outputs a vector of the size as you define in the Data size (N) parameter.

In the variable-length mode, the block outputs the received bytes up to Maximum data size and the Size port outputs the actual number of bytes the block receives.

The port receives the in the 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 UDP Receive block.

  • Apply the swapbytes function in a MATLAB Function block and place the block immediately after the WiFi UDP Receive block.

For more information, see Block Outputs for Fixed Length of Received Data.

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

At each sample time, the port outputs the number of bytes in the received data. For more information, see Block Outputs for Fixed Length of Received Data.

Data Types: uint16

The port outputs the status of the most recent receiver operation.

  • 1 — Packet received (both, blocking and non-blocking modes)

  • 0 — No packet available (non-blocking mode)

  • -1 — Timeout (blocking mode)

Data Types: int8

Parameters

expand all

Port number of the application on which you want to receive data.

Match the local port number with the remote port number on the sending host.

Type of the block receives from the sending host.

The size of each element depends on its data type.

Allow the block to process variable-length UDP data instead of a fixed-length payload. The block adjusts to the actual number of bytes available during the current read operation.

Enabling this parameter on the receiver side allows the block to output only the actual bytes in the UDP receiver packet.

To use variable-length UDP transmission and reception in a model, you must enable this parameter on both the WiFi UDP Receive and WiFi UDP Send blocks.

Number of bytes received at each sample time.

The maximum number of bytes the block receives at each sample time is shown in the table.

Target Hardware

ESP8266

WiFi Shield

Arduino On-board Wi-Fi Boards

Maximum Number of Received Bytes

40641400

Dependencies

  • To enable this parameter, clear Enable variable length data.

Maximum number of bytes the block stores and outputs in the variable-length mode.

For the variable-length mode, the incoming UDP packet may contain a different number of bytes at each time step. The block allocates a buffer of the size you specify in the Maximum data size (N) parameter. The Size port outputs the actual number of bytes received during that step up to the maximum data size limit.

Dependencies

  • To enable this parameter, select Enable variable length data.

Make the receiver operation block execution until at least one UDP message is available on the block input port or till the timeout elapses while waiting for a packet.

Time limit on how long the block must wait for data on the input port when blocking mode is enabled.

Dependencies

  • To enable this parameter, select Enable blocking mode.

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).

More About

expand all

Version History

Introduced in R2014a

expand all