The application introduced here is a basic one that sends strings from Nucleo (STM32), which is WiFi enabled with ESP32 and configured as a TCP server, to a terminal on a client PC or smartphone, but once you have a solid understanding and can use it, you can apply it in various ways.
Nucleo (STM32) and ESP32 use serial UART to send and receive data by AT commands, which are commonly used in serial USART.
The mode of the wireless module ESP32 should be set to the general STA (Station) mode to be assigned an IP address by the WiFi router at home or at work. Other modes include AP (access point) mode, in which the ESP32 itself is used as the parent device, so please try to implement this mode.
This example assumes that the WiFi router address of the DHCP server in the parent unit is "192.168.3.1" and the IP address assigned to ESP32 is "192.168.3.19." Please note that each environment is different.
Let's take a look at the program, which is configured using FreeRTOS. The main program flow is to set up each peripheral immediately after startup, and then configure WiFi settings. After that, the program is divided into two tasks, prvTask_data for creating data for the demonstration program and prvTask_monitor for monitoring the data.
The WiFi settings are summarized in the wifi_setting function, which generates a TCP server with port number 50000.
Data creation for the demonstration is done in the task prvTask_data, which adds data (data) every 20 ms. data is unsigned 8 bits and repeatedly returns to 0 when it exceeds 255.
The task prvTask_monitor for data monitor sends a 5-character transmission request command "AT+CIPSEND=0,5\r\n", which includes 2 newline codes, to send a 3-digit number. Insert a wait time. Numeric data is converted to 3-digit numbers (digit_conv function) and USART is sent as a character string.
The wait time to be inserted after the "AT+CIPSEND=0,5\r\n" request command depends on the baud rate of the UART communication. We have tried it and found that it worked properly if the baud rate was set to 25 ms or more at 9600 bps and 3 ms or more at 115200 bps. The reference program is for 9600 bps.
This is the basic configuration for WiFi-enabled string transmission. Once the TCP server is configured, the rest is as simple as serial communication. The communication protocol to realize the TCP server is built into the ESP32 firmware and only needs to be specified in the configuration code at the beginning.
To monitor the numbers sent from the TCP server side of Nucleo (STM32) on the client side, use a terminal application. Here we use TeraTerm as the terminal emulator on the PC; you should be able to connect by specifying the IP address and port.
The numbers sent from the Nucleo (STM32) side are updated every 0.5 seconds. Success is achieved if one cycle of numbers from 0 to 255 takes approximately 5 seconds.