Linux

SMS Gateway DIY

Setup SMS Gateway with playSMS and gammu

Generally:
The aim is to have an SMS gateway for sending 2FA passwords and also for messages from monitoring

Hardware:

Software:

  • RaspberryOS 32Bit
  • Rufus
  • gammu-smsd
  • playSMS
  • apache2
  • mariadb-server

Installation:
Download the operating system and write to the SD card with Rufus
As soon as this is done, an empty ssh file is created on the new drive x: \ boot, so that the SSH server is activated in the system.
If WLAN is required, a file wpa_supplicant.conf with content must also be found on x: \ boot

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=DE
network={
ssid="Wlanname"
psk="Wlanpasswort"
}

 

Now that the preparation is complete, the card can be switched on in the Pi and it can be switched on.
Now search for the Pi in the network with Netscanner or in DHCP.
It then continues with PuTTY
Connect to the found IP
Username: pi
Password: raspberry

sudo apt update && apt dist-upgrade -y

 

When the update is done, restart the Pi once: sudo shutdown -r now

Reconnect to PuTTY

Create user with whom the application runs

sudo adduser sms
sudo usermod -a -G sudo sms

 

Install the firewall and allow ssh, otherwise you can no longer get on the Pi

sudo apt install ufw
sudo ufw allow ssh
sudo ufw enable
sudo ufw reload
 

Install web server with PHP and database server

sudo update
sudo rm /etc/source.list.d/vscode.list # Seit dem letzten Update wird vscode von Microsoft automatisch hinzugefüht, da man das auf dem Server nicht braucht, wird es gelöscht
sudo apt install mariadb-server mc unzip apache2 php php-cli php-mysql php-gd php-curl php-mbstring php-xml php-zip
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
sudo systemctl start apache2.service
sudo systemctl enable apache2.service
sudo ufw allow http
sudo ufw allow https
sudo ufw reload

 

Gammu, the SMS service
Since we need the serial interface, the config.txt has to be adjusted beforehand

sudo nano /boot/config.txt
enable_uart=1

sudo apt install gammu gammu-smsd
mkdir -p /var/log/gammu /var/spool/gammu/{inbox,outbox,sent,error}

chown www-data:www-data -R /var/spool/gammu/*

 

nano /etc/gammu-smsdrc
[gammu]
port = /dev/ttyS0
connection = at
logfile = /var/log/gammu/gammu.log
logformat = textall
[smsd]
Service = files
InboxPath = /var/spool/gammu/inbox/
OutboxPath = /var/spool/gammu/outbox/
SentSMSPath = /var/spool/gammu/sent/
ErrorSMSPath = /var/spool/gammu/error/
InboxFormat = unicode
OutboxFormat = unicode
TransmitFormat = auto
debugLevel = 1
LogFile = /var/log/gammu/smsd.log
DeliveryReport = sms
DeliveryReportDelay = 7200
CheckSecurity = 0

 

Gammu test

service gammu-smsd start
gammu-smsd-monitor
echo "Testnachricht" | gammu-smsd-inject TEXT +4917XXXXXX

 

Prepare directory for playSMS and the web server

cd /home/sms
mkdir -p public_html log
sudo chmod 775 /home/sms public_html log
sudo chown sms.sms -R /home/sms
sudo chown www-data.sms -R /home/sms/log
ls -l /home/sms
sudo nano /etc/apache2/sites-available/sms.domain.local.conf
ServerName sms.domain.local
DocumentRoot /home/sms/public_html
ErrorLog /home/sms/log/httpd-error.log
CustomLog /home/sms/log/httpd-accesss.log combined
 AllowOverride FileInfo AuthConfig
 Limit Indexes Options MultiViews Indexes
 SymLinksIfOwnerMatch IncludesNoExec Require method GET POST OPTIONS php_admin_value engine On
sudo a2ensite sms.domain.local
sudo a2dissite 000-default.conf
sudo a2dissite default-ssl.conf
sudo systemctl reload apache2.service

 

If you would like to carry out this step with an https certificate, because the gateway is internal, this is not absolutely necessary

sudo apt install python3-certbot-apache
sudo certbot --apache

 

Create database

sudo mysqladmin create playsms
sudo mysql

 

CREATE USER 'playsms'@'localhost' IDENTIFIED BY 'strongpasswordhere';
GRANT ALL PRIVILEGES ON playsms.* TO 'playsms'@'localhost';
FLUSH PRIVILEGES;
exit

 

Install playSMS
Since the application should not run in root mode, the user is changed here and work continues with these rights

su sms
cd /home/sms
mkdir -p bin etc lib src
sudo chmod 775 bin etc lib src
sudo touch log/audit.log log/playsms.log
sudo chmod 664 log/audit.log log/playsms.log
sudo chown www-data.sms -R log
ls -l log

cd /home/sms/src
git clone -b 1.4.3 --depth=1 https://github.com/antonraharja/playSMS
cd /home/sms/src/playSMS

nano install.conf

DBUSER="playsms"
DBPASS="strongpasswordhere"
DBNAME="playsms"
DBHOST="localhost"
DBPORT="3306"
WEBSERVERUSER="www-data"
WEBSERVERGROUP="www-data"
PATHSRC="/home/sms/src/playSMS"
PATHWEB="/home/sms/public_html"
PATHLIB="/home/sms/lib"
PATHBIN="/home/sms/bin"
PATHLOG="/home/sms/log"
PATHCONF="/home/sms/etc"

cd /home/sms/src/playSMS
./install-playsms.sh

 

During the installation you have to confirm 3 times with y

The following has to be saved as /etc/systemd/system/playsms.service

[Unit]
Description=PlaySMS
After=mariadb.service
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf start
ExecStop=/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf stop
[Install]
WantedBy=multi-user.target

 

 

Subsequently

systemctl enable playsms.service

 

The config.php has to be adapted for extended logs and if https is used

nano /home/sms/public_html/config.php

logstate 3

ishttps true

 

http://IP
Username: admin
Password: admin

playSMS https://playsms.org/
Routing Konfiguration: https://edzeame.wordpress.com/2019/06/08/playsms-web-interface-gammu-install-and-configure/
API Referenz: https://github.com/playsms/playsms/blob/master/documents/development/WEBSERVICES.md

Forgot admin password?

Then use ssh on the Pi and after sudo -s use the following command

echo “UPDATE playsms_tblUser SET password=’21232f297a57a5a743894a0e4a801fc3′ WHERE uid=’1′” | mysql -uroot -p playsms

Das ganze gibt es auch als fertiges Image

(Deutsch) playSMS Image
Size: 436 MB

 

 

Amazon links are included in this article. Clicking on it will take you directly to the provider. Should you decide to buy there, we will receive a small commission. Nothing changes in the price for you.

64 thoughts on “SMS Gateway DIY

  1. Hi, danke für das Image!

    Über Gammu direkt kann ich SMS versenden, bei PlaySMS bleiben diese in der Queue hängen und gehen nicht raus.
    Zufällig eine Idee woran dies liegen könnte?

      1. Guten Abend! Habe das Image genutzt, sehe auch deine Testnachrichten darin, meine neuen bleiben aber hängen.
        Gammu ist dort auch als SMSC drin. Muss ich das noch mit der Queue verbinden?

    1. was steht denn in /home/sms/log und was sagt /var/log/gammu/smsd.log dazu? oder dmesg
      Ich hatte an einem PI das Problem, dass das 7600 HAT immer ein Undervoltage verursacht hat.

      1. Guten Morgen! In playsms.log steht nur der Queue-Eintrag einer neuen Nachricht drin, sonst nichts. In smsd.log passiert gar nichts wenn ich über playsms eine eine Nachricht versuche zu verschicken. Dort passiert erst etwas wenn ich über gammu direkt eine Nachricht sende.

          1. Die beiden Dateien habe ich nachgerüstet, aber noch keine Veränderung nach einem Neustart.
            Der playSMS daemon status steht auf rot, sieht so aus als ob dieser gar nicht laufen würde.

          2. Hi, der Raspi hängt nicht direkt am Netz dran. Hab jetzt auch mal die Anleitung von Alex abgearbeitet die du verlinkt hattest, aber dort komme ich noch nicht einmal auf das PlaySMS-Webinterface obwohl nginx etc. laufen…

          3. Bei den systemd Pfaden hast du es angepasst?
            /home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf start und
            /home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf stop ?

            Mit /home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf status solltest du sehen ob es überhaupt läuft
            Die Webseite wird immer angezeigt da der Webpfad auf /home/sms/public_html zeigt

  2. Das war es, danke!!!
    Allerdings muss ich playsms noch per Hand “/home/sms/bin/playsmsd /home/sms/etc/playsmsd.conf start” starten, sonst geht es nicht.

    1. Im Artikel habe ich es schon angepasst.
      Du musst noch
      systemctl enable playsms.service

      Dadurch wird der Service beim starten auch automatisch geladen

  3. Reicht es für Mail-To-SMS die Mailserver-Einstellungen über das Webinterface vorzunehmen oder muss man dazu in der config.php auch von etwas eintragen?

    1. Habe ich bis jetzt nicht gehabt, läuft auf zwei Pi seit erscheinen des Artikels , also ca 2-3 Monate. Wenn dann schau Mal in die logs, Apache, system, dmesg und playsms, vielleicht gibt es da einen Anhaltspunkt. Kann aber sein das die Disk voll ist. Ich hatte das Image mit nur 200mb frei. Dann mit raspi-config die Disk vergrößern

      1. Praktisch wenn man einen Kollegen hat der das kann. Ich hab auch trotz intensiver Suche nichts gefunden (Raspi4+Waveshare GSM Hat). Nimmt dein Kollege zufällig Aufträge an?

      1. In der config.php habe ich nichts zur Spracheinstellung gefunden. Kann es sein dass man erstmal über raspi-config die Lokalisationen installieren muss?

  4. Moin! Bin beim Wechsel der Simkarte auf das Problem gestossen dass Gammu keine SMSC-Nummer von der Simkarte zieht, diese muss man nach jedem Neustart neu setzen. Hast du eine Idee mich man die Nummer dauerhaft an Gammu übergeben kann?

  5. Das funktioniert jetzt, danke! Aus irgendeinem Grund muss ich nach jedem Neustart gammu-smsd per Hand einmal beenden und neu starten damit SMS rausgehen. Was könnte da der Grund sein? gammu-smsd wird automatisch immer mitgestartet.

  6. In der smsd.log wird nach einem Neustart immer der Fehler abgelegt dass keine SMSC-Nummer vorhanden wäre. Startet man den smsd kann neu geht es sofort. Kann es sein dass vielleicht irgendwelche Rechte der Config-Datei falsch sind? Ich habe das pi-default-PW geändert.

    1. Kommt drauf an welches hat du benutzt bei dem großen musste ich wie bei Waveshare steht die Brücken setzen. Mit dem Passwort hat das aber nichts zu tun

  7. Irgendwas mache ich grundsätzlich falsch: Hab die ich selbe Installation die im RB4 nicht geht mit einem Zero probiert. Selbes Modem, selbe SIM, geht sofort. Ich stecke irgendwie fest…

    1. Sagt es zufällig bei dmesg undervoltage? Das hab ich auf einem pi4 und 3 auch, auf dem Zero nicht. Habe aber auch kein Original Netzteil von raspberry. Mit einem vom Amazon Tab geht es zum Teil besser

      1. Sieht nicht nach Untervoltage aus. Nutze das originale Netzteil mit 3A. Sehe auch am HAT (habe einen anderen als du (SIM800X)) dass die Karte im Netz eingebucht ist.

        Würde es als Workaround gehen per Cronjob o.ä. Gammu nach jeden Reboot einmal zu stoppen/starten?

        1. Hallo Holger,
          ich habe habe das Problem nun auch gehabt und gefunden was zu ändern ist.
          in der /etc/gammu-smsdrc
          braucht es unter [smsd]
          einen Eintrag
          PhoneID =+49deine nummer

          und in der /etc/smsd.conf
          unter [GSM1]
          smsc = 49deinenummer

    1. Hallo Daniel,
      ich habe einen neuen Downloadlink eingebaut.
      Das Image ist noch das gleiche , vermutlich werde ich dieses aber nochmals überarbeiten, da hier kleinere Fehler wie in den anderen Kommentaren zu entnehmen ist , noch vorhanden sind.
      Gruß Stefan

      1. Hallo Stefan,

        Danke fürs hochladen.
        Trotzdem bin ich irgendwie zu Blöd …

        pi@raspberrypi:~ $ sudo gammu-smsd-monitor
        gammu-smsd-monitor[1075]: Using FILES service
        gammu-smsd-monitor[1075]: Configuring Gammu SMSD…
        gammu-smsd-monitor[1075]: SHM token: 0x1020303 (16909059)
        gammu-smsd-monitor[1075]: Warning: No PIN code in /etc/gammu-smsdrc file
        gammu-smsd-monitor[1075]: CommTimeout=30, SendTimeout=30, ReceiveFrequency=15, ResetFrequency=0, HardResetFrequency=0
        gammu-smsd-monitor[1075]: checks: CheckSecurity=0, CheckBattery=1, CheckSignal=1, CheckNetwork=1
        gammu-smsd-monitor[1075]: mode: Send=1, Receive=1
        gammu-smsd-monitor[1075]: deliveryreport = sms
        gammu-smsd-monitor[1075]: phoneid =
        gammu-smsd-monitor[1075]: Inbox is „/var/spool/gammu/inbox/“ with format „unicode“
        gammu-smsd-monitor[1075]: Outbox is „/var/spool/gammu/outbox/“ with format „unicode“ and transmission format „auto“
        gammu-smsd-monitor[1075]: Sent SMS moved to „/var/spool/gammu/sent/“
        gammu-smsd-monitor[1075]: SMS with errors moved to „/var/spool/gammu/error/“
        gammu-smsd-monitor[1075]: Mapped POSIX RO shared memory at 0x76f0d000
        Client: Gammu 1.40.0 on Linux, kernel 5.10.60-v7+ (#1448 SMP Sat Aug 21 10:43:27 BST 2021) compiler GCC 8.2
        PhoneID:
        IMEI: 867584034306048
        IMSI: 232056308028288
        Sent: 0
        Received: 0
        Failed: 64
        BatterPercent: 0
        NetworkSignal: -1

        Die SIM geht garantiert, funktioniert im Handy perfekt.
        Ist ein Raspi 3b+ und das SIM7600X-4G-HAT.
        Verbunden direkt über die GPIO und einmal ein Kabel von USB HAT zu USB Raspi.
        NetworkSignal -1 bedeutet keinen Empfang oder?
        Netzteil ist ein 5V 10A dran, also undervoltage sollte nicht sein! 🙂
        pi@raspberrypi:~ $ /opt/vc/bin/vcgencmd get_throttled
        throttled=0x0

        Hab ich was vergessen oder falsch gemacht?

        LG
        Daniel

          1. Hab es bereits mit und ohne probiert!

            pi@raspberrypi:~ $ sudo gammu-smsd-monitor
            gammu-smsd-monitor[1080]: Using FILES service
            gammu-smsd-monitor[1080]: Configuring Gammu SMSD…
            gammu-smsd-monitor[1080]: SHM token: 0x1020303 (16909059)
            gammu-smsd-monitor[1080]: Warning: No PIN code in /etc/gammu-smsdrc file
            gammu-smsd-monitor[1080]: CommTimeout=30, SendTimeout=30, ReceiveFrequency=15, ResetFrequency=0, HardResetFrequency=0
            gammu-smsd-monitor[1080]: checks: CheckSecurity=0, CheckBattery=1, CheckSignal=1, CheckNetwork=1
            gammu-smsd-monitor[1080]: mode: Send=1, Receive=1
            gammu-smsd-monitor[1080]: deliveryreport = sms
            gammu-smsd-monitor[1080]: phoneid = +4369917969329
            gammu-smsd-monitor[1080]: Inbox is “/var/spool/gammu/inbox/” with format “unicode”
            gammu-smsd-monitor[1080]: Outbox is “/var/spool/gammu/outbox/” with format “unicode” and transmission format “auto”
            gammu-smsd-monitor[1080]: Sent SMS moved to “/var/spool/gammu/sent/”
            gammu-smsd-monitor[1080]: SMS with errors moved to “/var/spool/gammu/error/”
            gammu-smsd-monitor[1080]: Mapped POSIX RO shared memory at 0x76f9a000
            Client: Gammu 1.40.0 on Linux, kernel 5.10.60-v7+ (#1448 SMP Sat Aug 21 10:43:27 BST 2021) compiler GCC 8.2
            PhoneID: +43699xxxxxx
            IMEI: 867584034306048
            IMSI: 232056308028288
            Sent: 0
            Received: 0
            Failed: 26
            BatterPercent: 0
            NetworkSignal: -1

            Fürchte ich muss nochmal ganz von vorne Beginnen!
            Soweit ich das verstanden habe gehts ja ohne dem USB Kabel nicht oder?

            PhoneID steht in der /etc/gammu-smsdrc, eine /etc/smsd.conf gibts nicht in deinem Image! 🙁

          2. Das USB Kabel ist nicht notwendig, das geht alles über die Pin Header. Das hat ist die e-h bzw g-h Version? Die beiden sind für Europa. Die anderen sind für China oder Amerika.

          3. Ok dann probier ich mal ohne. Aber langsam vermute ich das mein Provider das gesperrt hat. ich probier mal eine andere SIM die nächsten Tage.

            Es steht SIM7600E drauf, somit nehme ich an E für Europe!
            Ich halte dich am Laufenden.

          4. Die Pin war deaktiviert? Das stand am Anfang vom Artikel, sonst musst du die in die config eintragen, hatte mit aktivierter Pin aber auch so meine Schwierigkeiten und habe sie dann deaktiviert. Da die IMEI und die SIM-Karten Seriennummer erkannt wird funktioniert aber das Modul würde ich sagen. Anderen Standort schon getestet? Die richtige Antenne angeschlossen? Die vom GPS passt leider auch auf den Anschluss vom LTE.

          5. Tue 2021/08/24 14:35:54 gammu-smsd[1123]: Using FILES service
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: Configuring Gammu SMSD…
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: SHM token: 0x1020303 (16909059)
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: Warning: No PIN code in /etc/gammu-smsdrc file
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: CommTimeout=30, SendTimeout=30, ReceiveFrequency$
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: checks: CheckSecurity=0, CheckBattery=1, CheckSi$
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: mode: Send=1, Receive=1
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: deliveryreport = sms
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: phoneid = +4369917969329
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: Inbox is “/var/spool/gammu/inbox/” with format “$
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: Outbox is “/var/spool/gammu/outbox/” with format$
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: Sent SMS moved to “/var/spool/gammu/sent/”
            Tue 2021/08/24 14:35:54 gammu-smsd[1123]: SMS with errors moved to “/var/spool/gammu/error$
            Tue 2021/08/24 14:35:54 gammu-smsd[1124]: Created POSIX RW shared memory at 0x76f9c000
            Tue 2021/08/24 14:35:54 gammu-smsd[1124]: Starting phone communication…
            Tue 2021/08/24 14:35:57 gammu-smsd[1124]: Found 1 sms to “+436644710163” with text “Servus$
            Tue 2021/08/24 14:35:57 gammu-smsd[1124]: New message to send: OUTA20210824_113707_00_+436$
            Tue 2021/08/24 14:35:57 gammu-smsd[1124]: SMS sent on device: “/dev/ttyS0” status=331, ref$
            Tue 2021/08/24 14:35:57 gammu-smsd[1124]: SMS sent on device: “/dev/ttyS0” status=331, ref$
            Tue 2021/08/24 14:35:57 gammu-smsd[1124]: Error sending SMS: Network error. (NETWORK_ERROR$
            Tue 2021/08/24 14:35:58 gammu-smsd[1124]: Found 1 sms to “+436644710163” with text “Servus$
            Tue 2021/08/24 14:35:58 gammu-smsd[1124]: New message to send: OUTA20210824_113707_00_+436$
            Tue 2021/08/24 14:35:58 gammu-smsd[1124]: SMS sent on device: “/dev/ttyS0” status=331, ref$
            Tue 2021/08/24 14:35:58 gammu-smsd[1124]: SMS sent on device: “/dev/ttyS0” status=331, ref$
            Tue 2021/08/24 14:35:58 gammu-smsd[1124]: Error sending SMS: Network error. (NETWORK_ERROR$

            Ok Gammu dürfte alles passen, defintiv Netzproblem oder was meinst du?

          6. Hallo Daniel,
            Hier war die Antwort an Holger.
            Phoneid sollte da angegeben werden und wenn eine simpin vorhanden ist auch diese, sonst wird die Karte gesperrt.

            Sonst kann es schon ein Netzproblem sein , vielleicht Antenne Mal aus dem Fenster hängen
            Als Antwort auf Holger.
            Hallo Holger,
            ich habe habe das Problem nun auch gehabt und gefunden was zu ändern ist.
            in der /etc/gammu-smsdrc
            braucht es unter [smsd]
            einen Eintrag
            PhoneID =+49deine nummer

            Pin = 1234

  8. Hi Stefan, also es lag am Netzbetreiber, jetzt läuft mein Gammu endlich! dafür hats noch was mit playsms! frage, welche passwörter hast du im fertigen image verwendet? danke! LG Daniel

  9. Danke, mittels zurücksetzen hab ich es jetzt geschafft und das Ding läuft endlich! darf ich dich noch was fragen? Wie kann ich einstellen in PlaySMS das alle eingehenden SMS weitergeleitet werden an eine Gruppe? und gibts irgendwie eine chance das ding zu beschleunigen? also speziell eingehende sms aber auch ausgehende, irgendwie dauert das alles ewig!

  10. Hallo,
    ist das Image noch aktuell/lauffähig ?
    Ich habe es auf eine 16G SD geflasht, sehe auch das Filesystem, aber es bootet in einem Pi4 nicht

    1. Mir nicht bekannt, das es nicht bootet, aber ich hatte einige SD Karten bei denen müsste ich erst mit bootice einen Reset durchführen. Sonst per Anleitung, dauert auf dem Pi 4 auch nur 20 Minuten das zu installieren 🙂

      1. Vielen Dank für’s Feedback, klappt bei mir leider nicht, habe es mit mehreren SDs und mehreren Pi’s versucht. Wenn ich die SDs mit dem normalen OS flashe funktionieren sie einwandfrei.

        Auch das Installieren per Anleitung war leider bisher nicht erfolgreich. Bin nach längerem Probieren immerhin soweit, dass gammu-smsd-monitor anzeigt, dass das Modem verbunden ist.

        SMS über gammu versenden klappt auf root level.

        Allerdings funktioniert Apache nicht, der in der Anleitung angegebene Befehl “AllowOverride FileInfo AuthConfig” wird abgelehnt mit “AllowOverride not allowed here”

        Na ja, ich kämpfe mal weiter 😉 ….

Leave a Reply to TotoCancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.