ESP32 is a very good wireless SOC, which can be seen in many mature products. However, I always have trouble using its development environment. In order to reduce the dependence on the ESP32 development environment, you can use the ESP-AT firmware of ESP32. The ESP32 with the ESP-AT firmware can communicate with the microcontroller through the serial port, so that you can develop corresponding applications on the microcontroller you are familiar with.
In some applications that need to communicate through a wide area network, I am more accustomed to using IPV4. However, because IPV4 requires cross-operator routing, an ESP32 module cannot get an IPV4 public IP. If you want to establish a connection with other devices, you can only choose a server to transfer (in some cases, router port mapping is also difficult to achieve). In order to solve the problem of networking and reduce dependence on servers, you can try to use the current main IPV6 protocol. ESP32 also supports IPV6. Below I will share the process of using IPV6 to connect to other devices through ESP-AT.
First, you need to burn the ESP-AT firmware to the corresponding ESP32 module. The corresponding manual: Download Guide - ESP32 - — ESP-AT User Guide latest document (espressif.com) . After downloading ESP-AT, communicate with ESP32 through the microcontroller or USB to serial port, and implement the corresponding functions by sending AT commands.
Here I use USB to serial port to test using serial port assistant on PC. Open the serial port assistant and enter "AT+CIPV6=1" to enable IPV6, and enter "AT+CWJAP="SSID", "password" to connect to the corresponding router. Currently, all new routers support IPV6. You can open www.ip138.com on PC or mobile phone to check whether it supports IPV6. Huawei mobile phones can also check whether there is an IPV6 address in the IP address in "About Phone" -> "Status Information" of the mobile phone. If ESP32 obtains the IPV6 public network address, it will return "WIFI GOT IPv6 GL" after connecting to the router. At this time, enter "AT+CIPSTA?" to see the public network IPV6 address obtained by ESP32.
CIPSTA:ip6gl:The longer one at the end is the public IPV6 address.
After obtaining the public IPV6 address, you can communicate with other devices that support IPV6. ESP32 can act as a server or a client. Here we first test it by configuring ESP32 as a server.
If you want the server to support multiple connections, you can enter "AT+CIPMUX=1" before starting the service. Then enter "AT+CIPSERVER=1,7890,"TCPv6",0" to start the IPV6 TCP Socket server.
After starting the service, you can use the IPV6 TCP Socket client on other devices to connect to the public IPV6 address and port of ESP32 to establish a connection with ESP32.
I have written a client program using Csharp to establish a connection with ESP32 through its public IPV6 address. After the connection is successful, send "www.eeworld.com.cn" and the serial port of ESP32 will output the corresponding information.
If ESP32 wants to send information to other devices, you need to enter the AT+CIPSEND=len command first, where len is the length of the data to be sent. For example, if I want to send "www.eeworld.com.cn", I first enter "AT+CIPSEND=0,18", where the 0 after the equal sign is the number of connected devices when multiple connections are made, and 18 is the length of the data to be sent.
Then send " www.eeworld.com.cn " and you will receive a prompt "Recv 18 bytes SEND OK", indicating that the message was sent successfully. However, the program written in Csharp did not receive the message at this time.
After repeatedly executing "AT+CIPSEND=0,18" and " www.eeworld.com.cn ", all previously unreceived data will be received at once.
Looking at the official documentation of ESP32, you will find a sentence like this: "If all data is successfully sent to the protocol stack (it does not mean that the data has been sent to the other end)"......, that is to say, the previous data may have only been sent to the protocol stack, but it does not specify when it was sent. There is no corresponding instruction on how to force the data to be sent to the other end. This is a pity.
Through the above steps, ESP32 can be connected to other devices through the IPV6 public network address. However, it should be noted that the IPV6 address of individual users is also dynamically allocated, and it will change every once in a while. Therefore, if you want to achieve real interconnection, you still need the cooperation of the server. Of course, it only needs to report the IPV6 address of the server to the client, and does not need to process too much data. In addition to using the server, the exchange of IPV6 addresses can also be exchanged in other ways, such as SMS or email.