Android USB tethering automatic reconnection

Post new topic   Reply to topic    DD-WRT Forum Index -> Marvell MVEBU based Hardware (WRT1900AC etc.)
Author Message
frankd84
DD-WRT Novice


Joined: 05 Feb 2023
Posts: 12

PostPosted: Sun Feb 05, 2023 21:30    Post subject: Android USB tethering automatic reconnection Reply with quote
Hi guys,

I enabled tethering on my router through an Android phone with this wiki page:

https://wiki.dd-wrt.com/wiki/index.php/Cellular_Phone/USB_Modem_as_WAN_connection

It works like a charm.... if nothing wrong happens... (Phone restart, USB cable disconnection/reconnection, etc).

From the wiki guide, I thing that those 2 commands must be rerun in order to reconnect tethering if a disconnection has occured:

ifconfig usb0 up
udhcpc -i usb0

How is it possible to run those ones automatically in case of a connection failure?

For now, as a workaround, I just set the Watchdog to ping the phone's tether gateway address each 30 minutes, but I want a solution that doesn't require a reboot of the router each time.

Maybe a script like this one but for usb?

https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=280394&sid=db36810c02b2edd0d9bb1ec81f93022a

But I even don't know where to put it.

Thanks!
Sponsor
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12877
Location: Netherlands

PostPosted: Mon Feb 06, 2023 14:08    Post subject: Reply with quote
There are watch dog scripts which are loaded from startup and then run continuously, pinging every x seconds and if it detects a connection loss it will execute your commands

See: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324624&start=1

There is also watchdog script from @eibgrad: https://pastebin.com/iNC273ER

I also wrote one for OpenVPN: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=321686&start=2
and also Sploit wrote one, you can google for it if you want

My OpenVPN is perhaps the easiest as that does not need usb storage and can easily be adapted with your commands

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
egc
DD-WRT Guru


Joined: 18 Mar 2014
Posts: 12877
Location: Netherlands

PostPosted: Mon Feb 06, 2023 14:37    Post subject: Reply with quote
To give you a head start something like this, Administration/Commands and Save as Startup
Code:
#=======BEGIN tether-watchdog=========
sleep 60
SCRIPT="/tmp/tether-watchdog.sh"
cat << "EOF" > $SCRIPT
#!/bin/sh
(
SLEEP=120 # time (in secs) between each pass, do not set lower than 120 this gives you the ability to login and remove script from startup
#DEBUG= # uncomment/comment to enable/disable debug mode
PINGIP="8.8.8.8"  # Target IP to ping to

[ ${DEBUG+x} ] && set -x
logger "Start $(basename $0)"
while sleep $SLEEP; do
   logger "sleep $SLEEP $(basename $0)"
   TUN=$(get_wanface)
   while ! ping -qc1 -W6 -n $PINGIP -I $TUN &> /dev/null; do
      sleep 9
      if ! ping -qc1 -W6 -n $PINGIP -I $TUN &> /dev/null; then
         logger "$(basename $0) $TUN down, Restart will be executed"
         ifconfig usb0 up
         udhcpc -i usb0
         break
      fi   
   done
done
)2>&1 | logger -t $(basename $0)[$$]
EOF
chmod +x $SCRIPT
$SCRIPT > /dev/null 2>&1 &
#=======END tether-watchdog=========

_________________
Routers:Netgear R7000, R6400v1, R6400v2, EA6900 (XvortexCFE), E2000, E1200v1, WRT54GS v1.
Install guide R6400v2, R6700v3,XR300:https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=316399
Install guide R7800/XR500: https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=320614
Forum Guide Lines (important read):https://forum.dd-wrt.com/phpBB2/viewtopic.php?t=324087
frankd84
DD-WRT Novice


Joined: 05 Feb 2023
Posts: 12

PostPosted: Fri Feb 10, 2023 2:41    Post subject: Reply with quote
Quote:
To give you a head start something like this, Administration/Commands and Save as Startup
Code:
#=======BEGIN tether-watchdog=========
sleep 60
SCRIPT="/tmp/tether-watchdog.sh"
cat << "EOF" > $SCRIPT
#!/bin/sh
(
SLEEP=120 # time (in secs) between each pass, do not set lower than 120 this gives you the ability to login and remove script from startup
#DEBUG= # uncomment/comment to enable/disable debug mode
PINGIP="8.8.8.8" # Target IP to ping to

[ ${DEBUG+x} ] && set -x
logger "Start $(basename $0)"
while sleep $SLEEP; do
logger "sleep $SLEEP $(basename $0)"
TUN=$(get_wanface)
while ! ping -qc1 -W6 -n $PINGIP -I $TUN &> /dev/null; do
sleep 9
if ! ping -qc1 -W6 -n $PINGIP -I $TUN &> /dev/null; then
logger "$(basename $0) $TUN down, Restart will be executed"
ifconfig usb0 up
udhcpc -i usb0
break
fi
done
done
)2>&1 | logger -t $(basename $0)[$$]
EOF
chmod +x $SCRIPT
$SCRIPT > /dev/null 2>&1 &
#=======END tether-watchdog=========


Thanks a lot egc, it works like a charm.

I just changed the ping ip by the phone's tethering gateway ip since I want to monitor the connection between the router and the phone, not the Internet.
frankd84
DD-WRT Novice


Joined: 05 Feb 2023
Posts: 12

PostPosted: Sat Feb 11, 2023 14:36    Post subject: Reply with quote
frankd84 wrote:
Quote:
To give you a head start something like this, Administration/Commands and Save as Startup
Code:
#=======BEGIN tether-watchdog=========
sleep 60
SCRIPT="/tmp/tether-watchdog.sh"
cat << "EOF" > $SCRIPT
#!/bin/sh
(
SLEEP=120 # time (in secs) between each pass, do not set lower than 120 this gives you the ability to login and remove script from startup
#DEBUG= # uncomment/comment to enable/disable debug mode
PINGIP="8.8.8.8" # Target IP to ping to

[ ${DEBUG+x} ] && set -x
logger "Start $(basename $0)"
while sleep $SLEEP; do
logger "sleep $SLEEP $(basename $0)"
TUN=$(get_wanface)
while ! ping -qc1 -W6 -n $PINGIP -I $TUN &> /dev/null; do
sleep 9
if ! ping -qc1 -W6 -n $PINGIP -I $TUN &> /dev/null; then
logger "$(basename $0) $TUN down, Restart will be executed"
ifconfig usb0 up
udhcpc -i usb0
break
fi
done
done
)2>&1 | logger -t $(basename $0)[$$]
EOF
chmod +x $SCRIPT
$SCRIPT > /dev/null 2>&1 &
#=======END tether-watchdog=========


Thanks a lot egc, it works like a charm.

I just changed the ping ip by the phone's tethering gateway ip since I want to monitor the connection between the router and the phone, not the Internet.


Finally, the connection seems to drop and coming back each 120 seconds. The IP address to ping is good so I don't know what is going on.

Where can I see the debug output from the router's webpage (if possible)? Do I need to go through SSH?

Thank you very much! Wink
matjazk
DD-WRT User


Joined: 21 Aug 2019
Posts: 120
Location: Here, There And Everywhere

PostPosted: Sun Feb 12, 2023 12:13    Post subject: Reply with quote
@frankd84
Which router are you using that has support for Android tethering? As discussed in another thread, quote, "Option has not been added to date on any device that I'm aware of".
frankd84
DD-WRT Novice


Joined: 05 Feb 2023
Posts: 12

PostPosted: Sun Feb 12, 2023 21:10    Post subject: Reply with quote
matjazk wrote:
@frankd84
Which router are you using that has support for Android tethering? As discussed in another thread, quote, "Option has not been added to date on any device that I'm aware of".


As far as I know, there is no official support for that. Like I said in my first post, I followed this wiki page:
https://wiki.dd-wrt.com/wiki/index.php/Cellular_Phone/USB_Modem_as_WAN_connection

And the router I use is a Linksys WRT1900AC
matjazk
DD-WRT User


Joined: 21 Aug 2019
Posts: 120
Location: Here, There And Everywhere

PostPosted: Mon Feb 13, 2023 8:07    Post subject: Reply with quote
@frankd84 Thanks for clarification. I couldn't find the modules from the guide in any Atheros-based router that I have, but they do exist in Linksys WRT1200, which is, as is your WRT1900, Marvell-based. Maybe this thread should be moved to Marvell forum.
frankd84
DD-WRT Novice


Joined: 05 Feb 2023
Posts: 12

PostPosted: Mon Feb 13, 2023 13:21    Post subject: Reply with quote
matjazk wrote:
... but they do exist in Linksys WRT1200, which is, as is your WRT1900, Marvell-based. Maybe this thread should be moved to Marvell forum.


Originally, this thread was started in Advanced Network but was moved by someone else here. However, I didn't mention the router model on this post before... so my bad Sad

Mod note 04.06.24: Topic moved to Marvell (for now), should've been left in Advanced Networking. -kp69
Display posts from previous:    Page 1 of 1
Post new topic   Reply to topic    DD-WRT Forum Index -> Marvell MVEBU based Hardware (WRT1900AC etc.) All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum