my ESP32 (I use a development board: Says ESP-WROOM 32 on the actual chip) is not connecting to my WiFi consistently.
When using Arduino Ide:
Connects 50% of the time. Often connects first try but then on a reset it does not connect. Then on the third try it connects again and so on. I have not tested if this is always like this. But often it is like this.
With Platform IO in VS Code:
Did work once for me. But since then (3h of trying) it did not work again.
In both IDEs I use this example sketch with an HTTPs server:
Code: Select all
#include <WiFi.h>
#include <HTTPSServer.hpp>
#include <SSLCert.hpp>
#include <HTTPRequest.hpp>
#include <HTTPResponse.hpp>
using namespace httpsserver;
const char* ssid = "****";
const char* password = "****";
SSLCert * cert;
HTTPSServer * secureServer;
void setup() {
Serial.begin(115200);
Serial.println("Creating certificate...");
cert = new SSLCert();
int createCertResult = createSelfSignedCert(
*cert,
KEYSIZE_2048,
"CN=myesp.local,O=acme,C=US");
if (createCertResult != 0) {
Serial.printf("Error generating certificate");
return;
}
Serial.println("Certificate created with success");
secureServer = new HTTPSServer(cert);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println(WiFi.localIP());
ResourceNode * nodeRoot = new ResourceNode("/", "GET", [](HTTPRequest * req, HTTPResponse * res){
res->println("Secure Hello World!!!");
});
secureServer->registerNode(nodeRoot);
secureServer->start();
if (secureServer->isRunning()) {
Serial.println("Server ready.");
}
}
void loop() {
secureServer->loop();
delay(10);
}
Code: Select all
[env:esp32dev]
board = esp32dev
framework = arduino
lib_deps = esp32_https_server
monitor_speed = 115200
platform = espressif32
upload_port = COM7
Code: Select all
#include <WiFi.h>
#include <ESPmDNS.h>
#include <ArduinoOTA.h>
#include <WebServer.h>
const char* ssid = "Huck";
const char* password = "NutzedenTag!";
WebServer server(80);
const char* www_username = "admin";
const char* www_password = "esp32";
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Connect Failed! Rebooting...");
delay(1000);
ESP.restart();
}
ArduinoOTA.begin();
server.on("/", []() {
if (!server.authenticate(www_username, www_password)) {
return server.requestAuthentication();
}
server.send(200, "text/plain", "Login OK");
});
server.begin();
Serial.print("Open http://");
Serial.print(WiFi.localIP());
Serial.println("/ in your browser to see it working");
}
void loop() {
ArduinoOTA.handle();
server.handleClient();
}
I know that a lot of people have experienced similar problems but I could not find a solution. Does somebody know why it is not working/why it is that inconsistent?