Agent draft
This commit is contained in:
parent
f720af1747
commit
6651b254d5
@ -33,20 +33,20 @@ Numbers needs to be specified because most of the times they aren't written on t
|
|||||||
```
|
```
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB0",
|
"port":"/dev/ttyUSB0",
|
||||||
"msisdn":"+393409821322",
|
"msisdn":"+393409821322",
|
||||||
"imei":"990000862471854"
|
"imei":"990000862471854"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB1",
|
"port":"/dev/ttyUSB1",
|
||||||
"msisdn":"+443312123452"
|
"msisdn":"+443312123452"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB2",
|
"port":"/dev/ttyUSB2",
|
||||||
"msisdn":"+913446435634"
|
"msisdn":"+913446435634"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB3",
|
"port":"/dev/ttyUSB3",
|
||||||
"msisdn":"+12456345344"
|
"msisdn":"+12456345344"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
@ -0,0 +1,39 @@
|
|||||||
|
import gsm
|
||||||
|
import logging
|
||||||
|
import requests
|
||||||
|
import json
|
||||||
|
|
||||||
|
def load_config():
|
||||||
|
with open('config/gsm.json') as config:
|
||||||
|
gsm = json.load(config)
|
||||||
|
|
||||||
|
with open('config/api.json') as config:
|
||||||
|
api = json.load(config)
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"gsm": gsm,
|
||||||
|
"api": api
|
||||||
|
}
|
||||||
|
return config
|
||||||
|
|
||||||
|
config = load_config()
|
||||||
|
|
||||||
|
gsm_modules = list()
|
||||||
|
for module in config["gsm"]:
|
||||||
|
print(module)
|
||||||
|
gsm_object = gsm.Gsm(module["port"], module["msisdn"])
|
||||||
|
gsm_modules.append(gsm_object)
|
||||||
|
|
||||||
|
messages_queue = list()
|
||||||
|
while True:
|
||||||
|
for gsm_object in gsm_modules:
|
||||||
|
messages = gsm_object.fetch_messages()
|
||||||
|
messages_queue.extend(messages)
|
||||||
|
|
||||||
|
for message in messages_queue:
|
||||||
|
try:
|
||||||
|
r = requests.put(config["api"]["url"], headers={"key": config["api"]["key"]}, data=json.dumps(message), timeout=10)
|
||||||
|
except:
|
||||||
|
logging.error("Failed pushing messages queue to frontend")
|
||||||
|
if r:
|
||||||
|
messages_queue.delete(message)
|
@ -1,20 +1,20 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB0",
|
"port":"/dev/ttyUSB0",
|
||||||
"msisdn":"+393409821322",
|
"msisdn":"+393409821322",
|
||||||
"imei":"990000862471854"
|
"imei":"990000862471854"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB1",
|
"port":"/dev/ttyUSB1",
|
||||||
"msisdn":"+443312123452",
|
"msisdn":"+443312123452",
|
||||||
"pin": "12345"
|
"pin": "12345"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB2",
|
"port":"/dev/ttyUSB2",
|
||||||
"msisdn":"+913446435634"
|
"msisdn":"+913446435634"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"dev":"/dev/ttyUSB3",
|
"port":"/dev/ttyUSB3",
|
||||||
"msisdn":"+12456345344"
|
"msisdn":"+12456345344"
|
||||||
}
|
}
|
||||||
]
|
]
|
@ -28,7 +28,7 @@ class Gsm:
|
|||||||
r = self.cmd("ATI")
|
r = self.cmd("ATI")
|
||||||
if "OK" in r:
|
if "OK" in r:
|
||||||
return True
|
return True
|
||||||
else
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def unlock_sim(self, pin):
|
def unlock_sim(self, pin):
|
||||||
@ -52,10 +52,10 @@ class Gsm:
|
|||||||
r = self.cmd('AT+EMGR=1,7,"' + imei + '"')
|
r = self.cmd('AT+EMGR=1,7,"' + imei + '"')
|
||||||
if "OK" in r:
|
if "OK" in r:
|
||||||
return True
|
return True
|
||||||
else
|
else:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def check_messages(self):
|
def fetch_messages(self):
|
||||||
r = self.cmd("AT+CMGL=REC UNREAD")
|
r = self.cmd("AT+CMGL=REC UNREAD")
|
||||||
print(r)
|
print(r)
|
||||||
|
|
||||||
|
BIN
agent/gsm/__init__.pyc
Normal file
BIN
agent/gsm/__init__.pyc
Normal file
Binary file not shown.
BIN
agent/gsm/__pycache__/__init__.cpython-36.pyc
Normal file
BIN
agent/gsm/__pycache__/__init__.cpython-36.pyc
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user