diff --git a/python/tagserver_SQLite.py b/python/tagserver_SQLite.py index 8de0543..7a663c8 100644 --- a/python/tagserver_SQLite.py +++ b/python/tagserver_SQLite.py @@ -70,6 +70,17 @@ def main(): print("FYI, there is no Scan Rate stored in the database, defaulting to 10 seconds") scan_rate = 10 + try: + sa_test = str(configObj['save_all']) + if sa_test == "true": + save_all = True + else: + save_all = False + print("FYI, value for save_all is {0}".format(save_all)) + except KeyError: + print("FYI, there is no save_all value stored in the database, using False") + save_all = False + @@ -87,15 +98,16 @@ def main(): for r in tagList: r["val"] = readTag(PLC_IP_ADDRESS, str(r['name']))[0] print("{0} - {1}".format(r["name"], r["val"])) - if not r["val"] == r["lastVal"]: + if (not save_all and not r["val"] == r["lastVal"]) or save_all: with con: cur = con.cursor() aQuery = """INSERT INTO vals (tagID, val) VALUES ('%d', '%f');""" % (r["id"], float(r["val"])) # print(aQuery) cur.execute(aQuery) con.commit() + print("") r["lastVal"] = r["val"] - + print("-----------") time.sleep(scan_rate) except Exception as err: diff --git a/tsdriver.py b/tsdriver.py index 01bcc05..4fa2fe2 100644 --- a/tsdriver.py +++ b/tsdriver.py @@ -30,7 +30,8 @@ def setupChannels(): tagJSObj = json.loads(requests.get(addr + "/json/tag").text) if tagJSObj['status'] == "OK": for t in tagJSObj['tags']: - channels[str(t['tagName'])] = { + channel_name = re.sub(r'\W+', '', t['vanityName']).lower() + channels[str(channel_name)] = { 'tagID': t['id'], 'last_value': -999, 'data_type': "float",