Browsing around I found the pieces of this solution, and I put them together in a guide.
I did not use the guide in the Raspberry site since I found it complicate to make it compatible with the mobile dongle, and I used instead the NetworkManager daemon, following many advices in that sense I found in technical blogs. The problem with this solution is that, as of now, it is incompatible with the native solution in the Raspian distribution, and so I removed some native network tools. This is relevant if you plan to alter the network configuraton of the Raspberry, but it is otherwise transparent.
The reason why I developed this solution is to have an autonomous IoT concentrator device; as succh, it does not provide Internet access to devices connected to the RPi through WiFi or wired Ethernet. In the past I extended this project to give Internet access to a small classroom (10 students) not served by the Internet through the RPi. This is obtained by enabling and configuring packet forwarding into the RPi, which is not covered in this gist. There are many guides in the Internet about that, but remember that the solution should preferably use the NetworkManager toolset (i.e., nmcli) in order to alter the RPi networking configuration with NAT capabilities.
To have an idea of the capabilities of the RPi as a concentrator for WiFi sensors, consider that the WiFi range, measured using a WEMOS D1 R1, is little more than 30 meters in line of sight (-70dB).
Now you have two altrernatives: to follow the three steps Fast track, or to go to the Step by step guide; excluding the time to download the image file, it will take about half an hour on the computer, with a lot of free time for you. In both cases, when you have finished proceed to the So what? final section.
- Flash an SD with "Raspbian Buster Lite"
- Configure SSID, PSK and APN in the MobileModem.sh script
- Run the MobileModem.sh script as root on the Raspberry
- Skip to "So what?"
Materials I used (many variants are possible):
- a computer (Ubuntu 19.04) connected to LAN with Internet access
- an additional Ethernet plug cable on the same LAN
- the image for Raspbian 10 (from here)
- a SD to USB adapter
- a 4GB SD card
- a Raspberry PI 3 Model B V1.2
- a TP-LINK MA 260 Mobile Modem USB stick (3G HSPA+)
- a SIM card with data traffic
I used a 4 GB SD card for the task, leaving more than half of it free for data or additional packages. Use the SD to USB adapter on your PC to flash the card using Etcher. Before unmounting the SD from your PC, open the "boot" filesystem in your file manager and create an empty file named "ssh".
Insert the SD into the RPi and connect it to the LAN using the Ethernet plug.
Power the RPi with a suitable power supply: do not branch it to the computer USB, it is not sufficient.
Find the internet address of your RPi with the following command:
$ nmap -p 22 --open -sV xxx.xxx.xxx.xxx/xx | less
where the xxx.xxx.xxx.xxx/xx stands for the Internet address of your LAN, that you should know. Just in case, you can find it with:
ip address | grep global
Find the sequence of lines that refer to your RPi in the output of the nmap command (it takes a while to complete, be patient). Look for the "Raspbian" word and find some lines like the following:
Nmap scan report for <RPi address>
Host is up (0.088s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.9p1 Raspbian 10 (protocol 2.0)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
and annotate the address that appears on the first line (here and in the following it is replaced with )
Now copy your public key on the RPi:
ssh-copy-id pi@<RPi address>
using the pi user password, which is "raspberry".
On your PC open the MobileModem.sh script with a text editor and configure the three variables SSID, PSK and APN. Next copy the MobileModem.sh script on the RPi:
scp MobileModem.sh pi@<RPi address>:
(mind the final ":" in the command).
Log into your RPi using its IP address:
ssh pi@<RPi address>
No password needed, but you should change the default "raspberry" password as soon as possible.
When logged into the RPi (please check the command prompt "pi@raspberrypi:~ $ ") run the script:
pi@raspberrypi:~ $ sudo bash MobileModem.sh
At the end the Raspberry will automatically reboot.
While the Raspberry is booting up, you prepare the Mobile Modem USB dongle with the SIM card and you plug it into a USB port of the RPi. Wait for the green light on the modem and then ssh into the RPi with the usual command:
me@home:~ $ ssh pi@<RPi address>
Check that routes are correct:
pi@raspberrypi:~ $ route
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
default 10.40.87.189 0.0.0.0 UG 700 0 0 wwan0
10.40.87.188 0.0.0.0 255.255.255.252 U 700 0 0 wwan0
10.42.0.0 0.0.0.0 255.255.255.0 U 600 0 0 wlan0
192.168.113.0 0.0.0.0 255.255.255.0 U 100 0 0 eth0
Verify Internet connection:
pi@raspberrypi:~ $ ping -Iwwan0 www.example.com
PING www.example.com (93.184.216.34) from 10.40.87.190 wwan0: 56(84) bytes of data.
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=1 ttl=51 time=548 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=2 ttl=51 time=509 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=3 ttl=51 time=477 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=4 ttl=51 time=487 ms
^C
--- www.example.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 477.325/505.087/547.943/27.216 ms
Finally verify the presence of the new WiFI hotspot using a WiFi capable device (smartphone, PC etc.). Avoid joining a non-IoT device to the hotspot in case you use an IoT SIM in the modem, since such devices produce a lot of hidden traffic that might rapidly consume you credit. It's better to develop and test using an ordinary SIM.
At that point you can still ssh into the Raspberry through the LAN, but the connection to the Internet is through the mobile network: take this into account if you plan heavy traffic, since this would consume SIM credit. Instead, remove the mobile modem from the USB and enable the Ethernet port with the following command (on one line, do not split into two lines):
sudo dhclient -r eth0; sudo dhclient eth0
The effects disappear with a reboot.
The script has been tested one (1) time. Take any precaution you deem appropriate.
-
The hotspot configuration is taken from here .
-
More about mobile modem utilization is found in an Ubuntu guidenetwork-manager/docs/configure-cellular-connections .
Thank you for your reply.
I managed to get it working by adjusting the routing configurations by doing: