Created
November 22, 2013 05:35
-
-
Save noomz/7595343 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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