Compare commits

...

3 Commits

Author SHA1 Message Date
Xavier Del Campo Romero f85518f034
Turn WiFi off before suspend
This might help avoiding stability issues with WiFi.
2023-03-30 01:54:26 +02:00
Xavier Del Campo Romero 8556aecc46
sleepwalk: Set +x 2023-03-30 01:54:26 +02:00
Xavier Del Campo Romero e377bc87fd
Inhibit suspend on network activity 2023-03-30 01:54:19 +02:00
1 changed files with 39 additions and 1 deletions

40
sleepwalk Normal file → Executable file
View File

@ -7,6 +7,7 @@ SLEEP_MAX_SECS=600
WAKE_SECS=35
LOCK_DIR="/tmp/sleepwalk"
CPU_STATE=1
THRESHOLD="15.00"
set_cpu_offline() {
if [ $CPU_STATE -eq 1 ]; then
@ -41,6 +42,8 @@ start_deep_sleep() {
sleep 5 # Give some extra time for pending output data
if [ can_suspend ]; then
WIFI_WAS_ON=$(nmcli r wifi)
nmcli r wifi off
echo mem > /sys/power/state 2>/dev/null
fi
@ -107,8 +110,38 @@ is_screen_on() {
return "$(cat /sys/class/backlight/backlight/bl_power)"
}
network_activity() {
for n in $(seq 3)
do
for i in wwan0 wlan0
do
A=$(ifstat -i $i 1 1 | tail -n1)
RX=$(echo $A | awk '{print $1}')
TX=$(echo $A | awk '{print $2}')
if [ "$RX" = "n/a" ] || [ "$TX" = "n/a" ]
then
return 1
fi
for v in $RX $TX
do
C=$(echo $v $THRESHOLD |
awk '{if ($1 > $2) print "y"; else print "n"}')
if [ "$C" = "y" ]
then
return 0
fi
done
done
done
return 1
}
can_suspend() {
! ( is_inhibitor_active || is_screen_on || is_charging )
! ( is_inhibitor_active || is_screen_on || is_charging || network_activity )
}
led_sleep() {
@ -179,6 +212,11 @@ if [ "$1" == "start" ]; then
break
fi
done
if [ "$WIFI_WAS_ON" = "enabled" ]; then
nmcli r wifi on
fi
wait_for_notifications
done
elif [ "$1" == "stop" ]; then