Sending Text-Mode SMS via AT Commands ------------------------------------- 1. Requirements: - any Linux box with one USB2.0 port available, and current Expect and Kermit installations, - an LTE USB modem (aka a surf stick). Needs to be able to accept AT commands needed to configure text message sending, and to actually send text-mode SMSs. USB modems offering WiFi capabilities may or may not work. Make sure the stick covers local bands, since these differ by ITU region, or an Android phone with both developer mode, and AT command capability enabled. Some Android devices may not offer This implementation's scripts have been tested using both a Waveshare SIM7600G-H USB stick, and a Claro-branded ZTE MF829B. - a SIM allowing to send unlimited SMS (otherwise this gets expensive fast). 2. Installation: Move the expect scripts provided as part of this bundle to your $HOME/bin, and the ttyusb*.cfg files to your home directory. Invoke your package manager to install both kermit (might also be available as ckermit or gkermit) and expect. Expect drags in Tcl, which might already be present courtesy of a previuos SSH-SMS setup. On any recent Linux, stop and disable ModemManager via systemctl. 3. Preparation: When using an Android phone, make sure it presents a serial port to the Linux system. Plug it in, review the output of "dmesg -T" to see if any serial ports were added at the time the phone got connected. This can be hit or miss, and may differ depending on Linux flavor and version. 4. Sanity Check Before starting scripts against a surfstick or phone, make sure they would work OK by manually issuing commands against the stick. To do so, bring up kermit with the name of one of the port configuration files. Unless Linux had seen any /dev/ttyUSB* named devices prior to insertion of the USB stick, there is a good chance that the device accepting modem commands is the third one starting with ttyUSB, i.e. /dev/ttyUSB2, accessed via ttyusb2.cfg: kermit ttyusb2.cfg Heads up, the very first few commands might not get echoed back to the terminal. Start out with an ATZ (reload default configuration) or AT&F (load factory configuration). This might result in an OK. Turn on input echoing with ATE1. Once sent, input should get echoed as entered. To see what kind of device one is dealing with, run ATI. 5. SMS Commands Text messages can be entered to be sent either as plain text, or in form of a TPDU (telephony protocol data unit) or PDU. PDUs consist of a header and a packed payload, and are/will be discussed elsewhere. The AT-commands discussed below can be used to retrieve and set values, and to display accepted values. To query, append a question mark, to set, an equals sign, followed by the value, and, to see accepted values, both an equals sign, followed by question mark. Some commands require the value to be set to be quoted. To send an SMS in text mode, the sending device has to be configured to do so. Not all devices accept plain-text SMSs, but most, if not all, handle PDUs. To switch from PDU (the default) to text mode, run AT+CMGF=1 To switch back to PDU mode, try: AT+CMGF=0 Next property to check and change is the character set used. To see what the device has to offer, issue at+cscs=? +CSCS: ("IRA","GSM","UCS2") OK IRA stands for "International Standard Alphabet", pretty much ASCII: https://en.wikipedia.org/wiki/T.50_(standard) GSM stands for GSM7, a 7-bit alphabet where most special characters less than ASCII's 0x20, between 'Z' and 'a', as well as larger than 'z' have been replaced with non-english letters and symbols. IRA is a good one to run with. To mix things up not just slightly, switch to GSM: at+cscs="IRA" OK at+cscs="GSM" OK Finally, text SMSs can be sent in two different ways: - first store the message on the device, then send it to the recipient referencing the storage location, or - send it directly, so without storing. Storing a message on device or SIM to then send it to multiple recipients can be faster, because one does not have to send a potentially lengthy message more than once from PC to the device. But then device memory management presents an interesting rabbit hole to go down, so that's left for the audience to explore. There's a tutorial right here: https://www.developershome.com/sms/cpmsCommand.asp To send a text SMS directly to one recipient, run at+cmgs="phone-number,quoted" > message payload goes here Ctrl-Z Text-mode SMSs can be up to 160 characters long. Enter more to cause an error: at+cmgs="+12145661422" > The quick brown fox jumps over the lazy dogs back. > +CMGS: 86 OK at+cmgs="+12145661422" > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > The quick brown fox jumps over the lazy dogs back. > > +CMS ERROR: SMS size more than expected See source code (always under construction, since nothing is as constant as change) for moree. 5. References For a list of SMS-related AT-commands, refer to the latest version of 3GPP's 27.005, "Use of Data Terminal Equipment - Data Circuit terminating Equipment (DTE - DCE) interface for Short Message Service (SMS) and Cell Broadcast Service (CBS)" right here: https://www.3gpp.org/ftp/Specs/archive/27_series/27.005/ More AT-command summaries: SMS commands start on page 130. https://www.emnify.com/developer-blog/at-commands-for-cellular-modules https://www.1ot.com/blog/beginners-guide-to-at-commands https://docs.rs-online.com/5931/0900766b80bec52c.pdf https://nimbelink.com/Documentation/Skywire/2G_1xRTT/Telit_CE910_AT_Commands.pdf Fun fact, etsi.org has all of 3gpp's specs, just slightly differently numbered and referenced: https://webapp.etsi.org/key/key.asp?GSMSpecPart1=27&GSMSpecPart2=007 Full Menu: https://webapp.etsi.org/key/key.asp?full_list=y Interesting read about alphabets: https://www.3gpp.org/ftp/Specs/archive/23_series/23.038/