From 6651b254d5ecbb93abbf61e7250f8543b0a318e9 Mon Sep 17 00:00:00 2001 From: Giulio Date: Tue, 16 Jul 2019 15:12:57 +0200 Subject: [PATCH] Agent draft --- README.md | 8 ++-- agent/agent.py | 39 ++++++++++++++++++ agent/config/gsm.json | 8 ++-- agent/gsm/__init__.py | 6 +-- agent/gsm/__init__.pyc | Bin 0 -> 3003 bytes agent/gsm/__pycache__/__init__.cpython-36.pyc | Bin 0 -> 2374 bytes 6 files changed, 50 insertions(+), 11 deletions(-) create mode 100644 agent/gsm/__init__.pyc create mode 100644 agent/gsm/__pycache__/__init__.cpython-36.pyc diff --git a/README.md b/README.md index c1580f6..f66f290 100644 --- a/README.md +++ b/README.md @@ -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", "imei":"990000862471854" }, { - "dev":"/dev/ttyUSB1", + "port":"/dev/ttyUSB1", "msisdn":"+443312123452" }, { - "dev":"/dev/ttyUSB2", + "port":"/dev/ttyUSB2", "msisdn":"+913446435634" }, { - "dev":"/dev/ttyUSB3", + "port":"/dev/ttyUSB3", "msisdn":"+12456345344" } ] diff --git a/agent/agent.py b/agent/agent.py index e69de29..5d8194d 100644 --- a/agent/agent.py +++ b/agent/agent.py @@ -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) \ No newline at end of file diff --git a/agent/config/gsm.json b/agent/config/gsm.json index 8590d79..5752979 100644 --- a/agent/config/gsm.json +++ b/agent/config/gsm.json @@ -1,20 +1,20 @@ [ { - "dev":"/dev/ttyUSB0", + "port":"/dev/ttyUSB0", "msisdn":"+393409821322", "imei":"990000862471854" }, { - "dev":"/dev/ttyUSB1", + "port":"/dev/ttyUSB1", "msisdn":"+443312123452", "pin": "12345" }, { - "dev":"/dev/ttyUSB2", + "port":"/dev/ttyUSB2", "msisdn":"+913446435634" }, { - "dev":"/dev/ttyUSB3", + "port":"/dev/ttyUSB3", "msisdn":"+12456345344" } ] \ No newline at end of file diff --git a/agent/gsm/__init__.py b/agent/gsm/__init__.py index aa49d02..b7ac94b 100644 --- a/agent/gsm/__init__.py +++ b/agent/gsm/__init__.py @@ -28,7 +28,7 @@ class Gsm: r = self.cmd("ATI") if "OK" in r: return True - else + else: return False def unlock_sim(self, pin): @@ -52,10 +52,10 @@ class Gsm: r = self.cmd('AT+EMGR=1,7,"' + imei + '"') if "OK" in r: return True - else + else: return False - def check_messages(self): + def fetch_messages(self): r = self.cmd("AT+CMGL=REC UNREAD") print(r) diff --git a/agent/gsm/__init__.pyc b/agent/gsm/__init__.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b77bbfcbe2dd17426fc63d6d119081b76e52bf4a GIT binary patch literal 3003 zcmb_e-EJF26h31+cAO>+DTTJ`1uFxpQCp%4A*8A)gph`a##HN;(n!c!cDLy!`(t*- zR7L4kdchm<3cN%wcm^H-zVD3V5Q!U7EYI=$oH_HIbG|v_=ATOo_kX|nLoCxz6Te@e z*;R-HUn9B5?yPTQ*GSTkq$NpHUWpuuJlVzA$gn?$J=tIQ3>@uj+2WMlFKPEXh!hrK zWnRA`uNt!3qy?DUh24gB=B5Yiws{zrI+Dz32OHbk=}OYk&Vq!)eix==VrZlBcLUA- z0dZ*LP-GH4Jym$>Z{>7-P5*K<1`;y0!~moZ!RBE)80Lo2Sz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