Raspberry Pi Zero as SMS gateway
Tags: sms, rpizero, gammu
Published: 2018-12-04 22:51:38

---
title: Raspberry Pi Zero as SMS gateway
published: true
tags: sms,rpizero,gammu
canonical_url: https://jonnev.se/raspberry-pi-zero-as-sms-gateway/
---

 ![Raspberry Pi Zero as SMS gateway](https://jonnev.se/content/images/2018/01/IMG_7391_crop.JPG)

I've previously written about setting up a [SMS gateway](https://dev.to/joenas/sms-gateway-and-push-notifications-4432-temp-slug-2187664) using a 3G modem. I had that plugged into my HTPC and honestly it just didn't look good next to the TV. I figured using a Raspberry Pi and just stash it away somewhere would be better. At the same time I was preparing to create a [Magic Mirror](https://magicmirror.builders) of sorts (without the actual mirror) and I accidentally (?) stumbled across the [Adafruit Fona 808](https://www.adafruit.com/product/2542) when doing my regular window shopping for Pi stuff.

After some reading up - there are a lot of great tutorials I'll link to at the end of the post - I felt that there should be something a bit easier and I found a couple of HATs designed for the Pi.

I ended up buying one from [Sixfab](http://sixfab.com/product/gsmgprs-shield/) but either of [these](https://garatronic.fr/index.php/en/nadhat-en) [two](https://www.waveshare.com/gsm-gprs-gnss-hat.htm) should work as well. (If you try one of those I'd love to hear about it!)

![Raspberry Pi Zero as SMS gateway](https://jonnev.se/content/images/2018/01/GPRS_1.5_New-1024x1024-1.jpg)

### Assembling

I own a soldering iron but prefer not to use it unless necessary so imagine my joy when I found the [solderless GPIO header](https://thepihut.com/products/gpio-hammer-header-solderless). While at it I also bought a nice little [case](https://thepihut.com/products/zebra-zero-for-raspberry-pi-zero-black-ice). Assembling the header and case was pretty easy and the result great! Just follow [this guide](https://learn.pimoroni.com/tutorial/sandyj/fitting-hammer-headers).

![Raspberry Pi Zero as SMS gateway](https://jonnev.se/content/images/2018/01/IMG_7386-1.JPG)

_Zero mounted in the rig_

![Raspberry Pi Zero as SMS gateway](https://jonnev.se/content/images/2018/01/IMG_7387-1.JPG)

_Header attached_

![Raspberry Pi Zero as SMS gateway](https://jonnev.se/content/images/2018/01/IMG_7388-1.JPG)

_Case assembled_

![Raspberry Pi Zero as SMS gateway](https://jonnev.se/content/images/2018/01/IMG_7391-2.JPG)

_and finally GSM pHAT added_

### Setup

Now to getting the thing to work! There's a [blog post](http://sixfab.com/updated-tutorial-2-make-a-ppp-internet-connection-with-sixfab-gprs-shield-on-raspberry-pi/) at Sixfab, but it's aimed at setting up a GRPS connection. I was just interested in sending and receiving sms with `gammu` which I already had installed (with `postgres` as backend this time).

First you need to disable the serial console.

```
sudo systemctl stop serial-getty@ttyAMA0.service
sudo systemctl disable serial-getty@ttyAMA0.service
```

That one worked for me. Depending on your Pi you might need to do this instead.

```
sudo systemctl stop serial-getty@ttyS0.service
sudo systemctl disable serial-getty@ttyS0.service
```

Then remove the corresponding line in boot commandline

```
sudo nano /boot/cmdline.txt
# Remove "console=serial0, 115200" or "console=ttyAMA0, 115200"
```

Enable UART and disable Bluetooth on serial.

```
sudo nano /boot/config.txt
# Add these
enable_uart=1
dtoverlay=pi3-disable-bt
```

That last bit with disabling BT did the trick for me and took a reasonable amount of googling to find out. I don't use BT but if you do I recall seeing a solution somewhere...

### Connecting

**Reboot your Pi** and to test the connection to the pHat do this

```
sudo nano /etc/gammurc
# Add 
[gammu]
device = /dev/serial0
connection = at115200
```

And gammu should find your device

```
sudo gammu --identify
```

You can also interact with the shield via `screen`

```
sudo screen /dev/serial0 115200
```

Type `AT`, press enter and you should get `OK` back. `Ctrl-A, D` to exit.

If everything is ok you should now be able to use `gammu-smsd` to send and receive SMS. First **power up the shield** by pressing POWER-UP for a few seconds.

```
sudo nano /etc/gammu-smsdrc
```

This is my entire config with postgres and all.

```
[gammu]
port = /dev/serial0
connection = at115200

# SMSD configuration, see gammu-smsdrc(5)
[smsd]
service = sql
driver = native_pgsql
host = localhost
user = smsd
password = SUPERSECRET
database = smsd
RunOnReceive = python /opt/gammu/receivesms.py
```

### Sending SMS!

```
sudo service gammu-smsd restart
gammu-smsd-inject TEXT 123456 -unicode -text "Oh hai"
```

I've also written a small html client with an API backend for `gammu` that I'll (probably) publish soon.

### Reading list

- [Fona + Pi Zero](https://github.com/InitialState/fona-pi-zero/wiki)
- [Pi Wifi gateway](https://github.com/benstr/TUT-raspi-cellular-gateway/blob/master/readme.md)
- [Another Fona](https://learn.adafruit.com/adafruit-fona-3g-cellular-gps-breakout/overview)
- [SIM900](https://www.itead.cc/blog/raspberry-pi-sim900-gsmgprs-module-adapter-kit)
- [AT commands](https://garretlabs.wordpress.com/2014/06/05/raspberry-and-the-remote-controlled-relay-a-low-level-approach-a-k-a-at-modem-commands-the-usual-suspects/)
- [More on serial and BT](http://www.instructables.com/id/RASPBERRY-PI-3-and-RASPBIAN-JESSIE-GSM-3G-SERIAL-H/)