Lorank-8 gateway with 3G uplink connection - short howto included

For our project we’re deploying some Lorank-8 gateways around Amersfoort. Not all locations will have a wired internet connection available (e.g. random appartment buildings), so we’re looking to use a 3G connection as the uplink connection.

Seeing that the Lorank-8 is builtin around a Beaglebone Black and has a USB port available, it seems doable to just plug in a 3G USB stick, and use something like UMTSKeeper on the BBB directly to maintain the network connection (saving the need for another bit of hardware that does 3G -> Ethernet).

Anyone got some experience with a setup like this so far?

(I know that there are gateways that have 3G hardware built in, but we happen to have a few Lorank-8 gateways already and we rather like them)

@matthijs
What you can do is to leave the Lorank-8 “has is”, this would remove you some headaches of 3G/4G dongle and linux driver and take a external 3G/4G dedicated router such as this small TPLink ($25) that can be USB Powered.
http://www.tp-link.com/en/products/details/cat-4691_TL-MR3020.html

Putting 3G/34G dongle in this router, then you can wire Lorank to this router with wired ethernet connection, thus, router can also do Access point and some other interesting things.

I like using things doing what they’re made for, Lorank to Lora TpLink for routing :wink:

This one has 2 Ethernet port, cost is $16 and openwrt compatible

1 Like

We have done this by using a 3G Huawei Mobile Wifi device which has a physical port. The SIM card we use is one from bliep.nl, prepaid data.

In a few tests that we did it it worked just fine.

http://things.io/lorank-8-lora-gateway-gekoppeld-aan-3g-router/

Interesting, I always wondered what the approximate data use would be.

@Charles, @thingsio, thanks for your suggestions and extra information. However, I was really planning to remove the need for extra router and just connect a 3G dongle directly to the Lorank. That saves some cost, but more importantly makes the setup more self-contained and tidy to place somewhere (only needing a single power plug, no extra cables, etc.).

I ended up configuring this using the stock Debian ifupdown tools and ppp, which works well enough. Here’s a recap of what I did:

  • Install necessary packages:

     apt-get install ppp usb-modeswitch
    
  • Create configuration for pppd in the file /etc/ppp/peers/gprs:

     #Based on https://wiki.debian.org/Modem/3G#Installation_with_PPP_and_.2Fetc.2Fnetwork.2Finterfaces
     connect "/usr/sbin/chat -v -f /etc/chatscripts/gprs -T internet"
     /dev/ttyUSB0
     noipdefault
     defaultroute
     noauth
     usepeerdns
    
     # Keep the link alive
     lcp-echo-interval 30
     lcp-echo-failure 4
     lcp-echo-adaptive
    
     # Infinite retries
     maxfail 0
     # Time between retries
     holdoff 20
     # Keep running and automatically reconnect
     persist
    

    This lets pppd connect to the 3G modem’s serial port, use the
    gprs chatscript supplied by the ppp package to let the modem
    “dial” and then sets up a PPP connection. Whenever the connection
    breaks, it is restarted, which seems to work reliable enough for me
    now.

  • Modify /etc/network/interfaces to add:

     auto gprs
     iface gprs inet ppp
             provider gprs
    

This lets ifupdown start pppd on startup, using the above
configuration.

  • Create /etc/ppp/ip-up.d/ntpdate to update the current time after
    the PPP connection comes up (this was needed for the forwarder to run
    correctly IIRC).

     #!/bin/sh
    
     # Execute the ntpdate hook again. ifupdown will have ran it already, but
     # before the ppp connection is complete, making ntpdate fail.
     exec /etc/network/if-up.d/ntpdate
    
  • Set its mode to executable:

     chmod a+x /etc/ppp/ip-up.d/ntpdate
    

That’s it! This doesn’t seem to work with all 3G sticks, some might need
a different port than ttyUSB0 (most have multiple serial ports) or
might need a different chatscript. I also believe some (newer) 3G sticks
expose an USB ethernet interface instead of (or in addition to) a serial
port, which require some other commandline tool to set up a connection,
but I couldn’t make this work with the two sticks I had that support
this.

The above is intended for a Lorank8, but since that’s just a Beageboard with Debian on it, I suspect the same will apply to similar boards (including the Rasbperry Pi with Raspbian that a lot of people seem to be using).

Please provide the USB sticks that you used, saves some testing :slight_smile:

I also have a Lorank8 and I tried to repeat the steps you listed. Unfortunately my Lorank8 doesn’t connect automatically at start up. If I issue “ifup gprs” from the command line, then the gateway connects and the “ppp0” entry appears in “ifconfig”. Do you have any suggestion on what am I missing?

Thanks,

Interesting enough to be added to the doc!

I can’t easily look up the two sticks I’m currently using (the USB info does not provide enough details for these devices), but these are the ones that I still have lying around that worked:

  • E367u-1
  • K4510
  • E220

The X060s and K3520-Z didn’t work, but they didn’t show up as an USB device at all, so I suspect some kind of incompatibility with the beagleboard at the USB level there.

Do you have a network cable connected? I now remember that it appears that usb-modeswitch needs some time to make the ttyUSB0 device available, and if ifupdown tries to bring the interface up before that, it fails. However, when you do not have a network cable plugged in, and you have removed the wicd network daemon and let ifupdown handle DHCP on the network cable instead (as described here), the network startup is delayed by (IIRC) 60 seconds of trying to get a DHCP lease on the ethernet port, before the gprs interface is attempted, giving usb-modeswitch plenty of time to work.

It would perhaps be better if the configuration was changed so that ifupdown knows that it should act when ttyUSB0 becomes available, though I’m not sure if that’s supported directly (a udev rule would probably work, though).

TL;DR: Using the Huawei E3531i-2, I get plug-and-play 3G connectivity, no configuration required

Since posting this, I’ve found a much easier way to add 3G connectivity to a Lorank gateway: A Huawei Hi-link 3G stick.

“Normal” 3G modems offer a few serial ports and require the USB host to send some (not completely standardized) AT commands and set up a PPP connection. I’ve found that this is fragile, especially to guarantee proper reconnection on failures (I’ve tried Debian’s ifupdown and connman+ofono, neither of which were completely solid).

Some 3G modems from Huawei have “Hi-link”, which means they pose themselves as an USB ethernet adapter. The computer/Lorank can just do a DHCP request on that interface, which will then return an internal IP address. By navigating to the (internal) gateway address, the modem gives you a web interface to see the modem status and configure it.

The modem then takes care of setting up the 3G / PPP connection automatically, and also handles reconnection automatically. The internal IP does mean that there is an extra layer of NAT applied by the modem, but unless you really need a public IP, that shouldn’t really matter in practice.

Often, no configuration is needed at all: These modems seem to include a list of mobile providers with the needed APNs. If your provider is not listed, you might need to configure it manually (once, through the webinterface, afterwards it is remembered).

Configuration seems very limited and is mostly about the 3G side of things. The internal network is fixed to 192.168.8.x, and no port forwarding can be configured.

I’ve been testing this with a Huawei E3531i-2 (only €30), but similar things will apply to other Huawei Hi-link modems, and other manufacturers might have similar devices. Note that modem specifications in webshops often do not seem to mention that a modem uses Hi-link/usb ethernet, these things are really sold as black boxes it seems. Even the site of Huawei itself doesn’t seem to have this particular model listed…

As for using this modem with the Lorank: if the APN is autodetected or configured inside the modem, this is literally a matter of plug-and-play. The connman running on the Lorank sees a new ethernet interface and automatically brings it up. Even switching between ethernet and 3G seems to work (though I’m not sure what priority is used if both are plugged in).

Note that I tested using a clean Debian stretch image, but the Debian installation supplied with the Lorank also uses connman, so I expect it also works. Really old versions of the Lorank used wicd, I’m not sure if that works in the same way.

2 Likes

Two more additions to my previous post:

  • Turns out that usb-modeswitch is actually required, but apparently it was pre-installed on my Lorank. Just installing it is enough, a configuration is included for this 3G stick (at least in the Stretch version).
  • The 3G-stick seems to do aggressive power-saving, which causes a high latency (I’ve observed 300ms-600ms) on the first packet after a period of inactivity (in my testing, after 4-5 seconds already). In practice, this means that if a packet is also picked up by other gateways, the 3G-connected gateway misses the deduplication window, so it is not shown in the packet metadata. If no other gateways pick it up, I epxect 600ms should still be fast enough to allow a reply within 1000ms, though I did not test this. I’ve contacted Huawei to see if this powersaving can be disabled, but I’m not hopeful. A workaround that seems to work in a quick test is to run a ping command with a 3-4 second interval. It’s ugly, but only costs around 50MB/month, so that might be acceptable…