0

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".

Ed Mozley
  • 3,299
  • 4
  • 15
  • 20

1 Answers1

0

Apologies my I missed this in my initial search.

Read response AT command with pySerial

Serial response is displayed with:

response =  ser.read(2)

Also with the code

phone.write(bytes([26]))

I was able to send an SMS from within IDLE but it wouldn't send anything from the command prompt. To fix this I had to change it to

phone.write('\x1A')
Ed Mozley
  • 3,299
  • 4
  • 15
  • 20