aggiunto invio eventi, get status all' inizio
parent
e09fbc26a2
commit
63ff03d56f
|
|
@ -8,40 +8,50 @@ URL_RESPONSE = 'tscprinter/risposta/'
|
||||||
URL_HELLO = 'tscprinter/driver_acceso/'
|
URL_HELLO = 'tscprinter/driver_acceso/'
|
||||||
|
|
||||||
django_addr = ("http://{}:{}/"
|
django_addr = ("http://{}:{}/"
|
||||||
.format(os.getenv('DJANGO_HOST', '127.0.0.1'),
|
.format(os.getenv('DJANGO_HOST', '127.0.0.1'),
|
||||||
os.getenv('DJANGO_PORT')))
|
os.getenv('DJANGO_PORT')))
|
||||||
|
|
||||||
|
|
||||||
def notifier(queue_out, logger):
|
def notifier(queue_out, logger):
|
||||||
logger.warning("Notifier started")
|
logger.warning("Notifier started")
|
||||||
while True:
|
while True:
|
||||||
msg = queue_out.get(block=True)
|
msg = queue_out.get(block=True)
|
||||||
riuscita = False
|
riuscita = False
|
||||||
while not riuscita:
|
while not riuscita:
|
||||||
try:
|
try:
|
||||||
requests.post(django_addr+msg['url'], json=msg['msg'])
|
requests.post(django_addr+msg['url'], json=msg['msg'])
|
||||||
riuscita = True
|
riuscita = True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.debug("django irraggiungibile. aspetto 2 sec...")
|
logger.debug("django irraggiungibile. aspetto 2 sec...")
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
|
||||||
def send_response(queue_out, ip, command, data):
|
def send_response(queue_out, ip, command, data):
|
||||||
resp= {
|
resp= {
|
||||||
'ip': ip,
|
'ip': ip,
|
||||||
'comando': command,
|
'comando': command,
|
||||||
'dati': data
|
'dati': data
|
||||||
}
|
}
|
||||||
msg = {
|
msg = {
|
||||||
'url' : URL_RESPONSE,
|
'url' : URL_RESPONSE,
|
||||||
'msg': resp
|
'msg': resp
|
||||||
}
|
}
|
||||||
print(f"Mando Risposta: {msg}")
|
print(f"Mando Risposta: {msg}")
|
||||||
queue_out.put(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):
|
def send_hello(queue_out):
|
||||||
queue_out.put({
|
queue_out.put({
|
||||||
'url': URL_HELLO,
|
'url': URL_HELLO,
|
||||||
'msg': {}
|
'msg': {}
|
||||||
})
|
})
|
||||||
|
|
@ -102,6 +102,7 @@ def tsc_printer(q_in: queue.Queue, q_out: queue.Queue, q_cmd: queue.Queue, ip: s
|
||||||
try:
|
try:
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as prt:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as prt:
|
||||||
prt.connect((ip, port))
|
prt.connect((ip, port))
|
||||||
|
get_status()
|
||||||
while True:
|
while True:
|
||||||
itm = q_in.get(block=True)
|
itm = q_in.get(block=True)
|
||||||
cmd = itm['name']
|
cmd = itm['name']
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue