raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

USB 3G Dongle Disconnecting

Wed Jan 17, 2018 8:45 am

Hi all,

I come to you humbly at the end of my tether, teetering on the brink of insanity :lol:

Here is the situation:

A small service my business provides runs off a Raspberry Pi Zero W.

It is set up with usb_modeswitch using a Huawei k4203 and the following configuration:

/etc/udev/rules.d/40-usb_modeswitch.rules

Code: Select all

# Huawei k4203
ACTION=="add", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1f1c", RUN+="/usr/sbin/usb_modeswitch -v 12d1 -p 1f1c -W -M 55534243123456780000000000000011062000000101000100000000000000"
ACTION=="add", SUBSYSTEM=="net", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1590", NAME="4gmodem", RUN+="/root/modem-up.sh"
ACTION=="remove", KERNEL=="4gmodem", RUN+="/root/modem-down.sh"
/root/modem-down.sh

Code: Select all

#!/bin/bash
# modem-down.sh
/usr/bin/systemctl restart openvpn@raspz1
/usr/bin/rfkill unblock wifi
/usr/bin/ip link set WIRELESS_INTERFACE up
/root/modem-up.sh

Code: Select all

#!/bin/bash
# modem-up.sh
/usr/bin/rfkill block wifi
#/usr/bin/netctl restart 4gmodem-PROFILE
# Optional
#/usr/bin/ping -c 1 -w 60 8.8.8.8 &&
/usr/bin/systemctl restart openvpn@raspz1
/etc/usb_modeswitch.d/12d1\:1f1c

Code: Select all

# Vodafone / Huawei K4203
DefaultVendor=0x12d1
DefaultProduct=0x1f1c
#DefaultProduct=0x14fb
TargetVendor=0x12d1
TargetProductList="157a,1590"
MessageContent="55534243123456780000000000000011062000000101000100000000000000"
HuaweiNewMode=1
The issue is that sometimes the dongle disconnects from the internet - I can't SSH into it, it disconnects from my VPN and clients get annoyed.
When I'm at the office, no big deal - I just pull out the dongle, shove it back in and it works again.

Alternatively, I can turn off the power at the wall and once loaded again, it will reconnect and work.

However, I'm currently travelling overseas and (trying) to have a holiday (my family keeps asking me to get off the computer as I spend hours searching for a solution).

So in essence, I need a way to remotely get the dongle to reconnect to the web via a script of some sort.

Things I have tried:

-> A script that regularly pings the web, and if it doesn't hit google.com , reboots the pi.

This doesn't work. For reasons I can't seem to grasp, a software reboot does not seem to restart the connection. I have a feeling this may be because it does not cut power to the dongle like a full reboot or pulling out the dongle does.

-> Cutting power to the dongle

I tried cutting the power to the dongle using the following script:

Code: Select all

echo 0 > /sys/devices/platform/soc/20980000.usb/buspower
sleep 5
echo 1 > /sys/devices/platform/soc/20980000.usb/buspower
This does indeed cut the power, but only momentarily (e.g. it will not stay off until I send the "echo 1", but instead the device will flash blue a few times then resume its current state.)

As a point of note, when you first plug in the dongle physically, it will flash green a few times before turning blue - but it doesn't do this with the above script.

-> all variations of ifconfig 4gmodem down && up

Does not seem to do anything.

-> /etc/init.d/networking restart
- doesn't seem to do anything

Something I think could work:

I have had this idea for a few days, but the risk is if I'm wrong, the pi will remain disconnected from the internet and I won't have any way of fixing it until I return home - which is not good haha

Code: Select all

     echo "rebooting internet"
      #remove lines from modeswitch so it won't enable modem mode when plugged in.
      sudo rm /etc/udev/rules.d/40-usb_modeswitch.rules
      #reboot dongle
      sudo echo 0 > /sys/devices/platform/soc/20980000.usb/buspower
      sleep 5
      sudo echo 1 > /sys/devices/platform/soc/20980000.usb/buspower
      #modem will hopefully now be flashing green (in storage mode, not modem)
      #write to file
      sudo cat <<EOT >> /etc/udev/rules.d/40-usb_modeswitch.rules
      # Huawei k4203
      ACTION=="add", ATTR{idVendor}=="12d1", ATTR{idProduct}=="1f1c", RUN+="/usr/sbin/usb_modeswitch -v 
     12d1 -p 1f1c -W -M 55534243123456780000000000000011062000000101000100000000000000"
      ACTION=="add", SUBSYSTEM=="net", ATTRS{idVendor}=="12d1", ATTRS{idProduct}=="1590", 
      NAME="4gmodem", RUN+="/root/modem-up.sh"
      ACTION=="remove", KERNEL=="4gmodem", RUN+="/root/modem-down.sh"
     EOT
     #reboot dongle again with mode_switch reconfigured
      sudo echo 0 > /sys/devices/platform/soc/20980000.usb/buspower
      sleep 5
      sudo echo 1 > /sys/devices/platform/soc/20980000.usb/buspower
      # Device should now reboot into modem mode
The idea with the above code is that I noticed while setting up the dongle, that when not is modem mode it flashes green (such as when you first plug it into the device, before it switches blue)
So the above code essentially 'breaks' usb_modeswitch, reboots the dongle where it will hopefully go into storage mode, and then reverts the process.

I think it may work, but as i said, a bit too risky from this far away.

Does anyone have thoughts or ideas about how I could script disconnect/reconnecting the 3g Dongle?

Thanks

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Thu Jan 18, 2018 12:30 am

Have also tried to make the power cut script run longer with both continuous echo 0 commands, and larger sleep times etc - to no avail

sparkie777
Posts: 118
Joined: Tue Nov 27, 2012 4:37 am

Re: USB 3G Dongle Disconnecting

Thu Jan 18, 2018 10:08 am

I use one of my RPi3s as router between mobile networks and local WIFI. OS is raspbian (stretch) based, modem is: Huawei E3372

Out of curiosity I simply rebootet (init 6) and watched the modem LED. It goes completely off for a while and after this starts with blinking at higher frequency (indicating it starts searching for mobile networks). So my conclusion is that the power is cut off during the reboot for at least a short time.

Are you sure your modem stays online during reboot?

The E3372 works like a charm:-) I rather recommend it.

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Thu Jan 18, 2018 11:13 am

Hey Sparkie!

I had to give it a quick google between init 6 and normal shutdown cause I’d only done /shutdown -r now and sudo reboot.

If it cuts power on yours, I will give it a try with init 6 this evening!!

Will keep you updated!

sparkie777
Posts: 118
Joined: Tue Nov 27, 2012 4:37 am

Re: USB 3G Dongle Disconnecting

Thu Jan 18, 2018 4:14 pm

possibly it matters you use a Pi Zero W. I only could try with my RPi3. Besides that maybe there is a difference between the 2 Micro USB ports on your Pi Zero W? Anyway, good luck!

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Fri Jan 19, 2018 2:47 am

Hi mate,

Update - init 6 does not work.

Hmm could be the pi zero - I believe the usb port is directly connected to the power

sparkie777
Posts: 118
Joined: Tue Nov 27, 2012 4:37 am

Re: USB 3G Dongle Disconnecting

Fri Jan 19, 2018 3:56 am

usb_modeswitch provides some reset functionality. Did you already try that?

Code: Select all

usb_modeswitch -R -v 19d2 -p 1010
taken from:
Resetting Vodafone USB mobile broadband device with usb_modeswitch

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Fri Jan 19, 2018 6:44 am

Heya!

Hmm that's interesting! I had googled for some sort of reset for modeswitch but hadn't found anything.
I will script that in to try it next time it happens.

Thanks for your help bud!
Fingers crossed!!

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Fri Jan 19, 2018 11:26 am

Unfortunately, it doesnt seem to work.

I received this output

Code: Select all

Look for default devices ...
   product ID matched
 Found devices in default mode (1)
Access device 021 on bus 001
Get the current device configuration ...
Current configuration number is 1
Use interface number 0
 with class 2

USB description data (for identification)
-------------------------
Manufacturer: Vodafone(Huawei)
     Product: HUAWEI Mobile
  Serial No.: not provided
-------------------------
Warning: no switching method given. See documentation
Reset USB device .
 Device was reset
-> Run lsusb to note any changes. Bye!
but it didn;t reconnect

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Fri Jan 19, 2018 12:48 pm

Maybe someone knows how to manually trigger the modem back to storage mode, and then back again?

raspz1
Posts: 16
Joined: Wed Jan 17, 2018 8:17 am

Re: USB 3G Dongle Disconnecting

Sat Jan 20, 2018 3:00 am

Ok! So I managed to get the Pi to reconnect with the script I was scared to use (in case anyone else has this problem).

However now I have a new problem...once reconnected, the OpenVPN won't reconnect.

I get:

Code: Select all

PING www.google.com (192.168.9.1) 56(84) bytes of data.
64 bytes from vodafonemobile.vmb (192.168.9.1): icmp_seq=1 ttl=64 time=0.887 $

--- www.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.887/0.887/0.887/0.000 ms
#connected to internet - can ping google^

reconnect openvpn
Sat Jan 20 10:09:54 2018 Unrecognized option or missing or extra parameter(s)$
Sat Jan 20 10:09:54 2018 OpenVPN 2.4.0 arm-unknown-linux-gnueabihf [SSL (Open$
Sat Jan 20 10:09:54 2018 library versions: OpenSSL 1.0.2l  25 May 2017, LZO 2$
Sat Jan 20 10:09:54 2018 Outgoing Control Channel Authentication: Using 256 b$
Sat Jan 20 10:09:54 2018 Incoming Control Channel Authentication: Using 256 b$
Sat Jan 20 10:09:54 2018 TCP/UDP: Preserving recently used remote address: [A$
Sat Jan 20 10:09:54 2018 Socket Buffers: R=[163840->163840] S=[163840->163840]
Sat Jan 20 10:09:54 2018 UDP link local: (not bound)
Sat Jan 20 10:09:54 2018 UDP link remote: [AF_INET]45.79.167.232:1194
Sat Jan 20 10:09:54 2018 write UDP: Network is unreachable (code=101)
Sat Jan 20 10:09:54 2018 Network unreachable, restarting
Sat Jan 20 10:09:54 2018 SIGUSR1[soft,network-unreachable] received, process $
Sat Jan 20 10:09:54 2018 Restart pause, 5 second(s)
Sat Jan 20 10:09:59 2018 TCP/UDP: Preserving recently used remote address: [A$
Sat Jan 20 10:09:59 2018 Socket Buffers: R=[163840->163840] S=[163840->163840]
Sat Jan 20 10:09:59 2018 UDP link local: (not bound)
Sat Jan 20 10:09:59 2018 UDP link remote: [AF_INET]45.79.167.232:1194
Sat Jan 20 10:09:59 2018 write UDP: Network is unreachable (code=101)
Sat Jan 20 10:09:59 2018 Network unreachable, restarting
Sat Jan 20 10:09:59 2018 Network unreachable, restarting
Sat Jan 20 10:09:59 2018 SIGUSR1[soft,network-unreachable] received, process $
Sat Jan 20 10:09:59 2018 Restart pause, 5 second(s)
Sat Jan 20 10:10:04 2018 TCP/UDP: Preserving recently used remote address: [A$
Sat Jan 20 10:10:04 2018 Socket Buffers: R=[163840->163840] S=[163840->163840]
Sat Jan 20 10:10:04 2018 UDP link local: (not bound)
Sat Jan 20 10:10:04 2018 UDP link remote: [AF_INET]45.79.167.232:1194
Sat Jan 20 10:11:04 2018 TLS Error: TLS key negotiation failed to occur withi$
Sat Jan 20 10:11:04 2018 TLS Error: TLS handshake failed
Sat Jan 20 10:11:04 2018 SIGUSR1[soft,tls-error] received, process restarting
Sat Jan 20 10:11:04 2018 Restart pause, 5 second(s)
Sat Jan 20 10:11:09 2018 TCP/UDP: Preserving recently used remote address: [A$
Sat Jan 20 10:11:09 2018 Socket Buffers: R=[163840->163840] S=[163840->163840]
Sat Jan 20 10:11:09 2018 UDP link local: (not bound)
Sat Jan 20 10:11:09 2018 UDP link remote: [AF_INET]45.79.167.232:1194
Sat Jan 20 10:12:09 2018 TLS Error: TLS key negotiation failed to occur withi$
Sat Jan 20 10:12:09 2018 TLS Error: TLS handshake failed
Sat Jan 20 10:12:09 2018 SIGUSR1[soft,tls-error] received, process restarting
Sat Jan 20 10:12:09 2018 Restart pause, 5 second(s)
Sat Jan 20 10:12:14 2018 TCP/UDP: Preserving recently used remote address: [A$
Sat Jan 20 10:12:14 2018 Socket Buffers: R=[163840->163840] S=[163840->163840]
Sat Jan 20 10:12:14 2018 UDP link local: (not bound)
Sat Jan 20 10:12:14 2018 UDP link remote: [AF_INET]45.79.167.232:1194
Sat Jan 20 10:13:14 2018 TLS Error: TLS key negotiation failed to occur withi$
Sat Jan 20 10:13:14 2018 TLS Error: TLS handshake failed
Which just loops over and over.

client.conf

Code: Select all

client
dev tun
proto udp
sndbuf 0
rcvbuf 0
remote 45.79.167.232 1194
resolv-retry infinite
nobind
persist-key
persist-tun
remote-cert-tls server
auth SHA256
cipher AES-256-CBC
comp-lzo
setenv opt block-outside-dns
key-direction 1
verb 3
keepalive 30 120
server.conf

Code: Select all

port 1194
proto udp
dev tun
sndbuf 0
rcvbuf 0
ca ca.crt
cert server.crt
key server.key
dh dh.pem
auth SHA256
tls-auth ta.key 0
topology subnet
server 10.8.7.0 255.255.255.0
ifconfig-pool-persist ipp.txt
;push "redirect-gateway def1 bypass-dhcp"
;push "dhcp-option DNS 50.116.53.5"
;push "dhcp-option DNS 50.116.58.5"
;push "dhcp-option DNS 50.116.61.5"
keepalive 10 120
cipher AES-256-CBC
comp-lzo
user nobody
group nobody
persist-key
persist-tun
status openvpn-status.log
log openvpn.log
verb 3
crl-verify crl.pem
iptables -L

Code: Select all

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     udp  --  anywhere             anywhere             udp dpt:openvpn
ACCEPT     all  --  10.8.0.0/24          anywhere            

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     all  --  anywhere             anywhere             state RELATED,ESTABLISHED
ACCEPT     all  --  anywhere             anywhere            
ACCEPT     all  --  anywhere             anywhere            

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination  
Rebooting the Pi by removing Dongle or By Power off at wall again solves problem, however soft reboot with both sudo reboot, sbin/shutdown and sbin/init 6 does not.

Interestingly, I also have the Raspberry Pi configured to make a reverse tunnel to the server regularly (was helpful when attempting to troubleshoot pi issues), however that won't connect either now. Again, rebooting makes it work.

Everything I google on this reconnect issue seems to say it's either a firewall or a NAT issue.
However, it's using a cell 3g connection and seems to work most of the time fine for hours... until it just stops.
I know 3g connections have complex NAT settings, but is there a way around this?

Return to “Troubleshooting”

Who is online

Users browsing this forum: Baidu [Spider] and 44 guests