Created
July 14, 2018 06:35
-
-
Save six519/3cc90e36c1a7d8e4dd3cd92decb337b7 to your computer and use it in GitHub Desktop.
A6 GSM/GPRS Module Autoresponder (Auto Reply) Sample Code In Python
This file contains 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
#!/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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment