I'm using the following code to connect to a phone to send an SMS message:
import serial
import time
phone = serial.Serial()
phone.baudrate = 38400
phone.bytesize = 8
phone.stopbits = 1
phone.xonxoff = 0
phone.rtscts = 0
phone.timeout = 0
phone.port = 3 #try different ports here, if this doesn't work.
phone.parity=serial.PARITY_NONE
phone.open()
print phone.portstr
recipient = "+929409778"
message = "We did it!"
print ("I did come after it")
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")
print (message)
time.sleep(0.5)
phone.write(bytes([26]))
time.sleep(0.5)
phone.readall()
finally:
phone.close()
I am able to connect the phone, but I am not able to send the message. It's not giving me an error, so I'm not sure where to start debugging.
Is there something wrong with my code that I'm not seeing?