root-r
1
hi,
i have a d-link dwr-921 lte router running openwrt 18.06.4
the router frequently loses its internet connection, then i mostly have to reboot, connect the router to a computer via network cable and run the commands
# ssh root@192.168.1.1 and
# ifup wwan
manually to bring the router back online.
i am wondering if its possible to automate this, so the router automatically issues the "ifup wwan" command while booting or after booting (so i only have to reboot the router when it loses its internet connection, with no need to go to the command line in addition).
my knowledge about linux is limited, but i suppose this should be done by a boot script, right? unfortunately, i have no experience with writing scripts :-/
what do you think? what would be the best way to set up openwrt to run the "ifup wwan" command automatically at boot?
your help would be much appreciated.
thank you
trendy
2
There is an option in the interface settings to bring it up on boot.
For anything else there is rc.local
root@koutsomoura:~# cat /etc/rc.local
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
exit 0
2 Likes
See also:
Is reboot really necessary?
1 Like
You should not need to reboot the device, and you should not need to bring the interface up manually. Post your config files here, perhaps there is something weird there.
2 Likes
root-r
5
thank you. by "option in the interface settings" you mean the bottom section in system -> startup in luci, right?
so it should look like this?
exit 0 ifup wwan
root-r
6
thank you. i somehow got used to the thought that i have to reboot it to make the commands work, but maybe it was not necessary.
today i tried it and they worked without a reboot. so it looks like i have gotten that wrong.
are you sure that it is not normal that i have to bring up the wwan interface manually? the documentation sounds like this is normal, unless i'm misunderstanding it:
https://openwrt.org/toh/d-link/d-link_dwr-921#g3g_modem
where do i find my config files?
Well, if "uci set network.wwan.auto='0'" means "do not bring up on boot", I would try with "uci set network.wwan.auto='1'" and see what happens...
2 Likes
trendy
8
Nope, this is for services. The right place is Network->Interfaces->WWAN-> Advanced Settings-> Bring up on boot.
No, the line exit 0 must be at the end, so whatever you add there keep it above.
1 Like
jeff
9
Another thing to consider is that many wireless modems fail to notify upper layers that the connection to the provider is down, so that the OS doesn't "know" that it needs to initiate reconnection. One page that discusses this is http://www.embeddedpi.com/documentation/3g-4g-modems/raspberry-pi-sierra-wireless-mc7304-modem-qmi-interface-setup I don't think the scripts there are generally useful for OpenWrt as they require Perl (which is for all-in-one routers, huge), but perhaps worth seeing if the interface is actually marked as "DOWN" (using, for example, ip link) when you lose connectivity.
I haven't written a "router friendly" version of the script myself, but understanding the source of the problem can help determine a resolution better than the sledgehammer of "reboot".
root-r
10
i'm encountering a problem when trying to do that. there is no "advanced settings" tab and it just reads:
there is no device assigned yet, please attach a network device in the "physical settings" tab
however, i have a working internet connection right now.
here are two screenshots (i have removed details like ip-addresses):
what does this mean? why does it show the wwan interface as not connected in the second image?
root-r
12
i hope this is what you meant...X always means that i replaced a letter or a number, let me know if you need to know any of those
root@OpenWrt:~# uci show network
network.loopback=interface
network.loopback.ifname='lo'
network.loopback.proto='static'
network.loopback.ipaddr='XXX.X.X.X'
network.loopback.netmask='XXX.X.X.X'
network.globals=globals
network.globals.ula_prefix='XXXX:XXXX:XXXX::/XX'
network.lan=interface
network.lan.type='bridge'
network.lan.ifname='eth0.1'
network.lan.proto='static'
network.lan.ipaddr='192.168.1.1'
network.lan.netmask='XXX.XXX.XXX.X'
network.lan.ip6assign='60'
network.lan_dev=device
network.lan_dev.name='eth0.1'
network.lan_dev.macaddr='XX:XX:XX:XX:XX:XX'
network.wan=interface
network.wan.ifname='eth0.2'
network.wan.proto='dhcp'
network.wan_dev=device
network.wan_dev.name='eth0.2'
network.wan_dev.macaddr='XX:XX:XX:XX:XX:XX'
network.wan6=interface
network.wan6.ifname='eth0.2'
network.wan6.proto='dhcpv6'
network.@switch[0]=switch
network.@switch[0].name='switch0'
network.@switch[0].reset='1'
network.@switch[0].enable_vlan='1'
network.@switch_vlan[0]=switch_vlan
network.@switch_vlan[0].device='switch0'
network.@switch_vlan[0].vlan='1'
network.@switch_vlan[0].ports='0 1 2 3 6t'
network.@switch_vlan[1]=switch_vlan
network.@switch_vlan[1].device='switch0'
network.@switch_vlan[1].vlan='2'
network.@switch_vlan[1].ports='4 6t'
network.wwan=interface
network.wwan.proto='wwan'
network.wwan.apn='internet'
network.wwan.pincode='XXXX'
network.wwan.auto='0'
tmomas
13
Please use "Preformatted text </>" for logs, scripts, configs and general console output.

Please edit your posting accordingly.
root-r
15
it would have been my next step to change it to '1'...but right now (after noticing that wwan is shown as not connected though it apparently should be) i'm fearing that there may be a basic problem with my configuration of network interfaces.
i suppose as long as i'm not sure about that, i shouldn't make any changes.
what do you say to the screenshots and the terminal output i posted? is it normal that wwan interface is shown as not connected?
Perhaps if you can monitor neigh state...;
#!/bin/bash
VERBOSE=1
WANIF="eth0.2"
LOOPDELAY=3 #ooo
BACKOFFUP=3 #ooo
BACKOFFSTALE=2 #ooo
STALEMAX="7"
STALECOUNT="0"
DOWNCOUNT="0" #STATSONLY
CHECKCOUNT="0" #STATSONLY
WANREPAIRCOUNT=0
WANREPAIRMAX=10
WANREPAIRSTATE=
WANSTATUS=
GWIP="`ip route | grep default | cut -d' ' -f3`"
if [ ! -z "$GWIP" ]; then WANSTATUS="UP"; else WANSTATUS="DOWN"; fi
if ifconfig | grep -v " " | grep -v '^$' | awk '{print $1}' | grep -q "$WANIF"; then
echo "WANIF: $WANIF [ok]"
else
echo "WANIF: $WANIF [not-present]"
exit 1
fi
getgwip() {
GWIP="`ip route | grep default | cut -d' ' -f3`"
if [ ! -z "$GWIP" ]; then WANSTATUS="UP"; else WANSTATUS="DOWN"; fi
}
checkup() {
CHECKCOUNT=$[$CHECKCOUNT + 1]
echo -n "CHECKUP:"
if ping -c 2 -w 3 "${GWIP}" &>/dev/null; then
echo " [ok]"
WANSTATUS="UP"
return 0
else
echo " [down]"
WANSTATUS="DOWN"
return 1
fi
}
connectiondown() {
echo "CONNECTION IS DOWN: $DOWNCOUNT"
sleep 3
logger -t wan-mon "${WANIF} DOWN:`date +%Y%m%d-%H%M` ${DOWNCOUNT}"
echo "####!!! HANDLE REALDOWN !!! ###"; sleep 3
WANREPAIRCOUNT=$[$WANREPAIRCOUNT + 1]
WANREPAIRSTATE="FIXING" #REPAIR FAILED WAIT
}
connectionup() {
logger -t wan-mon "${WANIF} UP:`date +%Y%m%d-%H%M` ${DOWNCOUNT}"
}
showstats() {
echo -n "${WANRESULT:-LEARNING}"
echo -n ":::"
echo -n "${WANSTATUS:-ERRORSTATUS}"
echo -n " GW: $GWIP"
echo -n " STALECOUNT: $STALECOUNT"
echo -n " CHECKCOUNT: $CHECKCOUNT"
echo -n " DOWNCOUNT: $DOWNCOUNT"
echo -n " WANREPAIRCOUNT: $WANREPAIRCOUNT"
echo -n " WANREPAIRSTATE: $WANREPAIRSTATE"
echo ""
}
while true; do
if (("$WANREPAIRCOUNT" > "$WANREPAIRMAX")); then echo "ENDING SCRIPT ::: WANREPAIRCOUNT > WANREPAIRMAX" && exit 21; fi
getgwip
#Rif [ -z "$GWIP" ] || [ "$WANSTATUS" == "DOWN" ]; then
if [ -z "$GWIP" ]; then
echo "MAINLOOP: no-gw-ip CALL CONNECTIONDOWN"; sleep 2
connectiondown
else
WANSTATE="`ip neigh show dev $WANIF | grep -w "$GWIP"`"
case $WANSTATE in
*"FAILED"*) WANRESULT="FAILED"; WANSTATUS="DOWN"; ;;
*"STALE"*) WANRESULT="STALE"; STALECOUNT=$[$STALECOUNT + 1]; ;;
*"REACHABLE"*) WANRESULT="REACHABLE"; STALECOUNT=0; sleep $BACKOFFUP; ;;
*"DELAY"*) WANRESULT="DELAY"; ;;
*) WANRESULT="UNKNOWN"; WANSTATUS="DOWN"; ;;
esac
showstats
if (("$VERBOSE" > "0")); then
: #logger -t wan-mon-stat "`showstats`";
fi
if (("$STALECOUNT" > "$STALEMAX")); then
if checkup; then
STALECOUNT=0
else
DOWNCOUNT=$[$DOWNCOUNT + 1]
connectiondown
fi
fi
if [ "$WANSTATUS" == "DOWN" ]; then
echo "STATE is DOWN at bottom loop"; sleep 2
if checkup; then
STALECOUNT=0
else
DOWNCOUNT=$[$DOWNCOUNT + 1]
connectiondown
fi
fi
if (("$STALECOUNT" < "$STALEMAX")); then sleep $BACKOFFSTALE; fi
fi
sleep $LOOPDELAY
done
echo "BAILING"
exit 0
1 Like
root-r
18
so to change the value, is it correct to run the following commands?
uci set network.wwan.auto='1'
service network reload
or is there a better way? e.g. editing the /etc/config/network file?
i still don't know if it is normal that the wwan interface is shown as not connected (see the screenshots i posted), but maybe this will change when i set the value to '1'
Save and verify the changes:
uci commit network
uci get network.wwan.auto
root-r
20
okay, it works now. i don't have to run the ifup wwan command manually anymore. thank you and everybody else 
in luci, i now have the option to click on "restart" in the wwan section. however:
- protocol is still shown as "unmanaged"
- when i click "edit", it is the same as in the first screenshot i posted ("there is no device assigned yet...", protocol is shown as "static address")
- the wwan_4 section is like in the second screenshot i posted (protocol "virtual dynamic interface (dhcp client)" with no option to click on restart, stop, edit or delete)
is this supposed to be this way?