If you’ve built a D-Star hotspot and sometimes find the DV modem (GMSK modem) occasionally loses connection on the USB bus, I wrote a helpful script to check the presence of the modem and if not found on the expected device node, instructs the hotspot host to reboot and bring the system back on the air. This is published free and clear and anyone may use it and distribute it without permission so long as the preamble remains intact:
#!/bin/bash
#########################################################################
# UPDATED: 10-24-2014 #
# #
# This script checks the status of the DV modem and if found #
# to be missing, will reboot your hotspot and log the event. #
# #
# This is useful for applications where the DV modem loses #
# connection and functionality is halted in an unattended setting. #
# #
# OPERATION: #
# This assumes your DV modem is normally detected as /dev/ttyACM0 #
# When a DV modem disappears, the running dstarrepeater software locks #
# /dev/ttyACM0 and when the DV modem tries to reconnect, Linux #
# enumerates the device as the next available device node, #
# /dev/ttyACM1. Therefore, this script looks for the next enumerated #
# ttyACM device and if detected, reboots your Hotspot or repeater. #
# #
# This script was written by John Rogers, K1WIZ and permission #
# is granted for use and distribution so long as this notice #
# is unaltered and not removed. #
# #
# TO USE: #
# Simply place this script in /root/ #
# Rename the script file extension from .txt to .sh and make it #
# executable as follows: #
# #
# mv hotspot-dv-modem-check-script.txt hotspot-dv-modem-check-script.sh #
# chmod +x hotspot-dv-modem-check-script.sh #
# #
# call it every 5 minutes by setting a line in your /etc/crontab file #
# as follows: #
# #
# */5 * * * * /root/hotspot-dv-modem-check-script.sh #
# #
# Save the file and restart cron service (refer to your Linux #
# distro for instructions on restarting cron or simply reboot #
# your hotspot. #
#########################################################################check=`ls /dev/ttyACM1 | wc -l`
timestamp() {
date
}present() {
P1=`timestamp`
P2=`echo ". . . DV MODEM IS PRESENT"`
echo $P1 $P2 > /dev/null 2>&1
}notpresent() {
P1=`timestamp`
P2=`echo ". . . DV MODEM IS NOT PRESENT, REBOOTING HOTSPOT"`
echo $P1 $P2;
/sbin/reboot;
}if [ "$check" = 1 ]; then
notpresent >> /var/log/dvstat.log
exit 0
else
present
exit 0
fi
return 0