Barna Mink’s Homepage - Communicate with your Raspberry Pi server using SMS, a cellular modem and Redis

Barna Mink’s Homepage - Raspberry Pi + cellular + SMS + Redis

Raspi + cellular modem, connected to the LTE network


I run several Raspberry Pi servers in my home network, doing a whole host of useful things. I have long wanted to be able to use and communicate with these services when I’m on the go, but in a way that:

It took me surprisingly long to realize that the obvious solution was right in front of me and already a feature of my phone which I heavily use: text messages (SMS).

If I had a way to send texts to a phone number that’s connected to my network, then I could send commands to the various services (e.g. “add todo item”). Services could also reply to my commands using text messages (e.g. “OK, todo item added”), and also send me text messages on their own (e.g “reminder to buy groceries”).

SMS options

Apart from texting between humans, SMS is emerging as an important way to communicate with and between devices in the world of IoT and there are different ways to add SMS capability to a computer.

One route is to not use any hardware at all, but to use a gateway service, ie. a company that provides you with a “virtual” phone number and APIs you can use to send / receive messages via this phone number (and much other functionality). The one offering in this category that I explored in depth was Twilio. This would have been a workable route, though ultimately I felt it was more trouble than worth for something as simple as sending a text. My main dislikes:

The other route, of course, is the hardware route. Get a cellular modem for the Raspi, insert a SIM card from a suitable phone plan, write some simple software to talk to the modem and off we go. This seemed like a much more straightforward, and less error prone (not to mention, more fun) way to go.

Phone plan / SIM

I have read about carriers offering cheap IoT-specific plans, but when I tried to look for those, they seemed hard to find and pretty obscure, at least in the US (at this time this market seems to be bigger and better serviced in the EU).

So instead I looked for a “generic” plan that uses one of the usual widespread networks in the US and offers a very basic no-frills plan with unlimited text. Mint Mobile fit this bill perfectly. It uses the T-Mobile network and at the time of this writing, the basic plan with unlimited text is $15 / month (if you pay upfront for a full year).

Perhaps at some point there will be readily accessible SMS-only IoT plans out there for the US that are even cheaper, but for now, I’m happy with Mint Mobile.


Left, from top to bottom: Raspberry Pi 3 B+, Sixfab 3G/4G&LTE Base HAT, Quectel EC25-A 4G/LTE Module. On the right, Mint Mobile SIM card and Full Band LTE Antenna.

My research quickly led me to Sixfab, a company specializing in IoT / cellular equipment for Raspberry Pi and Arduino. The parts listed above were the ones I needed for connecting to the T-Mobile network in the US. When I placed my order, I had to pick out the individual items myself (with help from Sixfab’s customer support), in the meantime they seem to have added kits that should make ordering much simpler. You do need to order the right module for your region and network, so read the page carefully.

When everything is assembled, it looks like this:

The modem is powered from the GPIO pins of the Raspi. When powering up the Raspi, the HAT + modem powered up at the same time and connected to the cellular network without issues. The blue LED on the HAT will blink “on long / off short” when the connection is up and running (see the animation at the top of this page).

For OS and driver, I didn’t have to do much. I installed the latest Raspbian Buster Lite, which automatically recognized the modem and set up several /dev/ttyUSB devices to talk to it.

Sixfab recommends talking to the modem using the USB connection which requires connecting the HAT’s micro USB port to one of the Raspi’s USB-C ports using the supplied short USB cable (see picture above). It is also possible to talk to the modem without this cable, using the serial port via the GPIO pins. This requires soldering (shorting) two connections on the HAT and some configuration changes on the Raspi. This connection is also slower than the one through USB. So… use USB.

Talking to the modem

Modems are usually controlled to via “AT” commands using serial interfaces. There’s much information available out there on usual AT commands that every modem should support. The full command reference for the Quectel module is here, however for now I just wanted to try to send some basic commands manually, to prove that both the modem and the cellular connection were working properly.

For this, I used minicom:

minicom -D /dev/ttyUSB2

This connected to the modem and I could type commands to which the modem responded, such as:

+CSQ: 20,99


The first command simply checks whether the modem is up and listening.

The second command requests the signal strength of the cellular connection. 20 is returned, which means “excellent”. The second number is the bit error rate of the connection (during a call). Since there’s no call going on right now, 99 is returned, which basically means “N/A”.

Now that I knew that the modem was up and running and connected, I could turn my attention to writing the code which receives/dispatches and sends text messages. That will be the subject of Part 2, which is forthcoming.