Skip to content

Instantly share code, notes, and snippets.

@Archeb Archeb/SMSF.py
Last active Sep 24, 2019

Embed
What would you like to do?
SMS Forwarder
import serial
import re
import requests
ser = serial.Serial('/dev/ttyUSB0')
ser.write('AT+CSCS="UCS2"\n')
while 1:
read=ser.readline()
match=re.match(r'\+CMTI: "ME",(\d+)',read)
if(match):
ser.write('AT+CMGR=' + match.group(1) + '\n')
tmp=ser.readline()
info=ser.readline()
msg=ser.readline()
ser.write('AT+CMGD=' + match.group(1) + '\n')
infomatch=re.match(r'\+CMGR: "REC.*READ","(.*)",*"(.*)"',info)
if(infomatch):
srcphone=infomatch.group(1)
srctime=infomatch.group(2)
srcphone=unicode(srcphone.decode("hex"), "utf-16-be").encode("utf8")
msg=msg.strip('\r\n')
msg=unicode(msg.decode("hex"), "utf-16-be").encode("utf8")
finalmsg={'text':srcphone + ":" + msg + " [" + srctime + "]"}
mydata={'value1':srcphone,'value2':srctime,'value3':msg}
print mydata
requests.post('IFTTT API地址',json=mydata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.