From 00cf2ba3ec3fe8c4530b6c37f1685fd487977c30 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Sat, 2 Jan 2021 14:38:48 +0100 Subject: [PATCH] reduce wifi reconnection time after deep sleep #150 --- Makefile | 5 +++-- configs/networkmanager/resetscaninterval.sh | 2 ++ programs/sxmo_screenlock.c | 6 +++++- scripts/core/sxmo_postwake.sh | 2 ++ scripts/core/sxmo_resetscaninterval.sh | 11 +++++++++++ 5 files changed, 23 insertions(+), 3 deletions(-) create mode 100755 configs/networkmanager/resetscaninterval.sh create mode 100755 scripts/core/sxmo_resetscaninterval.sh diff --git a/Makefile b/Makefile index 910185e..7772420 100644 --- a/Makefile +++ b/Makefile @@ -44,8 +44,9 @@ install: $(PROGRAMS) install -D -m 0644 -t $(DESTDIR)$(PREFIX)/share/applications/ configs/xdg/mimeapps.list - mkdir -p $(PREFIX)/etc/NetworkManager/dispatcher.d - cp configs/networkmanager/updatestatusbar.sh $(PREFIX)/etc/NetworkManager/dispatcher.d/10-updatestatusbar.sh + mkdir -p $(DESTDIR)/etc/NetworkManager/dispatcher.d + install -D -m 0755 -T configs/networkmanager/updatestatusbar.sh $(DESTDIR)/etc/NetworkManager/dispatcher.d/10-updatestatusbar.sh + install -D -m 0755 -T configs/networkmanager/resetscaninterval.sh $(DESTDIR)/etc/NetworkManager/dispatcher.d/20-resetscaninterval.sh # Bin install -D -t $(DESTDIR)$(PREFIX)/bin scripts/*/* diff --git a/configs/networkmanager/resetscaninterval.sh b/configs/networkmanager/resetscaninterval.sh new file mode 100755 index 0000000..0b04f35 --- /dev/null +++ b/configs/networkmanager/resetscaninterval.sh @@ -0,0 +1,2 @@ +#!/bin/sh +sxmo_resetscaninterval.sh diff --git a/programs/sxmo_screenlock.c b/programs/sxmo_screenlock.c index 0948a4d..af465ab 100644 --- a/programs/sxmo_screenlock.c +++ b/programs/sxmo_screenlock.c @@ -375,10 +375,14 @@ syncstate() writefile(powerstatefile, "mem"); //---- program blocks here due to sleep ----- // // Just woke up again + fprintf(stderr, "Woke up\n"); fprintf(stderr, "Resetting usb connection to the modem\n"); writefile("/sys/bus/usb/drivers/usb/unbind", "3-1"); writefile("/sys/bus/usb/drivers/usb/bind", "3-1"); - fprintf(stderr, "Woke up\n"); + fprintf(stderr, "Lower scan interval for quicker reconnection to wireless network\n"); + writefile("/sys/module/8723cs/parameters/rtw_scan_interval_thr", "1200"); //ms + //^-- this will be undone again by a networkmanager hook after connection has been established + // or by a delayed script if no connection can be established after a while (to conserve battery) if (waketime > 0) { rtcresult = checkrtcwake(); } else { diff --git a/scripts/core/sxmo_postwake.sh b/scripts/core/sxmo_postwake.sh index 7d57cda..f3f7522 100755 --- a/scripts/core/sxmo_postwake.sh +++ b/scripts/core/sxmo_postwake.sh @@ -4,6 +4,8 @@ sxmo_statusbarupdate.sh +(sleep 15 && sxmo_resetscaninterval.sh) & + if [ -x "$XDG_CONFIG_HOME/sxmo/hooks/postwake" ]; then "$XDG_CONFIG_HOME/sxmo/hooks/postwake" fi diff --git a/scripts/core/sxmo_resetscaninterval.sh b/scripts/core/sxmo_resetscaninterval.sh new file mode 100755 index 0000000..20384c2 --- /dev/null +++ b/scripts/core/sxmo_resetscaninterval.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +# this script resets the wireless scan interval (value is in ms) +# it is invoked with a delay after waking from sleep +# to prevent the scan interval from being too quick, and thus +# too battery consuming, whilst no networks are found + +# the kernel parameter must be writable for the user +# or this script must have the setsuid bit set! + +echo 16000 > /sys/module/8723cs/parameters/rtw_scan_interval_thr