Browse Source

WiFi SoftAP fixes (#1881)

* Stop updating SoftAP SSID and password when changing hostname and password via WebUI / settings `reload`:
https://gitter.im/tinkerman-cat/espurna?at=5d65418f49ac051923be1f06
* Show real ssid and psk values from the current sdk configuration instead of using getSetting
* `WIFI.STA` command
master
Max Prokhorov 5 years ago
committed by GitHub
parent
commit
c123156b87
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 64 additions and 14 deletions
  1. +59
    -14
      code/espurna/wifi.ino
  2. +5
    -0
      code/platformio.ini

+ 59
- 14
code/espurna/wifi.ino View File

@ -19,28 +19,35 @@ uint8_t _wifi_ap_mode = WIFI_AP_FALLBACK;
// PRIVATE // PRIVATE
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
void _wifiCheckAP() {
void _wifiUpdateSoftAP() {
if (WiFi.softAPgetStationNum() == 0) {
#if USE_PASSWORD
jw.setSoftAP(getSetting("hostname").c_str(), getAdminPass().c_str());
#else
jw.setSoftAP(getSetting("hostname").c_str());
#endif
}
}
if ((WIFI_AP_FALLBACK == _wifi_ap_mode) &&
(jw.connected()) &&
((WiFi.getMode() & WIFI_AP) > 0) &&
(WiFi.softAPgetStationNum() == 0)
void _wifiCheckAP() {
if (
(WIFI_AP_FALLBACK == _wifi_ap_mode)
&& ((WiFi.getMode() & WIFI_AP) > 0)
&& jw.connected()
&& (WiFi.softAPgetStationNum() == 0)
) { ) {
jw.enableAP(false);
jw.enableAP(false);
} }
} }
void _wifiConfigure() { void _wifiConfigure() {
jw.setHostname(getSetting("hostname").c_str()); jw.setHostname(getSetting("hostname").c_str());
#if USE_PASSWORD
jw.setSoftAP(getSetting("hostname").c_str(), getAdminPass().c_str());
#else
jw.setSoftAP(getSetting("hostname").c_str());
#endif
_wifiUpdateSoftAP();
jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT); jw.setConnectTimeout(WIFI_CONNECT_TIMEOUT);
wifiReconnectCheck(); wifiReconnectCheck();
jw.enableAPFallback(WIFI_FALLBACK_APMODE); jw.enableAPFallback(WIFI_FALLBACK_APMODE);
jw.cleanNetworks(); jw.cleanNetworks();
@ -370,6 +377,7 @@ void _wifiDebugCallback(justwifi_messages_t code, char * parameter) {
} }
if (code == MESSAGE_ACCESSPOINT_DESTROYED) { if (code == MESSAGE_ACCESSPOINT_DESTROYED) {
_wifiUpdateSoftAP();
DEBUG_MSG_P(PSTR("[WIFI] Access point destroyed\n")); DEBUG_MSG_P(PSTR("[WIFI] Access point destroyed\n"));
} }
@ -424,6 +432,11 @@ void _wifiInitCommands() {
terminalOK(); terminalOK();
}); });
terminalRegisterCommand(F("WIFI.STA"), [](Embedis* e) {
wifiStartSTA();
terminalOK();
});
terminalRegisterCommand(F("WIFI.AP"), [](Embedis* e) { terminalRegisterCommand(F("WIFI.AP"), [](Embedis* e) {
wifiStartAP(); wifiStartAP();
terminalOK(); terminalOK();
@ -495,6 +508,32 @@ void _wifiWebSocketOnAction(uint32_t client_id, const char * action, JsonObject&
// INFO // INFO
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// backported WiFiAPClass methods
String _wifiSoftAPSSID() {
struct softap_config config;
wifi_softap_get_config(&config);
char* name = reinterpret_cast<char*>(config.ssid);
char ssid[sizeof(config.ssid) + 1];
memcpy(ssid, name, sizeof(config.ssid));
ssid[sizeof(config.ssid)] = '\0';
return String(ssid);
}
String _wifiSoftAPPSK() {
struct softap_config config;
wifi_softap_get_config(&config);
char* pass = reinterpret_cast<char*>(config.password);
char psk[sizeof(config.password) + 1];
memcpy(psk, pass, sizeof(config.password));
psk[sizeof(config.password)] = '\0';
return String(psk);
}
void wifiDebug(WiFiMode_t modes) { void wifiDebug(WiFiMode_t modes) {
#if DEBUG_SUPPORT #if DEBUG_SUPPORT
@ -519,8 +558,8 @@ void wifiDebug(WiFiMode_t modes) {
if (((modes & WIFI_AP) > 0) && ((WiFi.getMode() & WIFI_AP) > 0)) { if (((modes & WIFI_AP) > 0) && ((WiFi.getMode() & WIFI_AP) > 0)) {
DEBUG_MSG_P(PSTR("[WIFI] -------------------------------------- MODE AP\n")); DEBUG_MSG_P(PSTR("[WIFI] -------------------------------------- MODE AP\n"));
DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), getSetting("hostname").c_str());
DEBUG_MSG_P(PSTR("[WIFI] PASS %s\n"), getAdminPass().c_str());
DEBUG_MSG_P(PSTR("[WIFI] SSID %s\n"), _wifiSoftAPSSID().c_str());
DEBUG_MSG_P(PSTR("[WIFI] PASS %s\n"), _wifiSoftAPPSK().c_str());
DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.softAPIP().toString().c_str()); DEBUG_MSG_P(PSTR("[WIFI] IP %s\n"), WiFi.softAPIP().toString().c_str());
DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.softAPmacAddress().c_str()); DEBUG_MSG_P(PSTR("[WIFI] MAC %s\n"), WiFi.softAPmacAddress().c_str());
footer = true; footer = true;
@ -569,6 +608,12 @@ void wifiDisconnect() {
jw.disconnect(); jw.disconnect();
} }
void wifiStartSTA() {
jw.disconnect();
jw.enableSTA(true);
jw.enableAP(false);
}
void wifiStartAP(bool only) { void wifiStartAP(bool only) {
if (only) { if (only) {
jw.enableSTA(false); jw.enableSTA(false);


+ 5
- 0
code/platformio.ini View File

@ -243,6 +243,11 @@ upload_flags = ${common.ota_upload_flags}
board = ${common.board_4m} board = ${common.board_4m}
build_flags = ${common.build_flags_4m1m} -DNODEMCU_LOLIN -DDEBUG_FAUXMO=Serial -DNOWSAUTH build_flags = ${common.build_flags_4m1m} -DNODEMCU_LOLIN -DDEBUG_FAUXMO=Serial -DNOWSAUTH
[env:nodemcu-lolin-252]
platform = ${common.arduino_core_2_5_2}
board = ${common.board_4m}
build_flags = ${common.build_flags_4m1m} -DNODEMCU_LOLIN -DDEBUG_FAUXMO=Serial -DNOWSAUTH
[env:nodemcu-lolin-ssl] [env:nodemcu-lolin-ssl]
platform = ${common.platform_latest} platform = ${common.platform_latest}
board = ${common.board_4m} board = ${common.board_4m}


Loading…
Cancel
Save