https://mete.dev/2021/02/21/build-an-sms-forwarder-with-raspberry-pi-zero-w-and-waveshare-sim7000e-hat/ >$ mete * About * Projects Build an SMS Forwarder with Raspberry PI Zero W and Waveshare SIM7000E hat 02.21.2021 | #python #raspberrypi #telegram In this guide, I will explain how to receive SMS messages and forward them to your Telegram account using Raspberry PI Zero W and Wireshare GSM hat. [2021-02-21-14_09_49-Clipboard] Python will be used to read SMS messages and forward them to Telegram Bot API. Messages will be listened to by Gammu SMS service and it will trigger the Python script when an SMS message received. Setup First of all, we have to enable communication between GSM hat and Raspberry PI Zero, run Raspberry Pi Software Configuration Tool (raspi-config); $ sudo raspi-config Then, follow following actions; [image-1]Go to Interface Options [image-2]Select and enter P6 Serial Port [image-3]Select No at this screen. [image-4]Lastly, select Yes at this screen. Exit configuration tool. Now we need to enable UART on raspberry pi. Shutdown and eject SD card to open in another computer. Open /boot/ config.txt file, find the below statement and uncomment it to enable the UART. You can directly append it at the end of the file as well. enable_uart=1 Now, reboot raspberry pi device and open the console to install Gammu SMS Deamon and Python PiP package installer. $ sudo apt-get update $ sudo apt-get install python-pip gammu-smsd Install Telegram Bot API python library. $ sudo pip install python-telegram-bot==12.3.0 Note: Version 12.3.0 is the latest version that is compatible with Python 2.7, if you want to use it with Python 3+ version, you can install the latest available version. Now you need to create a bot in Telegram and obtain a token. Afterwards, start a chat with that bot in your Telegram account and send a test message to your bot. This will help us to identify your chat ID. Open following URL with you Telegram Bot token and copy the chat ID in the response; https://api.telegram.org/bot[YOUR-BOT-TOKEN]/getUpdates [image]This is your chat ID. Save following script in /home/pi/forward-telegram.py; #!/usr/bin/env python from __future__ import print_function import os import sys import telegram numparts = int(os.environ['DECODED_PARTS']) text = '' # Are there any decoded parts? if numparts == 0: text = os.environ['SMS_1_TEXT'] # Get all text parts else: for i in range(1, numparts + 1): varname = 'DECODED_%d_TEXT' % i if varname in os.environ: text = text + os.environ[varname] # Log print('Number %s have sent text: %s' % (os.environ['SMS_1_NUMBER'], text)) #Send by Telegram bot = telegram.Bot(token='[YOUR-BOT-TOKEN]') bot.send_message(chat_id=[YOUR CHAT ID], text=os.environ['SMS_1_NUMBER'].strip() + " | "+ text) Make python file executable $ chmod +x /home/pi/forward-telegram.py Update Gammu SMS Deamon's configuration to use GSM hat. Waveshare uses /dev/ttyS0 for communication. $ sudo nano /etc/gammu-smsdrc Find following lines in the configuration file and update with correct values, for me these values are following; port = /dev/ttyS0 connection = at115200 Also, we need to specify the script path to be ran by Gammu so add following line below [smsd] section; RunOnReceive = /home/pi/forward-telegram.py You can find my complete configuration file here. Restart Gammu SMS service. $ sudo systemctl restart gammu-smsd.service That's all! You should now able to get your SMS messages to your Telegram account. You can monitor Gammu SMS service for any problem with the following command; $ sudo systemctl status gammu-smsd.service Leave a Reply Cancel reply Your email address will not be published. Required fields are marked * [ ] [ ] [ ] [ ] [ ] [ ] [ ] Comment [ ] Name * [ ] Email * [ ] Website [ ] [ ] Save my name, email, and website in this browser for the next time I comment. [Post Comment] [ ] [ ] [ ] [ ] [ ] [ ] [ ] [ ] * Email * Twitter * GitHub * LinkedIn (c) 2021