Skip to content

added Enable/Disable WiFi functionality #4670

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3935cd6
* added ability to check if a usermod is enabled from UsermodManager
rhkean Apr 24, 2025
18a110f
Merge branch 'wled:main' into main
rhkean Apr 24, 2025
ded340c
updated package.json
rhkean Apr 24, 2025
097bcb5
usermod_disableWiFi initial commit
rhkean Apr 24, 2025
154cca6
Merge branch 'wled:main' into main
rhkean Apr 25, 2025
da471f9
Merge branch 'main' into usermod_disable_wifi
rhkean Apr 25, 2025
5ed7e13
handle AP enabling/disabling
rhkean Apr 27, 2025
17fbe5e
WiFi toggle with Settings page
rhkean Apr 28, 2025
eaaac68
disable Wifi
rhkean May 1, 2025
d036ebe
Merge pull request #2 from rhkean/usermod_disable_wifi
rhkean May 1, 2025
9ef4306
Merge branch 'wled:main' into main
rhkean May 1, 2025
5737cdb
added 'needs reboot' msg
rhkean May 1, 2025
e7e1d94
removed non-implemented usermod
rhkean May 1, 2025
a724498
removed my change to reboot on button0 short press
rhkean May 1, 2025
e082028
Merge branch 'wled:main' into main
rhkean May 1, 2025
44dfdb6
fixed it this time... derp
rhkean May 1, 2025
a68b23b
Merge branch 'main' of https://github.com/rhkean/WLED
rhkean May 1, 2025
4546422
addressing PR review concerns
rhkean May 1, 2025
8868e23
addressed feedback from PR
rhkean May 3, 2025
011c025
improved wifi settings warning about disable feature
rhkean May 3, 2025
1bf60f1
* fixed some indenting
rhkean May 4, 2025
6713d80
addressed blazoncek's comments
rhkean May 5, 2025
fc99393
final wifiEnabled tests before implementing a JSON API call for turni…
rhkean May 5, 2025
4aca03c
stray newline
rhkean May 5, 2025
3f65097
implemented JSON API for WiFi enable/disable
rhkean May 8, 2025
bce512e
fixed "apply at boot" issue where wifi does not disconnect correctly …
rhkean May 10, 2025
94ba2cd
needed to add check and disable of AP if active
rhkean May 10, 2025
16b5161
minor cleanup
rhkean May 10, 2025
1a3d805
being nit-picky
rhkean May 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions wled00/json.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,21 @@ bool deserializeState(JsonObject root, byte callMode, byte presetId)
WiFi.softAPdisconnect(true);
apActive = false;
}
//bool restart = wifi[F("restart")] | false;
//if (restart) forceReconnect = true;
if (!wifi[F("on")].isNull()) {
bool sta = getBoolVal(wifi[F("on")], wifiEnabled);
bool pwrOff = getBoolVal(wifi[F("pwrOff")], false);
if(!sta){
if(apActive) {
dnsServer.stop();
WiFi.softAPdisconnect(pwrOff);
apActive = false;
} else if (Network.isConnected()) {
WiFi.disconnect(pwrOff);
}
}
wifiEnabled = forceReconnect = sta;
wifiPower = sta | !pwrOff;
}
}

stateUpdated(callMode);
Expand Down
3 changes: 2 additions & 1 deletion wled00/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,8 @@ void WiFiEvent(WiFiEvent_t event)
case ARDUINO_EVENT_WIFI_STA_CONNECTED:
// followed by IDLE and SCAN_DONE
DEBUG_PRINTF_P(PSTR("WiFi-E: Connected! @ %lus\n"), millis()/1000);
wasConnected = true;
if(!wifiEnabled) WiFi.disconnect(!wifiPower);
else wasConnected = true;
break;
case ARDUINO_EVENT_WIFI_STA_DISCONNECTED:
if (wasConnected && interfacesInited) {
Expand Down
5 changes: 3 additions & 2 deletions wled00/wled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,7 @@ void WLED::handleConnection()
const unsigned long nowS = now/1000;
const bool wifiConfigured = WLED_WIFI_CONFIGURED;

if (!wifiEnabled) return;
// ignore connection handling if WiFi is configured and scan still running
// or within first 2s if WiFi is not configured or AP is always active
if ((wifiConfigured && multiWiFi.size() > 1 && WiFi.scanComplete() < 0) || (now < 2000 && (!wifiConfigured || apBehavior == AP_BEHAVIOR_ALWAYS)))
Expand Down Expand Up @@ -816,7 +817,7 @@ void WLED::handleConnection()
initConnection();
}
if (!apActive && now - lastReconnectAttempt > 12000 && (!wasConnected || apBehavior == AP_BEHAVIOR_NO_CONN)) {
if (!(apBehavior == AP_BEHAVIOR_TEMPORARY && now > WLED_AP_TIMEOUT)) {
if (!(apBehavior == AP_BEHAVIOR_TEMPORARY && now > WLED_AP_TIMEOUT) && (apBehavior != AP_BEHAVIOR_BUTTON_ONLY)) {
DEBUG_PRINTF_P(PSTR("Not connected AP (@ %lus).\n"), nowS);
initAP(); // start AP only within first 5min
}
Expand Down Expand Up @@ -901,4 +902,4 @@ void WLED::handleStatusLED()
#endif
}
}
#endif
#endif
14 changes: 11 additions & 3 deletions wled00/wled.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,27 +345,33 @@ typedef class WiFiOptions {
uint8_t apBehavior : 3;
bool noWifiSleep : 1;
bool force802_3g : 1;
bool wifiEnabled : 1;
bool wifiPower : 1;
};
WiFiOptions(uint8_t s, uint8_t c, bool h, uint8_t b, bool sl, bool g) {
WiFiOptions(uint8_t s, uint8_t c, bool h, uint8_t b, bool sl, bool g, bool e, bool p) {
selectedWiFi = s;
apChannel = c;
apHide = h;
apBehavior = b;
noWifiSleep = sl;
force802_3g = g;
wifiEnabled = e;
wifiPower = p;
}
} __attribute__ ((aligned(1), packed)) wifi_options_t;
#ifdef ARDUINO_ARCH_ESP32
WLED_GLOBAL wifi_options_t wifiOpt _INIT_N(({0, 1, false, AP_BEHAVIOR_BOOT_NO_CONN, true, false}));
WLED_GLOBAL wifi_options_t wifiOpt _INIT_N(({0, 1, false, AP_BEHAVIOR_BOOT_NO_CONN, true, false, true, true}));
#else
WLED_GLOBAL wifi_options_t wifiOpt _INIT_N(({0, 1, false, AP_BEHAVIOR_BOOT_NO_CONN, false, false}));
WLED_GLOBAL wifi_options_t wifiOpt _INIT_N(({0, 1, false, AP_BEHAVIOR_BOOT_NO_CONN, false, false, true, true}));
#endif
#define selectedWiFi wifiOpt.selectedWiFi
#define apChannel wifiOpt.apChannel
#define apHide wifiOpt.apHide
#define apBehavior wifiOpt.apBehavior
#define noWifiSleep wifiOpt.noWifiSleep
#define force802_3g wifiOpt.force802_3g
#define wifiEnabled wifiOpt.wifiEnabled
#define wifiPower wifiOpt.wifiPower
#else
WLED_GLOBAL int8_t selectedWiFi _INIT(0);
WLED_GLOBAL byte apChannel _INIT(1); // 2.4GHz WiFi AP channel (1-13)
Expand All @@ -377,6 +383,8 @@ WLED_GLOBAL bool noWifiSleep _INIT(true); // disabling m
WLED_GLOBAL bool noWifiSleep _INIT(false);
#endif
WLED_GLOBAL bool force802_3g _INIT(false);
WLED_GLOBAL bool wifiEnabled _INIT(true);
WLED_GLOBAL bool wifiPower _INIT(true);
#endif // WLED_SAVE_RAM
#ifdef ARDUINO_ARCH_ESP32
#if defined(LOLIN_WIFI_FIX) && (defined(CONFIG_IDF_TARGET_ESP32C3) || defined(CONFIG_IDF_TARGET_ESP32S2) || defined(CONFIG_IDF_TARGET_ESP32S3))
Expand Down