A small Keepalive daemon for MainsailOS (or any other Raspberry Pi OS based Image).
git clone https://github.com/mainsail-crew/sonar.git
cd ~/sonar
make config
sudo make install
cd ~/sonar
make uninstall
Simply add
[update_manager sonar]
type: git_repo
path: ~/sonar
origin: https://github.com/mainsail-crew/sonar.git
primary_branch: main
managed_services: sonar
install_script: tools/install.sh
to your moonraker.conf
You can configure its behavior using a file in "~/printer_data/config/sonar.conf". But you don't have to. Defaults are hardcoded and Sonar will run without any configuration.
Hint: The Sonar's configuration file syntax is based on TOML other than in TOML colons are also valid (and prettier). Therefore, a leading section descriptor is crucial!
[sonar]
enable: true
This setting is only evaluated at boot or when the service restarts. Set to "false" to prevent Sonar from starting. It won't run until you change it back to "true" and reboot or restart the service.
debug_log: false
If set to "true" service will log every attempt to reach its target. NOTE: That will highly increase log size, this is intended for debugging purposes only.
persistent_log: false
This option allows you to store a persistent log file "/var/log/sonar.log".
Otherwise, it will be only readable by journalctl -u sonar and it's not
persistent!
target: auto
Defines the ping target. Use an IP address, hostname, or 'auto' to automatically ping your default gateway (router).
count: 3
Number of pings per connection check (each lost reply is bounded to one second).
The packet loss of the check is compared with loss_threshold.
loss_threshold: 100
Packet loss (percent) from which a check counts as failed. 100 keeps the historical behaviour: failed only when no reply at all comes back. A WiFi link that keeps its association and its IP but drops most frames (beacon loss on a marginal radio link) is only detected with a lower value, e.g. 50.
loss_streak: 1
Number of consecutive failed checks before Sonar acts (reconnect). 2 or more ignores a single bad burst.
interval: 60
Sets interval in seconds, how long it should wait for next connection check.
restart_threshold: 10
Delay in seconds before attempting WiFi restart after connection loss
dongle_recovery: true
Recover a wedged adapter, not only a lost association: when there is no default
route at all, every dongle_recovery_threshold cycles the WiFi interface is
reconnected (nmcli, NetworkManager restart as fallback) and, if the adapter
then sees no network at all, its driver is reloaded (USB unbind/bind, kernel
module as fallback).
dongle_recovery_threshold: 3
Consecutive cycles without a default route before a recovery attempt.
soft_recoveries_before_reload: 3
A half-wedged USB dongle still receives (it lists the networks, associates, NetworkManager shows "connected", it may even keep its address and route) but transmits nothing, and soft reconnects alone loop forever. After this many soft recoveries in a row without the link coming back — whether there is no route at all or the gateway simply never answers — the driver is reloaded even though networks are visible. Minimum 1.
That's it. It isn't the best method to keep your WiFi up and running, but it is the easiest solution without changing firmware files or similar.
I hope you will find sonar useful, and it blows away your connection lost :)