Able to switch back and forth between MySQL and SQLite

This commit is contained in:
Patrick McDonagh
2016-04-13 17:17:15 -05:00
parent 83c63bde31
commit 667f654077
11 changed files with 405 additions and 236 deletions

View File

@@ -19,7 +19,7 @@ def readTag(addr, tag):
v = c.read_tag(tag)
return v
except Exception:
print("ERROR RETRIEVING TAG: {}".format(tag))
print("ERROR RETRIEVING TAG: {} at {}".format(tag, addr))
err = c.get_status()
c.close()
print err
@@ -49,7 +49,7 @@ class Tag():
def read(self, forceSend):
writeToDB = False
if self.tag:
v = readFn(self.plc_ip_address, self.tag)
v = self.readFn(str(self.plc_ip_address), str(self.tag))
if v:
if self.data_type == 'BOOL' or self.data_type == 'STRING':
val = v[0]
@@ -73,9 +73,10 @@ class Tag():
def sendToDB(self):
query = "INSERT INTO tag_vals (dtime, tagID, val) VALUES ({}, '{}', {})".format(time.time(), self.db_id, self.value)
self.last_send_time = time.time()
print query
# TODO: CHECK ON THIS LOGIC -- with con:
cur = con.cursor()
cur.execute(query)
con.commit()
cur.close()
with con:
cur = con.cursor()
cur.execute(query)
con.commit()
cur.close()