diff --git a/driver/notifier.py b/driver/notifier.py index 2006321..6df7d47 100644 --- a/driver/notifier.py +++ b/driver/notifier.py @@ -8,40 +8,50 @@ URL_RESPONSE = 'tscprinter/risposta/' URL_HELLO = 'tscprinter/driver_acceso/' django_addr = ("http://{}:{}/" - .format(os.getenv('DJANGO_HOST', '127.0.0.1'), - os.getenv('DJANGO_PORT'))) + .format(os.getenv('DJANGO_HOST', '127.0.0.1'), + os.getenv('DJANGO_PORT'))) def notifier(queue_out, logger): - logger.warning("Notifier started") - while True: - msg = queue_out.get(block=True) - riuscita = False - while not riuscita: - try: - requests.post(django_addr+msg['url'], json=msg['msg']) - riuscita = True - except Exception as e: - logger.debug("django irraggiungibile. aspetto 2 sec...") - time.sleep(2) - print(e) + logger.warning("Notifier started") + while True: + msg = queue_out.get(block=True) + riuscita = False + while not riuscita: + try: + requests.post(django_addr+msg['url'], json=msg['msg']) + riuscita = True + except Exception as e: + logger.debug("django irraggiungibile. aspetto 2 sec...") + time.sleep(2) + print(e) def send_response(queue_out, ip, command, data): - resp= { - 'ip': ip, - 'comando': command, - 'dati': data - } - msg = { - 'url' : URL_RESPONSE, - 'msg': resp - } - print(f"Mando Risposta: {msg}") - queue_out.put(msg) - + resp= { + 'ip': ip, + 'comando': command, + 'dati': data + } + msg = { + 'url' : URL_RESPONSE, + 'msg': resp + } + print(f"Mando Risposta: {msg}") + queue_out.put(msg) + +def send_event(queue_out, ip, connected, error, warning): + msg = { + 'ip': ip, + 'connected': connected, + 'error' : error, + 'warning': warning + } + print(f"Mando Evento: {msg}") + queue_out.put(msg) + def send_hello(queue_out): - queue_out.put({ - 'url': URL_HELLO, - 'msg': {} - }) \ No newline at end of file + queue_out.put({ + 'url': URL_HELLO, + 'msg': {} + }) \ No newline at end of file diff --git a/driver/tsc_printer.py b/driver/tsc_printer.py index 9c03cd8..185a751 100644 --- a/driver/tsc_printer.py +++ b/driver/tsc_printer.py @@ -102,6 +102,7 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s try: with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as prt: prt.connect((ip, port)) + get_status() while True: itm = q_in.get(block=True) cmd = itm['name']