Dockerised Python script for Raspberry PI (including 5) to send sms from SIM868 to Telegram
-
Firstly you need to find out the SMSC of your sim/region. To do this:
- Insert your SIM into your Android device
- Dial the
*#*#4636#*#*
(to get to the system menu). - Select "Phone information".
- Scroll down to the "SMSC" item
- If the SMSC number is not there, press "Refresh"
-
Insert the SIM card into the module
-
Install SIM868 in Raspberry Pi GPIO 40-pin port
-
Set the jumper to B as below
- Enable serial on Raspberry Pi: Type
sudo raspi-config
in console -> Interfaces Options -> Serial Port -> No -> Yes
- Install docker (Instruction here)
- Clone this project in any folder and go to it
git clone https://github.com/LionZXY/SMS2Telegram
cd SMS2Telegram
- Create
.env
file with this fields:
Field | Description | Example |
---|---|---|
TG_TOKEN | Telegram token for the bot, created in BotFather (read more here) | 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11 |
TG_CHAT_ID | ID of the chat room where messages will be sent. I get this parameter by open https://api.telegram.org/bot%TG_TOKEN%/getUpdates in browser |
1235433892 |
SERIAL_PORT | The port through which the Raspberry PI and SIM868 communicate. For Raspberry Pi 4 it can be /dev/ttyS0 . You can check this with minicom |
/dev/ttyAMA0 |
SMSC | SMSC address, this may be unique for each operator/country | +99599599999 |
REPORT_TIMEZONE | Timezone to which message arrival time will be converted | "Europe/London" |
Example .env
file is:
TG_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
TG_CHAT_ID=1235433892
SERIAL_PORT=/dev/ttyAMA0
SMSC=+99599599999
REPORT_TIMEZONE="Europe/London"
- Execute
docker compose up -d
. Warning: Important to build Docker image specifically on Raspberry Pi
- Enable PDU Mode:
AT+CMGF=0
- Enable Text Mod:
AT+CMGF=1
- Set SMSC to +99599599999:
AT+CSCA="+99599599999"
- Switch to PDU mode:
AT+CMGF=0
- Receive all unread messages (PDU Mode only):
AT+CMGL=0
- Receive all messages (PDU Mode only):
AT+CMGL=4
- Receive all messages (TEXT mode only:
AT+CMGL="ALL"
- Read message with index 1:
AT+CMGR=1
- Delete message with index 1:
AT+CMGD=1
- Set up antenna detected with URC reporting:
AT+CANT=1,1,10
- Check signal quality:
AT+CSQ