esp-idf/examples/protocols/sockets/udp_client
Djordje Nedic facab8c5a7 tools: Increase the minimal supported CMake version to 3.16
This updates the minimal supported version of CMake to 3.16, which in turn enables us to use more CMake features and have a cleaner build system.
This is the version that provides most new features and also the one we use in our latest docker image for CI.
2022-06-01 06:35:02 +00:00
..
main Build & config: Remove leftover files from the unsupported "make" build system 2021-11-11 15:32:36 +01:00
CMakeLists.txt tools: Increase the minimal supported CMake version to 3.16 2022-06-01 06:35:02 +00:00
example_test.py Split example_tests with Example_WIFI tag group into Example_OTA and Example_Protocols 2021-04-15 04:00:06 +00:00
README.md example: Remove duplicate commands and invalid serial port information 2020-04-08 13:17:48 +02:00
sdkconfig.ci Whitespace: Automated whitespace fixes (large commit) 2020-11-11 07:36:35 +00:00

UDP Client example

(See the README.md file in the upper level 'examples' directory for more information about examples.)

The application creates UDP socket and sends message to the predefined port and IP address. After the server's reply, the application prints received reply as ASCII text, waits for 2 seconds and sends another message.

How to use example

In order to create UDP server that communicates with UDP Client example, choose one of the following options.

There are many host-side tools which can be used to interact with the UDP/TCP server/client. One command line tool is netcat which can send and receive many kinds of packets. Note: please replace 192.168.0.167 3333 with desired IPV4/IPV6 address (displayed in monitor console) and port number in the following commands.

In addition to those tools, simple Python scripts can be found under sockets/scripts directory. Every script is designed to interact with one of the examples.

Send UDP packet via netcat

echo "Hello from PC" | nc -w1 -u 192.168.0.167 3333

Receive UDP packet via netcat

echo "Hello from PC" | nc -w1 -u 192.168.0.167 3333

UDP server using netcat

nc -u -l 192.168.0.167 3333

Python scripts

Script example_test.py could be used as a counter part to the udp-client application, ip protocol name (IPv4 or IPv6) shall be stated as argument. Example:

python example_test.py IPv4

Note that this script is used in automated tests, as well, so the IDF test framework packages need to be imported; please add $IDF_PATH/tools/ci/python_packages to PYTHONPATH.

Hardware Required

This example can be run on any commonly available ESP32 development board.

Configure the project

idf.py menuconfig

Set following parameters under Example Configuration Options:

  • Set IP version of example to be IPV4 or IPV6.

  • Set IPV4 Address in case your chose IP version IPV4 above.

  • Set IPV6 Address in case your chose IP version IPV6 above.

  • Set Port number that represents remote port the example will send data and receive data from.

Configure Wi-Fi or Ethernet under "Example Connection Configuration" menu. See "Establishing Wi-Fi or Ethernet Connection" section in examples/protocols/README.md for more details.

Build and Flash

Build the project and flash it to the board, then run monitor tool to view serial output:

idf.py -p PORT flash monitor

(To exit the serial monitor, type Ctrl-].)

See the Getting Started Guide for full steps to configure and use ESP-IDF to build projects.

Troubleshooting

Start server first, to receive data sent from the client (application).