A20-OLinuXino-Lime2 as GPRS modem for unattended use

Started by mbosschaert, May 29, 2020, 12:52:48 PM

Previous topic - Next topic

mbosschaert

Hi,
I'm trying to build a system to remotely monitor my holiday house. There is no telephone landline but 4G GSM/GPRS is fairly good. Over the last 2 years I did some testing but have not been able to build a solid system.

The hardware I used:
  • A2-OlinuXino-Lime2
  • MOD-USBG3
  • MOD-CAP
  • MOD-WIFI-AR9271
  • BATTERY-LIPO6600mAh


The software used:
  • a20-lime2_mainline_uboot_sunxi_kernel_3.4.103_jessie_eMMC_rel_15.img
  • wvdial
  • hostapd
  • and all required drivers for the hardware, like atheros-firmware,etc
  • usb-modeswitch (to make sure the MOD-USB3G is recognized as modem, not as storage)

With this setup the system usually remained stable for a couple of days or weeks, but suffered from frequent drops in ppp connection. To ultimately be able to have connection on a daily basis I programmed random reboots and random MAC-changing as the GSM provider apparently does not like continuous connections.

As finally this system was not reliable enough (completely failed to connect to the provider after some weeks with no apparent causes in the log files) I decided to rebuild it with the newest buster image of Olimex (A20-OLinuXino-buster-minimal-20200417-095756). Also I moved from wvdial to pppconfig as I could not solve the Device-busy warnings other than by rebooting.

So currently I'm rebuilding the system and I'm at the point that the wifi accesspoint (hostapd, iptables maquerading and dnsmasq) works fine. The pppd configuration, triggered by pppconfig, works by starting and stopping with pon/poff. And the GPRS connection seems to be fairly stable, as far as tested. Actually this topic is written while connected through the system which now actually functions as a wifi/GPRS router. The only hurdle I have to take now is the fact that the device (ttyUSB0) is not ready at the moment that the network interface ppp0 is activated. Even though the interface is configured as auto-start (auto ppp0), and pppd is configured as 'persistent' the connection is not initiated.

How can I get around this and make sure that /dev/ttyUSB0 is registered before pppd gets started.

Here some backgound info:
dmesg | grep ttyUSB:

May 26 22:49:37 A20-OLinuXino-HA-001 pppd[998]: Connect: ppp0 <--> /dev/ttyUSB0
May 26 22:50:35 A20-OLinuXino-HA-001 pppd[1158]: Connect: ppp0 <--> /dev/ttyUSB0
May 28 23:56:13 A20-OLinuXino-HA-001 kernel: [   29.136033] usb 4-1: GSM modem (1-port) converter now attached to ttyUSB0
May 28 23:56:13 A20-OLinuXino-HA-001 kernel: [   29.137834] usb 4-1: GSM modem (1-port) converter now attached to ttyUSB1
May 28 23:56:13 A20-OLinuXino-HA-001 kernel: [   29.141601] usb 4-1: GSM modem (1-port) converter now attached to ttyUSB2
May 28 23:56:33 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702993.9922] modem["ttyUSB2"]: modem state changed, 'disabled' --> 'enabling' (reason: user preference)
May 28 23:56:33 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702993.9943] manager: (ttyUSB2): new Broadband device (/org/freedesktop/NetworkManager/Devices/6)
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702993.9975] device (ttyUSB2): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702994.0015] device (ttyUSB2): modem state 'enabling'
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702994.0120] device (ttyUSB2): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702994.8718] modem["ttyUSB2"]: modem state changed, 'enabling' --> 'searching' (reason: user-requested)
May 28 23:57:56 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590703076.3326] modem["ttyUSB2"]: modem state changed, 'searching' --> 'registered' (reason: unknown)

root@A20-OLinuXino-HA-001:/var/log# cat /etc/network/interfaces.d/ppp0
allow-hotplug ppp0
auto ppp0
iface ppp0 inet ppp
provider myProvider

ppp-configuration
cat /etc/ppp/chap-secrets
ppp     *       ppp
cat /etc/ppp/options
asyncmap 0
auth
crtscts
lock
hide-password
modem
lcp-echo-interval 30
lcp-echo-failure 4
noipx
cat /etc/ppp/pap-secrets
*       hostname        ""      *
guest   hostname        "*"     -
master  hostname        "*"     -
root    hostname        "*"     -
support hostname        "*"     -
stats   hostname        "*"     -
"ppp" myProvider "ppp"
ppp     *       ppp
cat /etc/ppp/peers/myProvider
hide-password
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/myProvider"
debug
/dev/ttyUSB0
230400
defaultroute
noipdefault
user "ppp"
remotename myProvider
ipparam myProvider
persist
usepeerdns
/dev/ttyUSB0
cat /etc/chatscripts/myProvider
ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED
'' ATZ
OK AT+CGDCONT=1,"IP","internet.myProvider.com","0.0.0.0",0,0
OK-AT-OK "ATDT*99*#"
CONNECT \d\c

Just for the context: if this is solved, the next steps will be to configure mosquitto (and my mosquitto clients who report status of mains power, temperature, etc) and to build 2 ssh tunnels to my local server. One tunnel to safely communicate mqtt messages. The other tunnel will be 'reverse' to enable to login from my local server and perform maintenance. Reason for the necessity remote tunnel is that my GPRS provider will not give me a fixed IP address.

sumoxo

#1
Quote from: mbosschaert on May 29, 2020, 12:52:48 PMHi,
I'm trying to build a system to remotely monitor my holiday house. There is no telephone landline but 4G GSM/GPRS is fairly good. Over the last 2 years I did some testing but have not been able to build a solid system.

The hardware I used:
  • A2-OlinuXino-Lime2
  • MOD-USBG3
  • MOD-CAP
  • MOD-WIFI-AR9271
  • BATTERY-LIPO6600mAh


The software used:
  • a20-lime2_mainline_uboot_sunxi_kernel_3.4.103_jessie_eMMC_rel_15.img
  • wvdial
  • hostapd
  • and all required drivers for the hardware, like atheros-firmware,etc
  • usb-modeswitch (to make sure the MOD-USB3G is recognized as modem, not as storage)

With this setup the system usually remained stable for a couple of days or weeks, but suffered from frequent drops in ppp connection. To ultimately be able to have connection on a daily basis I programmed random reboots and random MAC-changing as the GSM provider apparently does not like continuous connections.

As finally this system was not reliable enough (completely failed to connect to the provider after some weeks with no apparent causes in the log files) I decided to rebuild it with the newest buster image of Olimex (A20-OLinuXino-buster-minimal-20200417-095756). Also I moved from wvdial to pppconfig as I could not solve the Device-busy warnings other than by rebooting.

So currently I'm rebuilding the system and I'm at the point that the wifi accesspoint (hostapd, iptables maquerading and dnsmasq) works fine. The pppd configuration, triggered by pppconfig, works by starting and stopping with pon/poff. And the GPRS connection seems to be fairly stable, as far as tested. Actually this topic is written while connected through the system which now actually functions as a wifi/GPRS router. The only hurdle I have to take now is the fact that the device (ttyUSB0) is not ready at the moment that the network interface ppp0 is activated. Even though the interface is configured as auto-start (auto ppp0), and pppd is configured as 'persistent' the connection is not initiated.

How can I get around this and make sure that /dev/ttyUSB0 is registered before pppd gets started.

Here some backgound info:
dmesg | grep ttyUSB:

May 26 22:49:37 A20-OLinuXino-HA-001 pppd[998]: Connect: ppp0 <--> /dev/ttyUSB0
May 26 22:50:35 A20-OLinuXino-HA-001 pppd[1158]: Connect: ppp0 <--> /dev/ttyUSB0
May 28 23:56:13 A20-OLinuXino-HA-001 kernel: [  29.136033] usb 4-1: GSM modem (1-port) converter now attached to ttyUSB0
May 28 23:56:13 A20-OLinuXino-HA-001 kernel: [  29.137834] usb 4-1: GSM modem (1-port) converter now attached to ttyUSB1
May 28 23:56:13 A20-OLinuXino-HA-001 kernel: [  29.141601] usb 4-1: GSM modem (1-port) converter now attached to ttyUSB2
May 28 23:56:33 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702993.9922] modem["ttyUSB2"]: modem state changed, 'disabled' --> 'enabling' (reason: user preference)
May 28 23:56:33 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702993.9943] manager: (ttyUSB2): new Broadband device (/org/freedesktop/NetworkManager/Devices/6)
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702993.9975] device (ttyUSB2): state change: unmanaged -> unavailable (reason 'managed', sys-iface-state: 'external')
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702994.0015] device (ttyUSB2): modem state 'enabling'
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702994.0120] device (ttyUSB2): state change: unavailable -> disconnected (reason 'none', sys-iface-state: 'managed')
May 28 23:56:34 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590702994.8718] modem["ttyUSB2"]: modem state changed, 'enabling' --> 'searching' (reason: user-requested)
May 28 23:57:56 A20-OLinuXino-HA-001 NetworkManager[561]: <info>  [1590703076.3326] modem["ttyUSB2"]: modem state changed, 'searching' --> 'registered' (reason: unknown)

root@A20-OLinuXino-HA-001:/var/log# cat /etc/network/interfaces.d/ppp0
allow-hotplug ppp0
auto ppp0
iface ppp0 inet ppp
provider myProvider

ppp-configuration
cat /etc/ppp/chap-secrets
ppp    *      ppp
cat /etc/ppp/options
asyncmap 0
auth
crtscts
lock
hide-password
modem
lcp-echo-interval 30
lcp-echo-failure 4
noipx
cat /etc/ppp/pap-secrets
*      hostname        ""      *
guest  hostname        "*"    -
master  hostname        "*"    -
root    hostname        "*"    -
support hostname        "*"    -
stats  hostname        "*"    -
"ppp" myProvider "ppp"
ppp    *      ppp
cat /etc/ppp/peers/myProvider
hide-password
noauth
connect "/usr/sbin/chat -v -f /etc/chatscripts/myProvider"
debug
/dev/ttyUSB0
230400
defaultroute
noipdefault
user "ppp"
remotename myProvider
ipparam myProvider
persist
usepeerdns
/dev/ttyUSB0
cat /etc/chatscripts/myProvider
ABORT BUSY ABORT 'NO CARRIER' ABORT VOICE ABORT 'NO DIALTONE' ABORT 'NO DIAL TONE' ABORT 'NO ANSWER' ABORT DELAYED
'' ATZ
OK AT+CGDCONT=1,"IP","internet.myProvider.com","0.0.0.0",0,0
OK-AT-OK "ATDT*99*#"
CONNECT \d\c

Just for the context: if this is solved, the next steps will be to configure mosquitto (and my mosquitto clients who report status of mains power, temperature, etc) and to build 2 ssh tunnels to my local server. One tunnel to safely communicate mqtt messages. The other tunnel will be 'reverse' to enable to login from my local server and perform maintenance. Reason for the necessity remote tunnel is that my GPRS provider will not give me a fixed IP address.

Any update on this OP? I'm having the same issue https aka ms remoteconnect and there's no reason to create a same topice twice.

mbosschaert

Sorry for my late reply.
On my remote server I completely moved my GPRS connection to an GPRS-USB modem/router which identifies itself as eth1. This completely solved the problem of the unstable ppp connection. The connection is now completely taken care of by the USB device (USB device:ID 12d1:14dc Huawei Technologies Co., Ltd. E33372 LTE/UMTS/GSM HiLink Modem/Networkcard).

I set up 2 SSH-tunnels after the network connection is established:
  • (for mqtt traffic): ssh -f -N -L 1884:localhost:1883 -p homeport homeIP
  • (as ssh backdoor): ssh -f -N -R homeSshport:localhost:22 -p homeport homeIP
Where homeport and homeSshport should be replaced by the portnumbers you defined for your home-server. Of course you can add additional options (like -o "ServerAliveInterval 120" to your wishes).

This allows me to, even though I cannot reach the server directly through its IP address, through the reverse tunnel on the local server (line 2) using the command ssh -l username -p homeSshport localhost.

Hope this helps
Cheers