Skip to content

gdbdzgd/esp32-uart2udp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

README.md

中文

esp32-uart2udp

esp32-uart2udp is a project based on the ESP-IDF framework that implements bidirectional data forwarding between UART and UDP on ESP32 development boards. This project enables forwarding data received from UART interfaces to a specified UDP server and vice versa, making it suitable for scenarios requiring data communication between serial devices and networks.

Features

  • Bidirectional Data Forwarding: Supports data transmission from UART to UDP and from UDP to UART.
  • Multi-UART Support: Configurable to enable UART1 and/or UART2 (controlled via compilation options).
  • WiFi Connectivity: Uses STA mode to connect to a specified WiFi network.
  • mDNS Service Discovery: Built-in mDNS service for easy device discovery in the network.
  • Configurable Parameters: Customize WiFi information, UART baud rate, pins, etc., via the menu configuration tool.
  • Multi-Task Concurrency: Implements asynchronous communication based on FreeRTOS tasks and message buffers to ensure efficient data processing.

Hardware Requirements

  • ESP32 series development board (e.g., ESP32-WROOM-32, ESP32-C3, etc.)
  • External serial devices (such as sensors, MCUs) connected according to the configured UART pins.
  • Stable WiFi network environment.

Software Dependencies

  • ESP-IDF 5.0 or later (with version adaptation logic in the code).
  • mDNS component (espressif/mdns, version ^1.0.3).

Compilation and Flashing

1. Environment Setup

Ensure the ESP-IDF development environment is installed. Refer to the ESP-IDF Official Documentation for setup instructions.

2. Clone the Repository

git clone https://github.com/your-repo/esp32-uart2udp.git
cd esp32-uart2udp

3. Configure the Project

Use the ESP-IDF menu configuration tool to set parameters:

idf.py menuconfig

Key configuration items:

  • WiFi Configuration: Set WiFi SSID and password (Component config -> WiFi -> WiFi STA Settings).
  • UART Configuration:
    • Enable UART1 and/or UART2 (Component config -> UART Configuration).
    • Configure UART baud rate, TX/RX pins (e.g., UART1 BAUD RATE, UART1 TX GPIO, etc.).
  • mDNS Configuration: Set mDNS hostname (Component config -> mDNS -> Hostname).

4. Compile and Flash

# Compile the project
idf.py build

# Flash to the device (replace COMx with the actual port)
idf.py -p COMx flash

# View logs
idf.py -p COMx monitor

Workflow

  1. Initialization: On startup, initialize NVS, WiFi (STA mode), UART interfaces, and mDNS service.
  2. Task Creation:
    • udp_listener: Listens on the specified UDP port, receives data, and forwards it to the corresponding UART's transmit buffer.
    • udp_client: Reads data from the UART receive buffer and sends it to the specified UDP server.
    • uartX_rx: Reads data from the UART interface and writes it to the UART receive buffer (X is 1 or 2).
    • uartX_tx: Reads data from the UART transmit buffer and sends it via the UART interface (X is 1 or 2).
  3. Data Forwarding: Uses FreeRTOS message buffers for inter-task data transfer to ensure thread safety.

Configuration Instructions

Configuration Item Description Configuration Path
WiFi SSID Target WiFi name Component config -> WiFi -> SSID
WiFi Password Target WiFi password Component config -> WiFi -> Password
UART1 Enable Whether to enable UART1 interface Component config -> UART Configuration -> Enable UART1
UART1 Baud Rate UART1 communication baud rate (e.g., 115200) Component config -> UART Configuration -> UART1 BAUD RATE
UART1 TX/RX Pins UART1 transmit/receive pin numbers Component config -> UART Configuration -> UART1 TX GPIO / UART1 RX GPIO
mDNS Hostname mDNS hostname of the device in the network Component config -> mDNS -> Hostname

License

This project is open-source under the GNU General Public License v3.0. See the LICENSE file for details.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published