diff --git a/python/mysql_cfg.pickle b/python/mysql_cfg.pickle index b5c07ec..2ba82cb 100644 --- a/python/mysql_cfg.pickle +++ b/python/mysql_cfg.pickle @@ -11,4 +11,4 @@ sS'user' p5 S'website' p6 -s. \ No newline at end of file +s. diff --git a/python/pycomm.log b/python/pycomm.log index d83c3a7..7363b30 100644 --- a/python/pycomm.log +++ b/python/pycomm.log @@ -1 +1 @@ -pycomm.ab_comm.clx WARNING 2016-01-25 14:45:25,488 (5, 'forward_close returned False') +pycomm.cip.cip_base WARNING 2016-04-07 16:14:59,861 (5, 'forward_close returned False') diff --git a/python/pycomm_micro/__init__.pyc b/python/pycomm_micro/__init__.pyc index a2df465..bc5fab5 100644 Binary files a/python/pycomm_micro/__init__.pyc and b/python/pycomm_micro/__init__.pyc differ diff --git a/python/pycomm_micro/ab_comm/__init__.pyc b/python/pycomm_micro/ab_comm/__init__.pyc index fc534df..d6cb62c 100644 Binary files a/python/pycomm_micro/ab_comm/__init__.pyc and b/python/pycomm_micro/ab_comm/__init__.pyc differ diff --git a/python/pycomm_micro/ab_comm/clx.pyc b/python/pycomm_micro/ab_comm/clx.pyc index 38ad70b..53c8acf 100644 Binary files a/python/pycomm_micro/ab_comm/clx.pyc and b/python/pycomm_micro/ab_comm/clx.pyc differ diff --git a/python/pycomm_micro/cip/__init__.pyc b/python/pycomm_micro/cip/__init__.pyc index cf7519b..ba3f8dd 100644 Binary files a/python/pycomm_micro/cip/__init__.pyc and b/python/pycomm_micro/cip/__init__.pyc differ diff --git a/python/pycomm_micro/cip/cip_base.pyc b/python/pycomm_micro/cip/cip_base.pyc index 81635c4..1ac6ff7 100644 Binary files a/python/pycomm_micro/cip/cip_base.pyc and b/python/pycomm_micro/cip/cip_base.pyc differ diff --git a/python/pycomm_micro/cip/cip_const.pyc b/python/pycomm_micro/cip/cip_const.pyc index 130af93..ced24b9 100644 Binary files a/python/pycomm_micro/cip/cip_const.pyc and b/python/pycomm_micro/cip/cip_const.pyc differ diff --git a/python/pycomm_micro/common.pyc b/python/pycomm_micro/common.pyc index 7276546..26cab34 100644 Binary files a/python/pycomm_micro/common.pyc and b/python/pycomm_micro/common.pyc differ diff --git a/python/tag_mysql.py b/python/tag_mysql.py index aa84957..e13a86b 100644 --- a/python/tag_mysql.py +++ b/python/tag_mysql.py @@ -13,6 +13,10 @@ with open('mysql_cfg.pickle', 'rb') as cfgFile: con = mysqlcon.connect(**mysql_cfg) + +PLC_IP_ADDRESS = "10.10.10.3" + + def readTag(addr, tag): time.sleep(0.01) c = ClxDriver() @@ -25,17 +29,17 @@ def readTag(addr, tag): print("ERROR RETRIEVING TAG: {}".format(tag)) err = c.get_status() c.close() - print err + print traceback.print_exc() pass c.close() class Tag(): - global readTag, con + global readTag, con, PLC_IP_ADDRESS - def __init__(self, name, tag, data_type, change_threshold, guarantee_sec, mapFn=None, plc_type='CLK'): - self.name = name - self.tag = tag - self.data_type = data_type + def __init__(self, name, tag, data_type, change_threshold, guarantee_sec, mapFn=None, plc_type='CLX'): + self.name = str(name) + self.tag = str(tag) + self.data_type = str(data_type) self.value = None self.last_value = None self.guarantee_sec = guarantee_sec @@ -50,7 +54,7 @@ class Tag(): def read(self, forceSend): writeToDB = False if self.tag: - v = readFn(PLC_IP_ADDRESS, self.tag) + v = self.readFn(PLC_IP_ADDRESS, self.tag) if v: if self.data_type == 'BOOL' or self.data_type == 'STRING': val = v[0] @@ -73,7 +77,9 @@ class Tag(): self.sendToDB() def sendToDB(self): - query = "INSERT INTO tag_vals (dtime, name, val) VALUES ({}, '{}', {})".format(time.time(), self.name, self.value) + # TODO: Datetime + query = "INSERT INTO poconsole.tag_vals (dtime, name, val) VALUES ('{}', '{}', {})".format(time.strftime('%Y-%m-%d %H:%M:%S'), self.name, self.value) + self.last_send_time = time.time() print query # TODO: CHECK ON THIS LOGIC -- with con: cur = con.cursor() diff --git a/python/tagserver_MySQL.py b/python/tagserver_MySQL.py index 0754035..661a42b 100644 --- a/python/tagserver_MySQL.py +++ b/python/tagserver_MySQL.py @@ -10,6 +10,7 @@ import mysql.connector as mysqlcon import pickle from tag_mysql import Tag import traceback +import time with open('mysql_cfg.pickle', 'rb') as pickleconfig: mysql_cfg = pickle.load(pickleconfig) @@ -22,14 +23,15 @@ tag_store = {} def main(): db.connect() cur = db.cursor() - query = "SELECT * FROM poconsole.tags" + query = "SELECT * FROM poconsole.tags WHERE class = 5 AND deleted = 0" cur.execute(query) tags = cur.fetchall() - #(1, u'card_type', 1, u'Card_Past[1].Card_Type', u'STRING', 0.0, 3600, u'card_type_map') + print tags + # [(1, u'Century Counter Up', 5, u'Century_Counter_Up', u'REAL', 10.0, 3600, None, 0)] db.disconnect() for t in tags: - tag_store[t[1]] = Tag(t[1], t[2], t[3], t[4], t[5], mapFn=t[6]) + tag_store[t[1]] = Tag(t[1], t[3], t[4], t[5], t[6], mapFn=t[7]) PLC_IP_ADDRESS = "10.10.10.3" # MAKE THIS A db VALUE diff --git a/www/dbcreate_MySQL.sql b/www/dbcreate_MySQL.sql index 4bf0cd6..df73678 100644 --- a/www/dbcreate_MySQL.sql +++ b/www/dbcreate_MySQL.sql @@ -1,18 +1,46 @@ -CREATE DATABASE TagData; -CREATE TABLE `TagData`.`tags` ( - `id` INT NOT NULL AUTO_INCREMENT, - `tagName` VARCHAR(128) NULL, - `dateAdded` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `units` VARCHAR(16) NULL, - `deleted` INT NULL DEFAULT 0, - PRIMARY KEY (`id`)); +CREATE DATABASE poconsole; +CREATE TABLE IF NOT EXISTS poconsole.tag_classes( + id int(11) NOT NULL AUTO_INCREMENT, + tag_class varchar(64), + description varchar(64), + PRIMARY KEY (id) +); -CREATE TABLE `TagData`.`values` ( - `id` INT NOT NULL AUTO_INCREMENT, - `tagID` INT NULL, - `val` FLOAT NULL, - `dateAdded` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`id`)); +CREATE TABLE IF NOT EXISTS poconsole.tags( + id int(11) NOT NULL AUTO_INCREMENT, + name TEXT, + class int(11), + tag varchar(128), + data_type varchar(32), + change_threshold float, + guarantee_sec integer(11), + map_function varchar(64), + deleted INT NULL DEFAULT 0, + PRIMARY KEY (id) +); + + +CREATE TABLE IF NOT EXISTS poconsole.tag_vals( + id int(11) NOT NULL AUTO_INCREMENT, + dtime datetime, + name varchar(128), + val float, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS poconsole.config ( + id INT NOT NULL AUTO_INCREMENT, + parameter varchar(128), + val varchar(128), + dateAdded TIMESTAMP NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (id) +); + +INSERT INTO poconsole.tag_classes (id, tag_class, description) VALUES (1, 'stroke', 'Stroke Information'); +INSERT INTO poconsole.tag_classes (id, tag_class, description) VALUES (2, 'history', 'Historical Data'); +INSERT INTO poconsole.tag_classes (id, tag_class, description) VALUES (3, 'gaugeoff', 'Gauge Off Data'); +INSERT INTO poconsole.tag_classes (id, tag_class, description) VALUES (4, 'welltest', 'Well Test Data'); +INSERT INTO poconsole.tag_classes (id, tag_class, description) VALUES (5, 'custom', 'Custom tags'); CREATE USER 'website'@'localhost' IDENTIFIED BY 'henrypump'; GRANT ALL ON *.* TO 'website'@'localhost'; @@ -20,4 +48,4 @@ CREATE USER 'admin'@'localhost' IDENTIFIED BY 'henrypump'; GRANT ALL ON *.* to 'admin'@'localhost'; CREATE USER 'admin'@'%' IDENTIFIED BY 'henrypump'; GRANT ALL ON *.* to 'admin'@'%'; -FLUSH PRIVILEGES; \ No newline at end of file +FLUSH PRIVILEGES;