From 50f64b41c20235ad50c16e13c8d167ad80c2fbb2 Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Tue, 24 Apr 2018 11:58:53 -0500 Subject: [PATCH 1/3] Adds code for pressure transmitter --- python_driver/device_base.py | 2 + python_driver/pondlevel.py | 102 ++++++++++++++++++++++++++++++----- 2 files changed, 92 insertions(+), 12 deletions(-) create mode 100644 python_driver/device_base.py diff --git a/python_driver/device_base.py b/python_driver/device_base.py new file mode 100644 index 0000000..edbd53d --- /dev/null +++ b/python_driver/device_base.py @@ -0,0 +1,2 @@ +class deviceBase(object): + pass \ No newline at end of file diff --git a/python_driver/pondlevel.py b/python_driver/pondlevel.py index 76e27e6..68f43f1 100644 --- a/python_driver/pondlevel.py +++ b/python_driver/pondlevel.py @@ -12,10 +12,17 @@ pond_level = { 'value': 15.0, 'timestamp': 0 } + +psi_reading = { + 'value': 0.0, + 'timestamp': 0 +} + send_delta = 0.5 send_time = 300 temp_pl = pond_level['value'] +temp_psi = psi_reading['value'] scaling_persist = persistence.load(filename="scaling_persist.json") strapping_persist = persistence.load(filename="strapping_persist.json") @@ -38,7 +45,7 @@ class start(threading.Thread, deviceBase): deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes) self.daemon = True - self.version = "1" + self.version = "2" self.finished = threading.Event() self.forceSend = False threading.Thread.start(self) @@ -48,6 +55,11 @@ class start(threading.Thread, deviceBase): self.PL_EUMAX = 23.068 self.PL_EUMIN = 0.0 + self.PSI_RAWMAX = 10.0 + self.PSI_RAWMIN = 0.0 + self.PSI_EUMAX = 600.0 + self.PSI_EUMIN = 0.0 + # Strapping table format # { # height: volume, @@ -65,7 +77,7 @@ class start(threading.Thread, deviceBase): def run(self): """Actually run the driver.""" - global pond_level, temp_pl, send_delta, send_time + global pond_level, temp_pl, psi_reading, temp_psi, send_delta, send_time try: self.PL_RAWMAX = scaling_persist['raw_max'] @@ -73,9 +85,19 @@ class start(threading.Thread, deviceBase): self.PL_EUMAX = scaling_persist['eu_max'] self.PL_EUMIN = scaling_persist['eu_min'] except KeyError: - print("No persistence data for scaling parameters.") + print("No persistence data for pond level scaling parameters.") except TypeError: - print("No persistence data for scaling parameters.") + print("No persistence data for pond level scaling parameters.") + + try: + self.PSI_RAWMAX = scaling_persist['psi_raw_max'] + self.PSI_RAWMIN = scaling_persist['psi_raw_min'] + self.PSI_EUMAX = scaling_persist['psi_eu_max'] + self.PSI_EUMIN = scaling_persist['psi_eu_min'] + except KeyError: + print("No persistence data for pressure scaling parameters.") + except TypeError: + print("No persistence data for pressure scaling parameters.") try: if len(strapping_persist.keys()) > 0: @@ -100,25 +122,44 @@ class start(threading.Thread, deviceBase): self.sendtodb("seteumax", self.PL_EUMAX, 0) self.sendtodb("seteumin", self.PL_EUMIN, 0) + self.sendtodb("setpsirawmax", self.PSI_RAWMAX, 0) + self.sendtodb("setpsirawmin", self.PSI_RAWMIN, 0) + self.sendtodb("setpsieumax", self.PSI_EUMAX, 0) + self.sendtodb("setpsieumin", self.PSI_EUMIN, 0) + send_loops = 0 while True: - send_now = False + pl_send_now = False + psi_send_now = False if self.forceSend: print "FORCE SEND: TRUE" - send_now = True + pl_send_now = True + psi_send_now = True mcu_status = self.mcu.getDict() # Gets a dictionary of the IO states cloop_val = float(mcu_status['cloop']) + analog1_val = float(mcu_status['analog1']) + temp_pl = scale_to_eu(cloop_val, self.PL_RAWMAX, self.PL_RAWMIN, self.PL_EUMAX, self.PL_EUMIN) + temp_psi = scale_to_eu(analog1_val, self.PSI_RAWMAX, self.PSI_RAWMIN, self.PSI_EUMAX, self.PSI_EUMIN) + # Check if pond level needs to be sent if abs(temp_pl - pond_level['value']) > send_delta: - print("Sending {} due to value change".format(temp_pl)) - send_now = True + print("Sending pond level {} due to value change".format(temp_pl)) + pl_send_now = True elif (time.time() - pond_level['timestamp']) > send_time: - print("Sending {} due to time limit".format(temp_pl)) - send_now = True + print("Sending pond level {} due to time limit".format(temp_pl)) + pl_send_now = True - if send_now: + # Check if pressure needs to be sent + if abs(temp_psi - psi_reading['value']) > send_delta: + print("Sending pressure psi {} due to value change".format(temp_psi)) + psi_send_now = True + elif (time.time() - psi_reading['timestamp']) > send_time: + print("Sending pressure psi {} due to time limit".format(temp_psi)) + psi_send_now = True + + if pl_send_now: self.sendtodb('pond_level', temp_pl, 0) pond_volume = 0.0 try: @@ -130,6 +171,11 @@ class start(threading.Thread, deviceBase): pond_level['value'] = temp_pl pond_level['timestamp'] = time.time() + if psi_send_now: + self.sendtodb('pressure_psi', temp_psi, 0) + psi_reading['value'] = temp_psi + psi_reading['timestamp'] = time.time() + print("pondlevel driver still alive...") if self.forceSend: if send_loops > 2: @@ -188,7 +234,11 @@ class start(threading.Thread, deviceBase): 'raw_max': self.PL_RAWMAX, 'raw_min': self.PL_RAWMIN, 'eu_max': self.PL_EUMAX, - 'eu_min': self.PL_EUMIN + 'eu_min': self.PL_EUMIN, + 'psi_raw_max': self.PSI_RAWMAX, + 'psi_raw_min': self.PSI_RAWMIN, + 'psi_eu_max': self.PSI_EUMAX, + 'psi_eu_min': self.PSI_EUMIN } persistence.store(scale_obj, filename="scaling_persist.json") @@ -261,3 +311,31 @@ class start(threading.Thread, deviceBase): self.sendtodb("seteumax", self.PL_EUMAX, 0) self.store_scaling_data() return(True) + + def pondlevel_setpsirawmin(self, name, value): + """Set the raw min pressure scaling value.""" + self.PSI_RAWMIN = float(value) + self.sendtodb("setpsirawmin", self.PSI_RAWMIN, 0) + self.store_scaling_data() + return(True) + + def pondlevel_setpsirawmax(self, name, value): + """Set the raw max pressure scaling value.""" + self.PSI_RAWMAX = float(value) + self.sendtodb("setpsirawmax", self.PSI_RAWMAX, 0) + self.store_scaling_data() + return(True) + + def pondlevel_setpsieumin(self, name, value): + """Set the psi min pressure scaling value.""" + self.PSI_EUMIN = float(value) + self.sendtodb("setpsieumin", self.PSI_EUMIN, 0) + self.store_scaling_data() + return(True) + + def pondlevel_setpsieumax(self, name, value): + """Set the psi max pressure scaling value.""" + self.PSI_EUMAX = float(value) + self.sendtodb("setpsieumax", self.PSI_EUMAX, 0) + self.store_scaling_data() + return(True) From 115f5ed9f04f79dbf5fa3962a5ec94d4117fc7e4 Mon Sep 17 00:00:00 2001 From: Patrick McDonagh Date: Mon, 30 Apr 2018 14:07:22 -0500 Subject: [PATCH 2/3] Templates for pressure transmitter and sets level/volume to only send every 5 min --- html_templates/Overview.html | 35 +++++++++++ html_templates/Scaling.html | 113 ++++++++++++++++++++++++++++++++++- html_templates/Trends.html | 2 +- python_driver/config.txt | 2 +- python_driver/pondlevel.py | 19 +++--- 5 files changed, 161 insertions(+), 10 deletions(-) diff --git a/html_templates/Overview.html b/html_templates/Overview.html index d7eaf67..632ab14 100644 --- a/html_templates/Overview.html +++ b/html_templates/Overview.html @@ -65,6 +65,41 @@ <% } %> + +<% if (channels["pondlevel.pressure_psi"].value > 0.0){ %> +
+
+

Pressure

+
+
+
+
+ + + +
+ + <%= channels["pondlevel.pressure_psi"].timestamp %> + +
+
+ +
+
+
+
+<% } %> +

Configuration

diff --git a/html_templates/Scaling.html b/html_templates/Scaling.html index 29f104e..4cfa93a 100644 --- a/html_templates/Scaling.html +++ b/html_templates/Scaling.html @@ -1,7 +1,10 @@
- +
+

Level

+
+

Raw Max (mA)

@@ -104,6 +107,114 @@
+
+
+

Pressure

+
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +
+ +