I have been using this code to send an SMS using Python on my Raspberry Pi.
How to Send/Receive SMS using AT commands?
import time
import serial
recipient = "+1234567890"
message = "Hello, World!"
phone = serial.Serial("/dev/ttyUSB3", 460800, timeout=5)
try:
time.sleep(0.5)
phone.write(b'ATZ\r')
time.sleep(0.5)
phone.write(b'AT+CMGF=1\r')
time.sleep(0.5)
phone.write(b'AT+CMGS="' + recipient.encode() + b'"\r')
time.sleep(0.5)
phone.write(message.encode() + b"\r")
time.sleep(0.5)
phone.write(bytes([26]))
time.sleep(0.5)
finally:
phone.close()
When the script runs there are no errors but no text message arrives. I have run the AT commands direct in minicom shell and the text message DOES get sent successfully.
Is there any way of the python script printing to screen the response from the modem as the commands are sent to it? For example if I send ATZ it would be good if I could print "OK".