-
Notifications
You must be signed in to change notification settings - Fork 0
Home
I scoured the internet trying to figure out how to get a cellular connection to the internet with a Raspberry Pi, and it was much more difficult than I expected. There aren't very many hardware solutions and all are surprisingly expensive. Eventually I decided to take a chance with the Waveshare HAT, which is basically just a carrier board for the SIM7600G module. I had expected some kind of more comprehensive integration with the Pi through the GPIO header pins, perhaps using I2C for example, but the interface mechanism here is AT commands via a USB port. This is some very elderly technology. AT commands harken back to the 1200 baud dial-up modem days from back in the 80's.
And then there is the software setup for this. Various websites attempt to describe how to do it and Waveshare themselves have a wiki site for it, but I can tell you that you don't want to be shooting AT commands to the device manually. Ideally the device will be plug-and-play in all circumstances. I finally realized that the ModemManager utility can handle the modem interactions for you, but you have to know exactly what to do. And even if you do get the modem up and running, you also need to have the routing and DNS set up so that it can reach the internet even when WiFi is disabled. In my experience you are likely to get dropouts on occasion due to poor signal strength, and this needs to be detected automatically and recovered.
Through hours of trial and error working with an AI coding assistant I was finally able to get the modem up and running reliably, the routes and DNS established, and automatic recovery after a dropout. It may not work with other modems, but I think the extensive suite of mmcli commands and techniques included here will be helpful for people in those cases as a start.
One challenge with these devices is that you will need a SIM card that lets you connect to an appropriate cellular service. Ideally that service won't cost you an arm and a leg monthly, but all you want is data so you may find a cheap plan. The service must also allocate an IPV4 address for your device, and I've found that not all of them will do that.
I recommend cellular resellers. These are second tier companies that tie into the major networks but cost a little less. A pre-paid plan is cheapest. At the present time I'm using US Mobile which is a reseller for both AT&T and Verizon. They have some relatively inexpensive plans and they will send you two SIM cards, one for each carrier. I'm using the AT&T (Dark Star) card, their network has very good coverage in the USA. AT&T gives you a static IP address from a pool of addresses that is assigned to you dynamically. These scripts handle that, but other services may do things differently and break the scripts.
The modem may lose connection to the cellular network at times, most likely due to weak signal. When that happens the Pi network stack will not reconnect automatically. The auto-recover.sh daemon in this project will handle that for you in the background.
The HAT came with the on-board jumpers attached correctly so I didn't have to rejigger them. You place your SIM card into a plastic carrier on the underside of the board, which can be unlatched for opening by pushing it sideways. You plug the board onto the GPIO header pins and plug in the included USB cable hooking the board to a port on the PI. You plug the included antenna cable onto a tiny socket labeled 'main'. The board will power up when the Pi boots, and there's a red 'net' LED that will turn on. This LED will start blinking when (if) the board gets signal! If it doesn't start blinking you will get nowhere, so you need to figure out why. Antenna not plugged in correctly? Unit needs to be repositioned? The carrier has lousy signal at your location?
You will need to know the APN (Access Point Name) for the carrier service you are using, and this is essential. You should be able to google it. Put that string in the CELLULAR_APN variable in the cellular-config.sh script.
If the board is powered up and blinking you are ready to proceed with the instructions in the setup guide. If setup succeeds you can run the monitoring script for a while to verify consistent connectivity. I find that even though the Pi can reach websites and services on the internet, and it does have a dynamically assigned IP address that you can know, it cannot act as a server. The cellular carriers will not route HTTP requests or other data to your IP address, they will only pass along responses. I find that you can establish a websocket connection however, which is bidirectional.
Recently I purchased one of these devices, they are about half the price of the SIM7600G. The SIM7080G is a NB-IoT/Cat-M modem and it purportedly runs at a data rate of up to up to 1 Mbps which could be adequate for many purposes. I installed it on a Pi and lsusb showed it in the USB device list. The net LED was blinking, it was seeing signal. After tweaking the scripts to handle its device signature I was able to get it up and running to the point where it was trying to register with the cellular carrier, but it never did succeed. Unfortunately it then started to intermittently fall off the USB list and become unreachable. I marked it off as a hardware failure and returned it, but the inability to register was a definite roadblock. It could be that the carrier I'm using does not support NB-IoT/Cat-M.