|
#!/usr/bin/env python |
|
import serial |
|
import time |
|
import re |
|
|
|
if __name__ == "__main__": |
|
ser = serial.Serial('/dev/cu.SLAB_USBtoUART', 9600, timeout=1) |
|
isOk = False |
|
|
|
try: |
|
while True: |
|
if not isOk: |
|
ser.write(b"AT+CMGF=1\r\n") |
|
|
|
data = ser.readline() |
|
|
|
if not isOk: |
|
if data.strip() == "OK": |
|
isOk = True |
|
|
|
if isOk: |
|
if data.strip() != "": |
|
print "%s\n" % data.strip() |
|
|
|
if re.search('^.*\+CMT', data.strip()): |
|
number = data.strip().replace("+CMT: ", "").split(",")[0].replace('"', '').replace("+63", "0") |
|
ser.write(b'AT+CMGS="%s"\r\n' % number) |
|
time.sleep(1) |
|
ser.write(b'I am busy right now. This is an automated reply.') |
|
ser.write(b'\x1a\r\n') |
|
|
|
time.sleep(1) |
|
|
|
except KeyboardInterrupt: |
|
ser.close() |