Skip to content

Commit 4dc5d52

Browse files
committed
Wi-Fi problems #562
1 parent 00778ac commit 4dc5d52

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

platformio.ini

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ build_flags =
1313
-D ARDUINO_RUNNING_CORE=1 ; Arduino Runs On Core (setup, loop)
1414
-D ARDUINO_EVENT_RUNNING_CORE=1 ; Events Run On Core
1515
-D AUDIOTASK_CORE=0 ; 0 or 1 - reads from the InBuffer, decodes and feeds I2S
16-
-D AUDIOCONTROLTASK_CORE=0 ; 0 or 1 - writes to the Inbuffer, evaluates the data and controls the events
1716
-D AUDIOCONTROLTASK_PRIO=2 ; 0 ... 24 Priority of the Task (0...configMAX_PRIORITIES -1)
1817
-D BOARD_HAS_PSRAM=1
1918
-D MONITOR_SPEED=${this.monitor_speed}

src/main.cpp

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
MiniWebRadio -- Webradio receiver for ESP32
55
66
first release on 03/2017 */String Version ="\
7-
Version 3.5.1 - Nov 18/2024 ";
7+
Version 3.5.1a - Nov 21/2024 ";
88

99
/* 2.8" color display (320x240px) with controller ILI9341 or HX8347D (SPI) or
1010
3.5" color display (480x320px) with controller ILI9486 or ILI9488 (SPI)
@@ -1164,6 +1164,14 @@ bool connectToWiFi() {
11641164
uint16_t idx = 0;
11651165
wifiMulti.addAP(_SSID, _PW); // SSID and PW in code
11661166
SerialPrintfln("WiFI_info: add SSID: " ANSI_ESC_CYAN "%s", _SSID);
1167+
1168+
if(pref.isKey("ap_ssid") && pref.isKey("ap_pw")) { // exists?
1169+
String ap_ssid = pref.getString("ap_ssid", ""); // credentials from accesspoint
1170+
String ap_pw = pref.getString("ap_pw", "");
1171+
if(ap_ssid.length() > 0 && ap_pw.length() > 0) wifiMulti.addAP(ap_ssid.c_str(), ap_pw.c_str());
1172+
SerialPrintfln("WiFI_info: add SSID: " ANSI_ESC_CYAN "%s", ap_ssid.c_str());
1173+
}
1174+
11671175
File file = SD_MMC.open("/networks.csv"); // try credentials given in "/networks.txt"
11681176
if(file) { // try to read from SD_MMC
11691177
while(file.available()) {
@@ -1430,6 +1438,9 @@ void setup() {
14301438

14311439
if(TFT_CONTROLLER < 2) strcpy(_prefix, "/s");
14321440
else strcpy(_prefix, "/m");
1441+
1442+
pref.begin("Pref", false); // instance of preferences from AccessPoint (SSID, PW ...)
1443+
14331444
#if CONFIG_IDF_TARGET_ESP32
14341445
tft.begin(TFT_CS, TFT_DC, VSPI, TFT_MOSI, TFT_MISO, TFT_SCK); // Init TFT interface ESP32
14351446
#else
@@ -3390,6 +3401,15 @@ void WEBSRV_onCommand(const String cmd, const String param, const String arg){
33903401

33913402
if(cmd == "AP_ready"){ webSrv.send("networks=", _scannedNetworks); return;} // via websocket
33923403

3404+
if(cmd == "credentials"){ String AP_SSID = param.substring(0, param.indexOf("\n")); // via websocket
3405+
String AP_PW = param.substring(param.indexOf("\n") + 1);
3406+
SerialPrintfln("credentials: SSID " ANSI_ESC_BLUE "%s" ANSI_ESC_WHITE ", PW " ANSI_ESC_BLUE "%s",
3407+
AP_SSID.c_str(), AP_PW.c_str());
3408+
pref.putString("ap_ssid", AP_SSID);
3409+
pref.putString("ap_pw", AP_PW);
3410+
ESP.restart();}
3411+
3412+
33933413
if(cmd.startsWith("SD/")){ String str = cmd.substring(2); // via XMLHttpRequest
33943414
if(!webSrv.streamfile(SD_MMC, scaleImage(str.c_str()))){
33953415
SerialPrintfln("webSrv: ... " ANSI_ESC_YELLOW "File not found " ANSI_ESC_RED "\"%s\"", str.c_str());

0 commit comments

Comments
 (0)