Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/modules/octopi/filesystem/boot/octopi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@
#camera_http_webroot="./www-octopi"
#camera_http_options="-n"

# Configuration of network monitoring
#
# This enables network monitoring for wifi connections with a simple ping test.
# If connection terminates by variable reasons system tries to restart the wifi connection to reestablish a connection.
# The connection test is done every minute.
# By default it is disabled (0 = off / 1 = on)
# dstination_host can be an ip address or a hostname (for hostname ensure dns resosultion is working correctly)
enable_network_monitor=0
destination_host=192.168.1.1

### EXPERIMENTAL
# Support for different streamer types.
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
Description=Network Monitor
ConditionPathExists=/usr/local/bin/networkcheck

[Service]
User=root
Type=simple
ExecStart=/usr/local/bin/networkcheck &
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Network Monitor Trigger (every 1 minutes)
After=network.target

[Timer]
OnCalendar=*-*-* *:*:00
AccuracySec=1s

[Install]
WantedBy=timers.target
28 changes: 28 additions & 0 deletions src/modules/octopi/filesystem/root/usr/local/bin/networkcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

source /boot/octopi.txt

if [ $enable_network_monitor == 1 ] && [ "$destination_host" != "" ]; then

if [ -f /boot/octopi-wpa-supplicant.txt ]; then # check if config file exists
input="/boot/octopi-wpa-supplicant.txt"
while IFS= read -r line; do # read config file line by line
if [[ $line =~ ^network=.* ]]; then # check if we have a network config if a line starts with "network="
echo "network config found..."
ping -c4 $destination_host > /dev/null # check if destination is reachable - possible by default the router
if [ $? != 0 ]; then
echo "Destination not reachable - reconfigure interface..."
sudo wpa_cli -i wlan0 reconfigure # reconfigure network to trigger reconnect
sudo dhclient -v # ensure connection will be established by refresh dhcp lease
echo "Reconnect done."
exit 0 # if we detect multiple network configs exit after 1st one - one reconnect is enough :-)
else
echo "Destination reachable - no action needed."
exit 0 # destination reached - exit loop
fi
fi
done < "$input"
fi
else
echo "Network monitoring not enabled."
fi
4 changes: 4 additions & 0 deletions src/modules/octopi/start_chroot_script
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ fi

systemctl_if_exists enable ffmpeg_hls.service

### Network monitoring

systemctl_if_exists enable networkcheck.timer

#cleanup
apt-get clean
apt-get autoremove -y
Expand Down