-
-
Save nikolaybotev/f09c2ca042bdaaabe07f434a6bc1e59f to your computer and use it in GitHub Desktop.
Send SMS using AT commands over the TTY of a Cellular modem. Supports Unicode international characters and emojis.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -e | |
# Usage: sendsms +375555555 "some text i want to send" | |
TELFNUMB="$1" | |
SMSTEXT="$2" | |
MODEM="${3:-/dev/ttyUSB2}" | |
TIMEOUT="${4:-1}" | |
# Text encoding | |
to_ucs2() { | |
python3 -c "import sys; print(sys.argv[1].encode('utf_16_be').hex())" "$1" | |
} | |
# Chat with modem | |
exec < $MODEM > $MODEM | |
# Configure modem | |
chat TIMEOUT $TIMEOUT "" "AT" "OK" | |
chat TIMEOUT $TIMEOUT "" "AT+CMGF=1" "OK" | |
chat TIMEOUT $TIMEOUT "" "AT+CSCS=\"UCS2\"" "OK" | |
chat TIMEOUT $TIMEOUT "" "AT+CSMP=17,167,0,25" "OK" | |
# Send message | |
chat TIMEOUT $TIMEOUT "" "AT+CMGS=\"$(to_ucs2 ${TELFNUMB})\"" ">" | |
chat TIMEOUT $TIMEOUT "" "$(to_ucs2 "${SMSTEXT}")^Z" "OK" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Change encoding to support international characters and emojis.