From 01c23b142c4b42f96e82bd06227af754a72eefcc Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Fri, 13 May 2016 09:26:41 -0500 Subject: [PATCH] Adds handshaking --- tag | 2 +- tagserver.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tag b/tag index c610c9f..156e3c4 160000 --- a/tag +++ b/tag @@ -1 +1 @@ -Subproject commit c610c9fa2cf18c547fefc9ee83db9f352d59609c +Subproject commit 156e3c4194f0932d0fa680904033df8e7d918232 diff --git a/tagserver.py b/tagserver.py index 67a21fc..ed6e103 100644 --- a/tagserver.py +++ b/tagserver.py @@ -17,6 +17,8 @@ import json web_address = "http://localhost:3000" scan_rate = 30 # seconds save_all = "test" # use True, False, or any string +plc_handshake_tag = None +last_handshake_time = 0 tag_store = {} device_types = {} @@ -69,6 +71,17 @@ def main(): print("Error getting save-all: {}".format(e)) print("I'll just use {} as the save-all parameter...".format(save_all)) + try: + handshake_req_data = {"where": {"parameter": "plc_handshake_tag"}} + handshake_req = requests.get('{}/config'.format(web_address), params=handshake_req_data) + handshake_try = json.loads(handshake_req.text) + if len(handshake_req_try) > 0: + plc_handshake_tag = handshake_try[0]['val'] + plc_handshake_tag = Tag("PLC Handshake", plc_handshake_tag, 0, "BOOL", 0, 0) + except Exception, e: + print("Error getting PLC Handshake Tag: {}".format(e)) + print("I'll just use {} as the PLC Handshake Tag parameter...".format(plc_handshake_tag)) + for t in tags: # name, tag, db_id, data_type, change_threshold, guarantee_sec, mapFn=None, device_type='CLX', ip_address='192.168.1.10'): tag_store[t['name']] = Tag(t['name'], t['tag'], t['id'], t['data_type'], t['change_threshold'], t['guarantee_sec'], mapFn=t['map_function'], ip_address=t['deviceID']['address'], device_type=device_types[t['deviceID']['device_type']]) @@ -80,6 +93,11 @@ def main(): except: print("ERROR EVALUATING {}".format(tag)) traceback.print_exc() + + if plc_handshake_tag: + if time.time() - last_handshake_time > 30.0: + plc_handshake_tag.write(1) + last_handshake_time = time.time() time.sleep(scan_rate) if __name__ == '__main__':