Forum › Forums › New users › New Users and General Questions › [solved]How can I stop wi-fi from disconnecting when the system sleeps? › Reply To: [solved]How can I stop wi-fi from disconnecting when the system sleeps?
Using standard sleep/suspend, wifi will always disconnect since all the hardware gets powered down except RAM. Normally, what happens is that connman will automatically reconnect when you wake the system, though. For that to work, you need “AutoConnect” enabled in the configuration for the connection profile, which is something you can check or change in the Connman System Tray window, on the Details tab.
If you’re not successfully reconnecting to an access point even thoug “AutoConnect” is enabled, I think that’s some router issue. It’s something I’ve seen on some wifi access points, where connman does try to reconnect after waking but then fails almost immediately. In this case, you should see “Failure” as the State on CMST’s Status tab after waking from sleep. Maybe this is something that can be fixed somewhere in your router settings, but you could also potentially work around it by running a manual connect command after a small delay.
At least for suspend on lid close, which is managed by acpid, you can create a script named /etc/acpi/local/lid.sh.post and put whatever you want there. Try something like
#!/bin/sh
# Name of the AP to reconnect to (get this from 'connmanctl services' or CMST's Details tab)
ap="wifi_7032174ef3f4_4775657374_managed_none"
# Wait 3 seconds after waking...is that long enough?
sleep 3
# Only attept to reconnect if there was an initial attempt to do it automatically that failed
if connmanctl services $ap | grep -q "State = failure"; then
connmanctl connect $ap
fi
It’s a fairly simplistic workaround and may need some tweaking for your case, but you get the point. This will also only work when you put the system to sleep by the closing lid. Other sleep methods on antix (like menu options or shortcut keys) use pm-utils instead of acpid. To make those also use the same script(s) as acpid, you could put an additional script in /etc/pm/sleep.d like this:
#!/bin/sh
. /etc/default/acpi-support
. /usr/share/acpi-support/policy-funcs
case "$1" in
suspend) [ -x /etc/acpi/local/lid.sh.pre ] && /etc/acpi/local/lid.sh.pre ;;
resume) [ -x /etc/acpi/local/lid.sh.post ] && /etc/acpi/local/lid.sh.post ;;
*) exit ;;
esac
There’s also an alternate type of “sleep” nowadays called s2idle or freeze that can keep the connection up even during sleep, but I don’t know how well it works on Linux. Probably depends on your hardware and kernel version, but you could try it if you want by writing s2idle to /sys/power/mem_sleep.
echo s2idle | sudo tee /sys/power/mem_sleep
Then confirm with
cat /sys/power/mem_sleep
and it should return
[s2idle] deep
At least on my system, it still disconnects from wifi, but there might be some way to configure it not to. Another name for s2idle is “Connected Standby,” so this is supposed to be one of the features. This will definitely use more battery power during sleep.
"--"