Added the ability to store tag at every scan

This commit is contained in:
Patrick McDonagh
2016-02-29 20:23:09 -06:00
parent 9442685a6a
commit a8e9bec928
2 changed files with 16 additions and 3 deletions

View File

@@ -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("<saved>")
r["lastVal"] = r["val"]
print("-----------")
time.sleep(scan_rate)
except Exception as err:

View File

@@ -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",