Skip to content
Snippets Groups Projects
Commit e122e298 authored by Recolic's avatar Recolic :house_with_garden:
Browse files

Initial commit

parents
No related branches found
No related tags found
No related merge requests found
# naive sms HTTP API
A naive API server to remote-access your SMS without phone!
This is a very naive API server, to remote-access your SMS. Warning: it doesn't even support parallel requests. For personal use only.
## requires
[SIM800C USB to GSM module](https://www.amazon.com/EC-Buying-Quad-Band-Integrated-Transmission/dp/B0B64X81LD/ref=sr_1_4?crid=2KW2A16T3C6R0&keywords=sim800&qid=1701559081&sprefix=sim800%2Caps%2C350&sr=8-4)
python3
python usim800 module (please clone from github: <https://github.com/Bhagyarsh/usim800> . pip release is too old)
## how to use
### step 1 - test if your SIM800 module is working
Run `python pullsms.py`. If it prints your SMS correctly, you are good.
### step 2 - start api server
Run `python apiserver.py 8080` as daemon.
### step 3 - enjoy
Try if your api server is working.
```
curl "http://localhost:8080/mO0c7JlqE1n5r/smsget"
curl "http://localhost:8080/mO0c7JlqE1n5r/smsdel"
```
# pip3 install web.py smartrent.py
#
# Run this program like: python this.py 30801
# Usage: curl "http://localhost:30801/mO0c7JlqE1n5r/smsget"
# Usage: curl "http://localhost:30801/mO0c7JlqE1n5r/smsdel"
# Modified: no telegram notify
from usim800 import sim800
import sys
def sms_get_or_del(get_or_del):
# Param: True for get, False for del
# Return: message
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
if get_or_del:
res_dict = gsm.sms.readAll()
result_str = ""
if len(res_dict) == 0:
result_str = "No SMS on this SIM."
else:
result_str = "SIM <b>17386011111</b><br />"
for k in res_dict:
num, sender, time, body = [res_dict[k][index] for index in [0,2,4,5]]
result_str += '<b>{}</b> {} {} {}<br />'.format(num, sender, time, body)
# with open('/tmp/debug', 'wb+') as f:
# f.write(result_str.encode("utf-8", "ignore"))
return result_str[-4000:] # Max: 4096 chars
else:
gsm.sms.deleteAllReadMsg()
return "Deleted all message on SIM"
def send_666_to_12306():
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
print('Test send 666 to 12306...')
gsm.sms.send('12306','666')
import json,requests # callback: telegram api
def telegram_notify(msg):
url = "https://maker.ifttt.com/trigger/recolxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
payload = {
"value1": msg
}
headers = {
"Content-Type": "application/json"
}
requests.post(url, data=json.dumps(payload), headers=headers)
import web
urls = (
'/(.*)', 'hello'
)
app = web.application(urls, globals())
class hello:
def GET(self, uri):
if not uri.startswith('mO0c7JlqE1n5r'):
return "Wrong API key"
try:
action = uri.split('/')[1].lower()
if action == "smsget":
get_or_del = True
elif action == "smsdel":
get_or_del = False
elif action == "send12306":
send_666_to_12306()
return "Sent 666 to 12306, success"
else:
return "Wrong API usage. Expect smsget/smsdel"
msg = sms_get_or_del(get_or_del)
# telegram_notify(msg)
return '<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">' + "Done. Result:<br />" + msg
except Exception as e:
raise
# return "API Error: " + str(e)
if __name__ == "__main__":
app.run()
from usim800 import sim800
import sys
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
if len(sys.argv) == 2 and sys.argv[1] == 'del':
print('Deleting all msg...')
gsm.sms.deleteAllReadMsg()
else:
print('Reading all msg...')
res_dict = gsm.sms.readAll()
for k in res_dict:
print(res_dict[k])
from usim800 import sim800
import sys
gsm = sim800(baudrate=9600,path="/dev/ttyUSB0")
print('Test send 666 to 12306...')
gsm.sms.send('12306','666')
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment