Skip to content

Instantly share code, notes, and snippets.

@ereli
Created September 11, 2014 11:41
Show Gist options
  • Save ereli/e34acea8f0d581c23dcb to your computer and use it in GitHub Desktop.
Save ereli/e34acea8f0d581c23dcb to your computer and use it in GitHub Desktop.
#
# AT commands ref :http://www.fccps.cz/img.asp?attid=24590
# credit to: https://gist.github.com/pmarti/11120153
import serial
from smspdu import SMS_SUBMIT
def send_text(number, text):
# encode the SMS
p = SMS_SUBMIT.create('sender', number, text)
#set pdu_length
pdu_length = len(p.toPDU())/2
#set pdu
pdu = p.toPDU()
# open the modem port (hard coded COM port)
ser = serial.Serial("COM12",9600, timeout=1)
# write the PDU length and wait 1 second till the
# prompt appears (a more robust implementation
# would wait till the prompt appeared)
ser.write('ATI\r')
print ser.readlines()
ser.write('AT+CMGF=0\r')
print ser.readlines()
ser.write('AT+CMGS=%d\r' % pdu_length)
print ser.readlines()
# write the PDU and send a Ctrl+z escape
ser.write('%s\x1a' % pdu)
print ser.readlines()
ser.close()
send_text('+97212654789', 'hey how are you?')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment