improve wifi reconect
This commit is contained in:
@@ -62,6 +62,12 @@ SSH_TUNNEL_PORT=$(sqlite3 /var/www/nebuleair_pro_4g/sqlite/sensors.db "SELECT va
|
|||||||
|
|
||||||
#need to wait for the network manager to be ready
|
#need to wait for the network manager to be ready
|
||||||
sleep 20
|
sleep 20
|
||||||
|
|
||||||
|
# IMPORTANT: Always enable WiFi radio at boot (in case it was disabled by power save)
|
||||||
|
echo "Ensuring WiFi radio is enabled..."
|
||||||
|
nmcli radio wifi on
|
||||||
|
sleep 2
|
||||||
|
|
||||||
# Get the connection state of wlan0
|
# Get the connection state of wlan0
|
||||||
STATE=$(nmcli -g GENERAL.STATE device show wlan0)
|
STATE=$(nmcli -g GENERAL.STATE device show wlan0)
|
||||||
|
|
||||||
|
|||||||
@@ -12,8 +12,9 @@ r'''
|
|||||||
|____/ \__,_| \_/ \___|
|
|____/ \__,_| \_/ \___|
|
||||||
|
|
||||||
WiFi Power Saving Script
|
WiFi Power Saving Script
|
||||||
Disables WiFi after 10 minutes of boot if wifi_power_saving is enabled in config.
|
Disables WiFi completely after 10 minutes of boot if wifi_power_saving is enabled in config.
|
||||||
Saves ~100-200mA of power consumption.
|
Saves ~100-200mA of power consumption.
|
||||||
|
WiFi is automatically re-enabled at next boot (see boot_hotspot.sh).
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
/usr/bin/python3 /var/www/nebuleair_pro_4g/wifi/power_save.py
|
/usr/bin/python3 /var/www/nebuleair_pro_4g/wifi/power_save.py
|
||||||
@@ -67,8 +68,10 @@ def is_wifi_enabled():
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
def disable_wifi():
|
def disable_wifi():
|
||||||
"""Disable WiFi radio using nmcli"""
|
"""Disable WiFi radio completely using nmcli"""
|
||||||
try:
|
try:
|
||||||
|
# Disable WiFi radio completely to save maximum power
|
||||||
|
# WiFi will be re-enabled automatically at next boot by boot_hotspot.sh
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
["sudo", "nmcli", "radio", "wifi", "off"],
|
["sudo", "nmcli", "radio", "wifi", "off"],
|
||||||
capture_output=True,
|
capture_output=True,
|
||||||
@@ -76,7 +79,7 @@ def disable_wifi():
|
|||||||
timeout=10
|
timeout=10
|
||||||
)
|
)
|
||||||
if result.returncode == 0:
|
if result.returncode == 0:
|
||||||
log_message("WiFi disabled successfully - saving ~100-200mA power")
|
log_message("WiFi disabled completely - saving ~100-200mA power (will re-enable at next boot)")
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
log_message(f"Failed to disable WiFi: {result.stderr}")
|
log_message(f"Failed to disable WiFi: {result.stderr}")
|
||||||
@@ -115,13 +118,13 @@ def main():
|
|||||||
log_message("WiFi is already disabled - nothing to do")
|
log_message("WiFi is already disabled - nothing to do")
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Disable WiFi
|
# Disable WiFi completely after 10-minute configuration window
|
||||||
log_message("Disabling WiFi after 10-minute configuration window...")
|
log_message("Disabling WiFi completely after 10-minute configuration window...")
|
||||||
if disable_wifi():
|
if disable_wifi():
|
||||||
log_message("WiFi power save completed successfully")
|
log_message("WiFi disabled successfully - will re-enable at next boot")
|
||||||
return 0
|
return 0
|
||||||
else:
|
else:
|
||||||
log_message("WiFi power save failed")
|
log_message("WiFi disable failed")
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user