Nie możesz mieć takiej sekcji inicjalizującej WIFI na sztywno z autoconnect.
Wgrywasz jakikolwiek szkic z WIFI, flasz ma specjalną sekcję gdzie jest zapisane udane logownie do sieci, potem w opcjach menu wybierasz by nie nadpisywać tych danych i przy kolejnych wgrywaniach szkicu do raz zaprogramowanego modułu nie musisz się do niego logować na akcesspoint i podawać danych. Tam gdzie jest opcja "erase flash" wybierz "szkic tylko". Ale jak mu się nie uda połączyć to stawia AP i czeka na połączenie, co jakiś czas pewnie robi reset i próbuje się połączyć do znanego WIFI. O
czywiście albo raz wgrywasz szkic po staremu nadpisując dane ssid, albo od razu ze szkic only do nowego, ale każdemu nowemu raz musisz podać palcem z telefonu ssid i haslo
Przykładowy setup z autokonekt, OTA, WWW websockets, wygląda tak:
Kod:
void setup(){
pinMode(LED1PIN, OUTPUT);
writeLED1(0);
pinMode(LED2PIN, OUTPUT);
writeLED4(1);
pinMode(LED3PIN, OUTPUT);
writeLED4(1);
pinMode(LED4PIN, OUTPUT);
writeLED4(1);
Serial.begin(115200);
Serial.println();
Serial.println();
Serial.println();
for(uint8_t t = 4; t > 0; t--) {
Serial.printf("[SETUP] BOOT WAIT %d...\r\n", t);
Serial.flush();
delay(1000);
}
Serial.println("\n Starting");
pinMode(TRIGGER_PIN, INPUT_PULLUP);
AsyncWiFiManager wifiManager(&server,&dns);
wifiManager.autoConnect("AutoConnectAP");
Serial.println(WiFi.localIP());
//Send OTA events to the browser
ArduinoOTA.onStart([]() { events.send("Update Start", "ota"); });
ArduinoOTA.onEnd([]() { events.send("Update End", "ota"); });
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
char p[32];
sprintf(p, "Progress: %u%%\n", (progress/(total/100)));
events.send(p, "ota");
});
ArduinoOTA.onError([](ota_error_t error) {
if(error == OTA_AUTH_ERROR) events.send("Auth Failed", "ota");
else if(error == OTA_BEGIN_ERROR) events.send("Begin Failed", "ota");
else if(error == OTA_CONNECT_ERROR) events.send("Connect Failed", "ota");
else if(error == OTA_RECEIVE_ERROR) events.send("Recieve Failed", "ota");
else if(error == OTA_END_ERROR) events.send("End Failed", "ota");
});
ArduinoOTA.setHostname(hostName);
ArduinoOTA.begin();
DS18B20.begin();
liczbaDS=DS18B20.getDeviceCount();
if(liczbaDS) DS18B20.requestTemperatures();
DS18B20.setWaitForConversion(0);
DStoTAB(liczbaDS);
webSocket.begin();
webSocket.onEvent(webSocketEvent);
server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
request->send(200, "text/html", INDEX_HTML);
});
server.begin();
VAR5=thinkinterval;
}