Config Pages, functions and tables added
This commit is contained in:
@@ -37,20 +37,50 @@ def readTag(addr, tag):
|
||||
c.close()
|
||||
|
||||
def main():
|
||||
|
||||
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
query = "SELECT * FROM tags WHERE deleted = 0;"
|
||||
cur.execute(query)
|
||||
tags = cur.fetchall()
|
||||
|
||||
PLC_IP_ADDRESS = "10.10.10.3" # MAKE THIS A db VALUE
|
||||
scan_rate = 10
|
||||
configObj = {}
|
||||
|
||||
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
query = "SELECT parameter, val FROM config GROUP BY parameter;"
|
||||
cur.execute(query)
|
||||
config = cur.fetchall()
|
||||
for x in config:
|
||||
configObj[x[0]] = x[1]
|
||||
|
||||
try:
|
||||
PLC_IP_ADDRESS = str(configObj['ip_address'])
|
||||
print("FYI, using PLC IP Address from the database {0}".format(PLC_IP_ADDRESS))
|
||||
except KeyError:
|
||||
print("FYI, there is no PLC IP Address stored in the database, defaulting to 192.168.1.10")
|
||||
PLC_IP_ADDRESS = "192.168.1.10"
|
||||
|
||||
try:
|
||||
scan_rate = int(configObj['scan_rate'])
|
||||
print("FYI, using Scan Rate from the database {0}".format(scan_rate))
|
||||
except KeyError:
|
||||
print("FYI, there is no Scan Rate stored in the database, defaulting to 10 seconds")
|
||||
scan_rate = 10
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
tagList = []
|
||||
print("\nScan List\n--------------")
|
||||
if len(tags) > 0:
|
||||
for t in tags:
|
||||
tagList.append({"id": int(t[0]), "name": t[1], "val": None, "lastVal": None})
|
||||
print(tagList)
|
||||
print(t[1])
|
||||
print("--------------\n")
|
||||
|
||||
while True:
|
||||
try:
|
||||
@@ -61,7 +91,7 @@ def main():
|
||||
with con:
|
||||
cur = con.cursor()
|
||||
aQuery = """INSERT INTO vals (tagID, val) VALUES ('%d', '%f');""" % (r["id"], float(r["val"]))
|
||||
print(aQuery)
|
||||
# print(aQuery)
|
||||
cur.execute(aQuery)
|
||||
con.commit()
|
||||
r["lastVal"] = r["val"]
|
||||
|
||||
Reference in New Issue
Block a user