Skip to content

Instantly share code, notes, and snippets.

@noomz
Created November 22, 2013 05:35
Show Gist options
  • Save noomz/7595343 to your computer and use it in GitHub Desktop.
Save noomz/7595343 to your computer and use it in GitHub Desktop.
# reg-exp
import re
# use pyserial
import serial
from time import sleep
def checkOK():
isOK = False
lines = ser.readlines()
for line in lines:
print line
if re.match(r'^OK', line):
isOK = True
if isOK:
print '---- OK!'
else:
print '---- FAIL!'
# replace /dev/ttyUSB3 to your device path
ser = serial.Serial('/dev/ttyUSB3', 115200, timeout=1)
# clear serial command
ser.write('ATZ\r')
# Set operating mode see: http://www.developershome.com/sms/operatingMode2.asp
ser.write('AT+CMGF=1\r')
# Read buffer
ser.readlines()
# To send SMS, first set destination number
# see: http://www.developershome.com/sms/sendSmsByAtCommands.asp
ser.write('AT+CMGS="0841112222"\r')
# Then write the message
ser.write('Hello! From SIM Card\r')
# .. can have many lines
ser.write('-- Second line\r')
# .. write char 26 (Ctrl-z) to end message body
ser.write(chr(26))
sleep(1) # wait for response
checkOK()
ser.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment