The serial port is sent repeatedly when the network is connected of ESP32

When I connect to the network, I find that the data in the serial port is sent twice.


Here is the code to implement the connection.

Further, you can see that there is a dot in the first box and none in the box below. Meanwhile, printed 2 should actually be the callback when the "SYSTEM_EVENT_STA_DISCONNECTED" event was triggered, but it was triggered at connection time.
image
And I found that the number "2" was printed twice as often as the number of Internet connections. As you can see, the "2" was printed 4 times when I connected to the network, and the "2" was also printed 4 times when I closed the hotspot. When I connected to the network again, the "2" was printed 6 times, and likewise, when I turned off the hotspot, the "2" was still printed 6 times.
I want to know what causes this and how to avoid it.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.