Hello,
We bought two ESP32S3 at work as surveillance devices for long run experiments. Unfortunately, I could not achieve a reliable behavior of the wifi during the connection process. I used the standard example but WiFi.begin(ssid, password)
works only after a manual reboot of the board using the button.
What steps I took to try to pinpoint the issue :
- Using the same program at work and at home to see if it was related to one specific access point
- Loading the program with VisualStudio/PlatformIO at work and Arduino-CLI at home
- Rebooting the board by turning on and off the power of the RaspberryPi3’s internal usb hub I’m using at home using
uhubctl
- Soft rebooting the board by using the
resetFunc
function (ressource) - Hard rebooting the board by emulating the reset performed by the IDE after programming the board (ressource) ; my brother cleaned the Bash/C code of the original author for me, I’ll put the new one below and we will probably implement it in Python in the near future
- Increasing pauses (from the original 100 ms to 10 s) between
WiFi.disconnect();
andWiFi.begin(ssid, password);
- Adding a step at which we wait for any user input by checking the size of the serial input buffer to manually start the wifi connection when our serial terminal is up to be sure to miss nothing
The thing I haven’t tried for now is to wire the EN pad to a digital output in order to simulate a push of the button directly in the program and avoid pushing on it manually. I still hope to understand the issue and have a more reliable behavior.
I also haven’t tried to adapt the standard test code to use different wifi functions (WiFi.disconnect();
with wifioff or eraseap parameters, WiFi.reconnect()
, or WiFi.waitForConnectResult()
, etc.).
Does someone have an idea on what I am doing wrong and/or what could be the solution?
EDIT: I played a little bit with WiFi.waitForConnectResult()
and WiFi.status()
and according to the Arduino reference, it seems that when calling WiFi.begin()
, the status should switch to WL_IDLE_STATUS. But for me it is directly on WL_DISCONNECTED: at the function return value, right after the call, or until the end of the timeout. So it seems that WiFi.begin()
is not behaving as it should for me.
Many thanks in advance!
Martin.
The last iteration of the wifi init code we tried:
void init_wifi() {
// Set WiFi to STA mode and disconnect from an AP if it was previously connected
Serial.print("Initializing WiFi");
WiFi.mode(WIFI_STA);
WiFi.disconnect();
delay(1000);
Serial.print(".");
Serial.println();
// Set WiFi to STA mode and connect to AP
Serial.print("Connecting to WiFi");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
delay(1000);
Serial.print(".");
Serial.println();
// Wait for opened connection
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(1000);
}
Serial.println();
// Print IP address
Serial.print("Obtained IP address: ");
Serial.println(WiFi.localIP());
Serial.println();
}
The code we used on the RaspberryPi to send a reset though the serial port (called with the serial port as an argument: ./ahr /dev/ttyACM0
):
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, char* argv[]) {
if (argc < 2) {
fprintf(stderr, "need serial device\n");
exit(1);
}
char* sport = argv[1];
unsigned int delay = 1;
int port_fd = open(sport, O_RDWR | O_NOCTTY);
if (errno)
printf("Error opening %s: %s (%d).\n", sport, strerror(errno), errno);
int modem_ctrl, modem_ctrl_saved;
if (ioctl(port_fd,TIOCMGET,&modem_ctrl_saved) == -1)
printf("Error getting handshake lines: %s (%d).\n", strerror(errno), errno);
modem_ctrl = (modem_ctrl_saved | TIOCM_RTS) & ~TIOCM_DTR;
if (ioctl(port_fd, TIOCMSET, &modem_ctrl) == -1)
printf("Error setting handshake lines: %s (%d).\n", strerror(errno), errno);
sleep (delay);
if (ioctl(port_fd, TIOCMSET, &modem_ctrl_saved) == -1)
printf("Error setting handshake lines: %s (%d).\n", strerror(errno), errno);
close(port_fd);
}