Configure a TCP server and connect to it with a PC, smartphone, or other client terminal application. The same as "TCP communication(WiFi) transmission of STM32 with ESP32".
To control MCU by command codes from the client side, all you need to do is to process incoming character codes and add what you want to be processed according to the codes.
If you connect the ESP32 to the terminal app, type the 9 characters of "depfields" and press Enter, you have sent 11 characters, including the newline code. If the terminal is set to local echo, the characters you entered will appear.
On the TCP server side, when a character is received from the client side, the message "+IPD,0,11:depfields" is displayed. ＋The +IPD indicates incoming data, and the connection ID is 0, meaning that a total of 11 characters were received, including the string and newline code. The response string contains the line feed codes CR+LF.
The following is an application for communication between ESP32 and MCU, which replaces the above-mentioned operation from PC terminal software with Nucleo(STM32). This application divides the process according to the match or mismatch between the code "ABC" registered in advance and the receiving code. The input code includes "@" at the end to indicate the end of the character string including the receiving code.
Enter "ABC@" while connected to the TCP server side of the Nucleo (STM32) WiFi enabled with ESP32 using a TCP communication terminal such as a PC or smartphone, etc. When ESP32 receives the string, it will send "+IPD,0,6:ABC@" as a character via UART communication. The STM32 side can extract the "ABC" code.
Once the receiving code is obtained, the application can then create what it wants to process, just as in serial communication.
For example, if the code is registered as "ON" or "OFF", and the processing can be divided into two types when the code matches these codes, it will be possible to remotely control the device as a software switch.