Skip to content

Instantly share code, notes, and snippets.

@six519
Created July 14, 2018 06:35
Show Gist options
  • Save six519/3cc90e36c1a7d8e4dd3cd92decb337b7 to your computer and use it in GitHub Desktop.
Save six519/3cc90e36c1a7d8e4dd3cd92decb337b7 to your computer and use it in GitHub Desktop.
A6 GSM/GPRS Module Autoresponder (Auto Reply) Sample Code In Python
#!/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