diff options
author | Piotr Dobrowolski <admin@tastycode.pl> | 2017-01-17 01:05:45 +0100 |
---|---|---|
committer | Piotr Dobrowolski <admin@tastycode.pl> | 2017-01-17 01:05:45 +0100 |
commit | 9209cd077ac2b246b99196f42cae72ce4ebb22b5 (patch) | |
tree | fcdb6d529c2058e9afaacfa7f9d267d05c15acf3 | |
parent | dc1a83c9819c8c4a58481d637ac804fe2d457a93 (diff) | |
download | bitvend-9209cd077ac2b246b99196f42cae72ce4ebb22b5.tar.gz bitvend-9209cd077ac2b246b99196f42cae72ce4ebb22b5.tar.bz2 bitvend-9209cd077ac2b246b99196f42cae72ce4ebb22b5.tar.xz bitvend-9209cd077ac2b246b99196f42cae72ce4ebb22b5.zip |
Add subsystems status display
-rw-r--r-- | bitvend.py | 4 | ||||
-rw-r--r-- | bitvend/processor.py | 9 | ||||
-rw-r--r-- | mdb/device.py | 11 | ||||
-rw-r--r-- | templates/base.html | 12 | ||||
-rw-r--r-- | templates/index.html | 5 |
5 files changed, 34 insertions, 7 deletions
@@ -31,7 +31,9 @@ proc.init_app(app) @app.route('/') def index(): return flask.render_template( - 'index.html', items=app.config['ITEMS']) + 'index.html', items=app.config['ITEMS'], + mdb_online=dev.online, + proc_online=proc.online) @app.route('/log') def log(): diff --git a/bitvend/processor.py b/bitvend/processor.py index 73f5c17..40313f7 100644 --- a/bitvend/processor.py +++ b/bitvend/processor.py @@ -12,7 +12,7 @@ class PaymentProcessor(threading.Thread): daemon = True input_address = None device = None - last_pong = None + last_pong = 0 app = None def __init__(self, device, input_address=None, chain_id=None, app=None): @@ -112,7 +112,6 @@ class PaymentProcessor(threading.Thread): def keepalive(self, ws): # Keepalive thread target, just send ping once in a while - self.last_pong = time.time() while True: # FIXME check last ping time ws.send(json.dumps({ @@ -120,7 +119,11 @@ class PaymentProcessor(threading.Thread): })) time.sleep(20) - if time.time() - self.last_pong > 30: + if time.time() - self.last_pong > 60: self.logger.warning('Closing socket for inactivity') ws.close() return + + @property + def online(self): + return time.time() - self.last_pong < 40 diff --git a/mdb/device.py b/mdb/device.py index 7b23afe..0b1940c 100644 --- a/mdb/device.py +++ b/mdb/device.py @@ -128,7 +128,7 @@ class MDBDevice(object): class CashlessMDBDevice(MDBDevice): base_address = CASHLESS_RESET state = 'IDLE' - + last_poll = 0 config_data = [ 0x01, # Feature level 0x19, 0x85, # PLN x---DD @@ -160,6 +160,7 @@ class CashlessMDBDevice(MDBDevice): return [] elif req.command == CASHLESS_POLL: + self.last_poll = time.time() try: msg = self.poll_queue.get_nowait() self.logger.info('Sending POLL response: %r', msg) @@ -195,7 +196,7 @@ class CashlessMDBDevice(MDBDevice): elif req.data[0] == 0x04: self.logger.info('VEND: session complete %r', req) - self.state = 'IDLE' + self.state = 'OK' return [0x07] elif req.data[0] == 0x05: @@ -227,7 +228,7 @@ class CashlessMDBDevice(MDBDevice): self.logger.info(' -> Disp rows: %d', disp_rows) self.logger.info(' -> Disp info: %d', disp_info) - self.state = 'IDLE' + self.state = 'OK' return [0x01] + self.config_data @@ -254,6 +255,10 @@ class CashlessMDBDevice(MDBDevice): # Called when user selects a product return True + @property + def online(self): + return time.time() - self.last_poll < 5 + # # This is mostly unfinished Bill validator implementation diff --git a/templates/base.html b/templates/base.html index 77f572b..fe7eed1 100644 --- a/templates/base.html +++ b/templates/base.html @@ -38,6 +38,18 @@ body { </button> </div> <div class="navbar-collapse collapse" id="navbar-main"> + <p class="navbar-text navbar-nav"> + {% if mdb_online %} + <span class="label label-success">mdb: online</span> + {% else %} + <span class="label label-danger">mdb: offline</span> + {% endif %} + {% if proc_online %} + <span class="label label-success">payments: online</span> + {% else %} + <span class="label label-danger">payments: offline</span> + {% endif %} + </p> <p class="navbar-text navbar-right"> 1zł = {{ format_btc(from_local_currency(100)) }} </p> diff --git a/templates/index.html b/templates/index.html index b8f2e6e..25760ba 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,5 +1,10 @@ {% extends "base.html" %} {% block content %} + {% if not mdb_online or not proc_online %} + <div class="alert alert-warning"> + <b>Some of the subsystems are misbehaving.</b> Please avoid making payments, unless in absolute need of Mate. + </div> + {% endif %} <div class="alert alert-info"> This is just a test deployment of Warsaw Hackerspace Vending Machine Bitcoin Payments System™.<br /> <b>Please report any issues to <a href="mailto:informatic@hackerspace.pl" class="alert-link">informatic@hackerspace.pl</a>.</b> |