Scripts as per previous post:
Script1: Wan1 Down Modem Reset (Scheduled)
- Checks wan USB port inactive and reboots router if needed.
- Pings a known good host and starts scripts 2 and 3 if no reply.
Code:
########################################################
## Modem reset script for 3G PPP Wan links with Email reporting ##
## based on ping reply to a known good host. ##.
## The google dns server at 8.8.4.4 is used ##
## in this example, but you can use any known good host to ping. ##
## take note of your wan interface name! ##
#
### NB NB!! This script runs two other scripts which perform the ###
### actual modem reset sequences: ###
### "Wan1 Modem Reset DataChan" ###
### "Wan1 Modem Reset InfoChan" ###
#
## Schedule this script at whatever checking interval you require. ##
## Remember to set up Tools - Email settings ##
## Peter James 2012-04-20 ##
########################################################
# Delay for first time run after boot #
:delay 15;
# Set the 3G wan name #
:local WanName "wan1";
# get the usb port for this interface #
:local usbPortName [/interface ppp-client get [/interface ppp-client find name=$WanName] port];
:log info "Starting $WanName 3G Down Check";
:local i 0;
:local result 0;
### Define the email address to receive 3G modem reset report ###
:local emailAddressToNotify "your_email_address_here"
## Define host to check ###
:local testhost "8.8.4.4";
## Define number of pings to check ##
:local PingCount 10;
### Get System Identity ###
:local SystemID [/system identity get name]
## If the usb port is inactive, reboot the router to attempt to fix this ##
#:log info "Checking USB Port: $usbPortName Status";#
:if ([/port get [find name=$usbPortName] inactive]) do={
:log info "USB Port: $usbPortName detected as inactive - System Rebooting";
/system reboot;
}
## Skip the ping check if the wan interface is not running ##
:if ([/interface get [find name="$WanName"] running]=true) do={
:do {
:set i ($i + 1);
:if ([/ping $testhost interface="$WanName" interval=3 count=1]=1) do={
:set result ($result+1);
}
} while=($i < $PingCount)
}
# ping has failed PingCount times or ping check was skipped #
:if ($result=0) do={
:log info "Starting $WanName 3G Modem Reset Sequence";
# get its ID number #
:local WanID [/interface ppp-client find name=$WanName];
# Disable the interface to stop dial attempts #
/interface ppp-client disable $WanID;
# Run the reset scripts #
execute "/system script run \"Wan1 Modem Reset DataChan\"";
execute "/system script run \"Wan1 Modem Reset InfoChan\"";
# Wait for all reset sequences to complete #
delay 60;
# Enable the interface once again #
/interface ppp-client enable $WanID;
# Modem should now redial and connect #
:log info "waiting to send email 30 seconds";
## wait before trying to send email ##
delay 30;
# Check if interface is now running #
:if ([/interface get [find name="$WanName"] running]=true) do={
/tool e-mail send tls=yes subject="$SystemID $WanName 3G Modem Was Reset" to=$emailAddressToNotify body="$WanName 3G Modem Was Reset"
:log info "Email sent $WanName 3G Modem Was Reset";
:log info "$WanName Modem Reset Sequence Complete";
} else={
:log info "$WanName Interface Not Running - Modem Reset Sequence Failed";
}
}
:log info "$WanName 3G Down Check Complete";
Script2: Wan1 Modem Reset DataChan (Started by Script1)
(This script can also be called independently at any time to issue a modem reset over the data channel)
Code:
# Reset the PPP Interface 3G Modem using Data Channel #
###################################################################
## Script uses PPP Modem Init to send AT command to serial port ##
## Commands are simply fired "blind" at the modem ##
## Example sends the AT+CFUN=4, AT+CFUN=6 command sequence ##
## ZTE MF-190 requires AT+CFUN=4, AT+CFUN=1 sequence or AT+ZRST ##
## Sierra Wireless: AT!RESET ##
## ZTE: AT+ZRST ##
## Huawei: AT+CFUN=4, AT+CFUN=6 sequence ##
## This script can be used with Netwatch or sheduled to run on startup ##
## after a watchdog reboot. ##
## You can adjust the delays and AT commands as needed ##
### Peter James 2012-04-20 ###
###################################################################
:local pppName "wan1";
:log info "$pppName Modem Data Channel Reset Started";
delay 20;
:local ModemPort [/interface ppp-client get [/interface ppp-client find name=$pppName] port];
:local DataChan [/interface ppp-client get [/interface ppp-client find name=$pppName] data-channel];
:if ([:len [/interface find name="ResetData1"]] = 0 ) do={
:log info "creating temporary reset ppp interface DataChan";
# Create temporary ppp interface for the specified USB port #
/interface ppp-client add add-default-route=no comment="ResetData1" dial-on-demand=no disabled=yes data-channel=$DataChan name=ResetData1 port=$ModemPort;
}
# Set Interface ID number #
:local ResetData1id [/interface ppp-client find name="ResetData1"];
## Send modem reset sequence ##
# Send first part of reset sequence #
/interface ppp-client set modem-init="AT+CFUN=4" $ResetData1id;
#/interface ppp-client set modem-init="AT+ZRST" $ResetData1id;#
/interface ppp-client enable $ResetData1id;
# Allow time for Init command to be sent #
delay 5;
# disable again to stop any possible dial attempts #
/interface ppp-client disable $ResetData1id;
# Wait for tx and rx RF circuits to switch off #
delay 5;
# Send second part of reset sequence #
/interface ppp-client set modem-init="AT+CFUN=6" $ResetData1id;
/interface ppp-client enable $ResetData1id;
delay 5;
/interface ppp-client set modem-init="" $ResetData1id;
/interface ppp-client disable $ResetData1id;
delay 2;
# Remove temporary interface #
/interface ppp-client remove $ResetData1id;
:log info "$pppName Modem Data Channel Reset Completed";
Script3: Wan1 Modem Reset InfoChan (Started by Script1)
(This script can also be called independently at any time to issue a modem reset over the info channel)
Code:
# Reset the PPP Interface 3G Modem using Info Channel #
###################################################################
## Script uses PPP Modem Init to send AT command to serial port ##
## Commands are simply fired "blind" at the modem ##
## Example sends the AT+CFUN=4, AT+CFUN=6 command sequence ##
## ZTE MF-190 requires AT+CFUN=4, AT+CFUN=1 sequence or AT+ZRST ##
## Sierra Wireless: AT!RESET ##
## ZTE: AT+ZRST ##
## Huawei: AT+CFUN=4, AT+CFUN=6 sequence ##
## This script can be used with Netwatch or sheduled to run on startup ##
## after a watchdog reboot. ##
## You can adjust the delays and AT commands as needed ##
## Peter James 2012-04-20 ##
###################################################################
:local pppName "wan1";
:log info "$pppName Modem Info Channel Reset Started";
#delay 20;#
:local ModemPort [/interface ppp-client get [/interface ppp-client find name=$pppName] port];
:local InfoChan [/interface ppp-client get [/interface ppp-client find name=$pppName] info-channel];
:if ([:len [/interface find name="ResetInfo1"]] = 0 ) do={
:log info "creating temporary reset ppp interface InfoChan";
# Create temporary ppp interface for the specified USB port #
/interface ppp-client add add-default-route=no comment="ResetInfo1" dial-on-demand=no disabled=yes data-channel=$InfoChan name=ResetInfo1 port=$ModemPort;
}
# Set Interface ID number #
:local ResetInfo1id [/interface ppp-client find name="ResetInfo1"];
## Send modem reset sequence ##
# Send first part of reset sequence #
/interface ppp-client set modem-init="AT+CFUN=4" $ResetInfo1id;
#/interface ppp-client set modem-init="AT+ZRST" $ResetInfo1id;#
/interface ppp-client enable $ResetInfo1id;
# Allow time for Init command to be sent #
delay 5;
# disable again to stop any possible dial attempts #
/interface ppp-client disable $ResetInfo1id;
# Wait for tx and rx RF circuits to switch off #
delay 5;
# Send second part of reset sequence #
/interface ppp-client set modem-init="AT+CFUN=6" $ResetInfo1id;
/interface ppp-client enable $ResetInfo1id;
delay 5;
/interface ppp-client set modem-init="" $ResetInfo1id;
/interface ppp-client disable $ResetInfo1id;
delay 2;
# Remove temporary interface #
/interface ppp-client remove $ResetInfo1id;
:log info "$pppName Modem Info Channel Reset Completed";
Bookmarks