You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Not an issue actually, but merely a post with a script to detect whenever a USB modem changes it's name (when disconnected / reconnected while it's old port is being read).
The following script updates the modem device path in /etc/gammu-smsdrc whenever needed.
You can configure it as cron task every 15 minutes or so
#!/usr/bin/env bash
log_file="/var/log/modem_update.log"
gammu_config_file="/etc/gammu-smsdrc"
modem=""
# Optional command when modem port change detected
optional_cmd="systemctl restart gammu-smsd"
function log {
line="${1}"
echo "${line}" >> "${log_file}"
echo "${line}"
}
for tty in $(ls /dev/ttyUSB*); do
log "Checking $tty"
picocom -qrX -b 9600 $tty
sleep 1
result=$(echo "AT&F" | picocom -qrix 1000 $tty)
if [ "${result}" = "AT&F" ]; then
log "Found AT compatible modem at $tty"
modem="${tty}"
else
log "No AT compatible modem at $tty"
fi
done
curr_gammu_modem=$(cat "${gammu_config_file}" | grep "device = " | awk -F'=' '{gsub(/ /,""); print $2}')
if [ "${modem}" != "" ]; then
if [ "${modem}" != "${curr_gammu_modem}" ]; then
log "Updating modem from ${curr_gammu_modem} to ${modem}"
sed -i "s%${curr_gammu_modem}%${modem}%" "${gammu_config_file}"
if [ "${optional_cmd}" != "" ]; then
log "Running ${optional_cmd}"
${optional_cmd} >> "${log_file}"
if [ $? -ne 0 ]; then
log "Could not restart service, exitcode: $?"
fi
fi
fi
fi
Hope this helps someone ;)
The text was updated successfully, but these errors were encountered:
Hello,
Not an issue actually, but merely a post with a script to detect whenever a USB modem changes it's name (when disconnected / reconnected while it's old port is being read).
The following script updates the modem device path in
/etc/gammu-smsdrc
whenever needed.You can configure it as cron task every 15 minutes or so
Hope this helps someone ;)
The text was updated successfully, but these errors were encountered: