Adds a bunch of Meshify stuff.
Can be started and stopped from Meshify
This commit is contained in:
1
POCloud/Alerts.html
Normal file
1
POCloud/Alerts.html
Normal file
@@ -0,0 +1 @@
|
||||
<module>Alerts</module>
|
||||
211
POCloud/Channel.py
Normal file
211
POCloud/Channel.py
Normal file
@@ -0,0 +1,211 @@
|
||||
"""Define Meshify channel class."""
|
||||
from pycomm.ab_comm.clx import Driver as ClxDriver
|
||||
from pycomm.cip.cip_base import CommError, DataError
|
||||
import time
|
||||
|
||||
|
||||
def binarray(intval):
|
||||
"""Split an integer into its bits."""
|
||||
bin_string = '{0:08b}'.format(intval)
|
||||
bin_arr = [i for i in bin_string]
|
||||
bin_arr.reverse()
|
||||
return bin_arr
|
||||
|
||||
|
||||
def read_tag(addr, tag):
|
||||
"""Read a tag from the PLC."""
|
||||
c = ClxDriver()
|
||||
try:
|
||||
if c.open(addr):
|
||||
try:
|
||||
v = c.read_tag(tag)
|
||||
return v
|
||||
except DataError:
|
||||
c.close()
|
||||
print("Data Error during readTag({}, {})".format(addr, tag))
|
||||
except CommError:
|
||||
# err = c.get_status()
|
||||
c.close()
|
||||
print("Could not connect during readTag({}, {})".format(addr, tag))
|
||||
# print err
|
||||
except AttributeError as e:
|
||||
c.close()
|
||||
print("AttributeError during readTag({}, {}): \n{}".format(addr, tag, e))
|
||||
c.close()
|
||||
return False
|
||||
|
||||
|
||||
def read_array(addr, tag, start, end):
|
||||
"""Read an array from the PLC."""
|
||||
c = ClxDriver()
|
||||
if c.open(addr):
|
||||
arr_vals = []
|
||||
try:
|
||||
for i in range(start, end):
|
||||
tag_w_index = tag + "[{}]".format(i)
|
||||
v = c.read_tag(tag_w_index)
|
||||
# print('{} - {}'.format(tag_w_index, v))
|
||||
arr_vals.append(round(v[0], 4))
|
||||
# print(v)
|
||||
if len(arr_vals) > 0:
|
||||
return arr_vals
|
||||
else:
|
||||
print("No length for {}".format(addr))
|
||||
return False
|
||||
except Exception:
|
||||
print("Error during readArray({}, {}, {}, {})".format(addr, tag, start, end))
|
||||
err = c.get_status()
|
||||
c.close()
|
||||
print err
|
||||
pass
|
||||
c.close()
|
||||
|
||||
|
||||
def write_tag(addr, tag, val):
|
||||
"""Write a tag value to the PLC."""
|
||||
c = ClxDriver()
|
||||
if c.open(addr):
|
||||
try:
|
||||
cv = c.read_tag(tag)
|
||||
wt = c.write_tag(tag, val, cv[1])
|
||||
return wt
|
||||
except Exception:
|
||||
print("Error during writeTag({}, {}, {})".format(addr, tag, val))
|
||||
err = c.get_status()
|
||||
c.close()
|
||||
print err
|
||||
c.close()
|
||||
|
||||
|
||||
class Channel:
|
||||
"""Holds the configuration for a Meshify channel."""
|
||||
|
||||
def __init__(self, ip, mesh_name, plc_tag, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False):
|
||||
"""Initialize the channel."""
|
||||
self.plc_ip = ip
|
||||
self.mesh_name = mesh_name
|
||||
self.plc_tag = plc_tag
|
||||
self.data_type = data_type
|
||||
self.last_value = None
|
||||
self.value = None
|
||||
self.last_send_time = 0
|
||||
self.chg_threshold = chg_threshold
|
||||
self.guarantee_sec = guarantee_sec
|
||||
self.map_ = map_
|
||||
self.write_enabled = write_enabled
|
||||
|
||||
def __str__(self):
|
||||
"""Create a string for the channel."""
|
||||
return "{}: {}\nvalue: {}, last_send_time: {}".format(self.mesh_name, self.plc_tag, self.value, self.last_send_time)
|
||||
|
||||
def read(self, force_send=False):
|
||||
"""Read the value and check to see if needs to be stored."""
|
||||
send_needed = False
|
||||
send_reason = ""
|
||||
if self.plc_tag:
|
||||
v = read_tag(self.plc_ip, self.plc_tag)
|
||||
if v:
|
||||
if self.data_type == 'BOOL' or self.data_type == 'STRING':
|
||||
if self.last_send_time == 0:
|
||||
send_needed = True
|
||||
send_reason = "no send time"
|
||||
elif self.value is None:
|
||||
send_needed = True
|
||||
send_reason = "no value"
|
||||
elif not (self.value == v[0]):
|
||||
if self.map_:
|
||||
if not self.value == self.map_[v[0]]:
|
||||
send_needed = True
|
||||
send_reason = "value change"
|
||||
else:
|
||||
send_needed = True
|
||||
send_reason = "value change"
|
||||
elif (time.time() - self.last_send_time) > self.guarantee_sec:
|
||||
send_needed = True
|
||||
send_reason = "guarantee sec"
|
||||
elif force_send:
|
||||
send_needed = True
|
||||
send_reason = "forced"
|
||||
else:
|
||||
if self.last_send_time == 0:
|
||||
send_needed = True
|
||||
send_reason = "no send time"
|
||||
elif self.value is None:
|
||||
send_needed = True
|
||||
send_reason = "no value"
|
||||
elif abs(self.value - v[0]) > self.chg_threshold:
|
||||
send_needed = True
|
||||
send_reason = "change threshold"
|
||||
elif (time.time() - self.last_send_time) > self.guarantee_sec:
|
||||
send_needed = True
|
||||
send_reason = "guarantee sec"
|
||||
elif force_send:
|
||||
send_needed = True
|
||||
send_reason = "forced"
|
||||
if send_needed:
|
||||
self.last_value = self.value
|
||||
if self.map_:
|
||||
try:
|
||||
self.value = self.map_[v[0]]
|
||||
except KeyError:
|
||||
print("Cannot find a map value for {} in {} for {}".format(v[0], self.map_, self.mesh_name))
|
||||
self.value = v[0]
|
||||
else:
|
||||
self.value = v[0]
|
||||
self.last_send_time = time.time()
|
||||
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||
return send_needed
|
||||
|
||||
|
||||
class BoolArrayChannels(Channel):
|
||||
"""Hold the configuration for a set of boolean array channels."""
|
||||
|
||||
def compare_values(self, new_val_dict):
|
||||
"""Compare new values to old values to see if the values need storing."""
|
||||
send = False
|
||||
for idx in new_val_dict:
|
||||
try:
|
||||
if new_val_dict[idx] != self.last_value[idx]:
|
||||
send = True
|
||||
except KeyError:
|
||||
print("Key Error in self.compare_values for index {}".format(idx))
|
||||
send = True
|
||||
return send
|
||||
|
||||
def read(self, force_send=False):
|
||||
"""Read the value and check to see if needs to be stored."""
|
||||
send_needed = False
|
||||
send_reason = ""
|
||||
if self.plc_tag:
|
||||
v = read_tag(self.plc_ip, self.plc_tag)
|
||||
if v:
|
||||
bool_arr = binarray(v[0])
|
||||
new_val = {}
|
||||
for idx in self.map_:
|
||||
try:
|
||||
new_val[self.map_[idx]] = bool_arr[idx]
|
||||
except KeyError:
|
||||
print("Not able to get value for index {}".format(idx))
|
||||
|
||||
if self.last_send_time == 0:
|
||||
send_needed = True
|
||||
send_reason = "no send time"
|
||||
elif self.value is None:
|
||||
send_needed = True
|
||||
send_reason = "no value"
|
||||
elif self.compare_values(new_val):
|
||||
send_needed = True
|
||||
send_reason = "value change"
|
||||
elif (time.time() - self.last_send_time) > self.guarantee_sec:
|
||||
send_needed = True
|
||||
send_reason = "guarantee sec"
|
||||
elif force_send:
|
||||
send_needed = True
|
||||
send_reason = "forced"
|
||||
|
||||
if send_needed:
|
||||
self.value = new_val
|
||||
self.last_value = self.value
|
||||
self.last_send_time = time.time()
|
||||
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||
return send_needed
|
||||
38
POCloud/Control.html
Normal file
38
POCloud/Control.html
Normal file
@@ -0,0 +1,38 @@
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
|
||||
<div class="row row-flex">
|
||||
<div class="col-xs-12 text-center">
|
||||
<h1>Control</h1>
|
||||
</div>
|
||||
<div class='col-xs-6 text-center box-me'>
|
||||
<!-- Use data-confirm-message to set the exact message that pops up in the alert window. -->
|
||||
|
||||
<a href="#"
|
||||
data-confirm-message="Are you sure you want to remotely start the transfer station?"
|
||||
data-refreshpause="1"
|
||||
data-command=""
|
||||
data-staticsend="{'tag': 'cmd_Start', 'val': 1}"
|
||||
data-channelId="<%= channels["transferstation.writeplctag"].channelId %>"
|
||||
data-techname="<%=channels["transferstation.writeplctag"].techName %>"
|
||||
data-name="<%= channels["transferstation.writeplctag"].name%>"
|
||||
data-nodechannelcurrentId="<%= channels["transferstation.writeplctag"].nodechannelcurrentId %>"
|
||||
id="<%= channels["transferstation.writeplctag"].channelId %>"
|
||||
class="btn btn-large btn-theme animated confirmstatic pad15">
|
||||
Start</a>
|
||||
</div>
|
||||
<div class='col-xs-6 text-center box-me'>
|
||||
<a href="#"
|
||||
data-confirm-message="Are you sure you want to remotely stop the transfer station?"
|
||||
data-refreshpause="1"
|
||||
data-command=""
|
||||
data-staticsend="{'tag': 'cmd_Stop', 'val': 1}"
|
||||
data-channelId="<%= channels["transferstation.writeplctag"].channelId %>"
|
||||
data-techname="<%=channels["transferstation.writeplctag"].techName %>"
|
||||
data-name="<%= channels["transferstation.writeplctag"].name%>"
|
||||
data-nodechannelcurrentId="<%= channels["transferstation.writeplctag"].nodechannelcurrentId %>"
|
||||
id="<%= channels["transferstation.writeplctag"].channelId %>"
|
||||
class="btn btn-large btn-theme animated confirmstatic pad15">
|
||||
Stop</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
33
POCloud/Maps.py
Normal file
33
POCloud/Maps.py
Normal file
@@ -0,0 +1,33 @@
|
||||
"""Holds map values for advvfdipp."""
|
||||
|
||||
transferstation_map = {
|
||||
|
||||
'alarm': {0: "OK", 1: "Alarmed"},
|
||||
'lockout': {0: "OK", 1: "Locked Out"},
|
||||
'enable_disable': {0: "Disabled", 1: "Enabled"},
|
||||
'run': {0: "Stopped", 1: "Running"},
|
||||
'bit_channels': {
|
||||
'system_enabled': {
|
||||
1: 'system1_enabled',
|
||||
2: 'system2_enabled',
|
||||
3: 'system3_enabled'
|
||||
},
|
||||
'ft_enabled': {
|
||||
0: 'ft01_enabled',
|
||||
1: 'ft11_enabled',
|
||||
2: 'ft21_enabled',
|
||||
3: 'ft31_enabled'
|
||||
},
|
||||
'lt_enabled': {
|
||||
0: 'lt01_enabled',
|
||||
1: 'lt11_enabled',
|
||||
2: 'lt21_enabled',
|
||||
3: 'lt31_enabled'
|
||||
},
|
||||
'ptx2_enabled': {
|
||||
1: 'pt12_enabled',
|
||||
2: 'pt22_enabled',
|
||||
3: 'pt32_enabled'
|
||||
}
|
||||
}
|
||||
}
|
||||
9
POCloud/NodeDetailHeader.html
Normal file
9
POCloud/NodeDetailHeader.html
Normal file
@@ -0,0 +1,9 @@
|
||||
<div class='col-xs-1'>
|
||||
<div class="<%= nodecolors.statuscolor %> nodecolor"></div>
|
||||
</div>
|
||||
<div class='col-xs-6'>
|
||||
<h3><%= node.vanityname %></h3>
|
||||
</div>
|
||||
<div class='col-xs-2'>
|
||||
<h3><%= channels["transferstation.cmd_run"].value %></h3>
|
||||
</div>
|
||||
35
POCloud/Nodelist.html
Normal file
35
POCloud/Nodelist.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<style>
|
||||
.header h4 {
|
||||
position: relative;
|
||||
top: 0.9em;
|
||||
}
|
||||
.header h2 {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
color: #aaa;
|
||||
margin: 0.75em 0;
|
||||
}
|
||||
.header p {
|
||||
font-size: 24px;
|
||||
color: black;
|
||||
font-weight: 600;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="row header">
|
||||
<div class="col-xs-1">
|
||||
<div class="<%= nodecolors.statuscolor %> nodecolor"></div>
|
||||
</div>
|
||||
|
||||
<div class="col-xs-2">
|
||||
<img src="<%= nodeimgurl %>" />
|
||||
</div>
|
||||
|
||||
<div class="col-xs-4">
|
||||
<h4><%= node.vanityname %></h4>
|
||||
</div>
|
||||
<div class="col-xs-2">
|
||||
<h2>Flow Rate</h2>
|
||||
<p><%= Math.round(channels["transferstation.flow_rate"].value * 100) / 100 %> GPM</p>
|
||||
</div>
|
||||
</div>
|
||||
503
POCloud/Overview.html
Normal file
503
POCloud/Overview.html
Normal file
@@ -0,0 +1,503 @@
|
||||
<% if ((channels['transferstation.lt01_enabled'].value == 1) || (channels['transferstation.ft01_enabled'].value == 1)) { %>
|
||||
<div class="row row-flex box-me" id="sharedSystems">
|
||||
<div class="col-xs-12 text-center">
|
||||
<h1>Shared Devices</h1>
|
||||
</div>
|
||||
|
||||
<% if (channels["transferstation.lt01_enabled"].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Pond Level (LT01)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-lt01_level"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.lt01_level"
|
||||
data-units="ft."
|
||||
data-min="0"
|
||||
data-max="25"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels["transferstation.lt01_level"].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="lt01_level">
|
||||
<%= channels["transferstation.lt01_level"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
||||
<% if (channels['transferstation.ft01_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>System Flow (FT01)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-ft01_flow"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.ft01_flow"
|
||||
data-units="GPM"
|
||||
data-min="0"
|
||||
data-max="1000"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.ft01_flow'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="ft01_flow">
|
||||
<%= channels["transferstation.ft01_flow"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
||||
|
||||
<% if (channels["transferstation.system1_enabled"].value == 1) { %>
|
||||
<div class="row row-flex box-me" id="system1">
|
||||
<div class="col-xs-12 text-center">
|
||||
<h1>System 1</h1>
|
||||
</div>
|
||||
<% if (channels['transferstation.lt11_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Pond Level (LT11)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-lt11_level"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.lt11_level"
|
||||
data-units="ft."
|
||||
data-min="0"
|
||||
data-max="25"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.lt11_level'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="lt11_level">
|
||||
<%= channels["transferstation.lt11_level"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Booster Pump Intake Pressure (PT11)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-pt11_pressure"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.pt11_pressure"
|
||||
data-units="PSI"
|
||||
data-min="0"
|
||||
data-max="100"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.pt11_pressure'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="pt11_pressure">
|
||||
<%= channels["transferstation.pt11_pressure"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% if (channels['transferstation.pt12_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Booster Pump Discharge Pressure (PT12)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-pt12_pressure"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.pt12_pressure"
|
||||
data-units="PSI"
|
||||
data-min="0"
|
||||
data-max="100"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.pt12_pressure'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="pt12_pressure">
|
||||
<%= channels["transferstation.pt12_pressure"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (channels['transferstation.ft11_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>System Flow (FT11)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-ft11_flow"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.ft11_flow"
|
||||
data-units="GPM"
|
||||
data-min="0"
|
||||
data-max="1000"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.ft11_flow'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="ft11_flow">
|
||||
<%= channels["transferstation.ft11_flow"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
||||
|
||||
|
||||
<% if (channels["transferstation.system2_enabled"].value == 1) { %>
|
||||
<div class="row row-flex box-me" id="system2">
|
||||
<div class="col-xs-12 text-center">
|
||||
<h1>System 2</h1>
|
||||
</div>
|
||||
<% if (channels['transferstation.lt21_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Pond Level (LT21)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-lt21_level"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.lt21_level"
|
||||
data-units="ft."
|
||||
data-min="0"
|
||||
data-max="25"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.lt21_level'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="lt21_level">
|
||||
<%= channels["transferstation.lt21_level"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Booster Pump Intake Pressure (PT21)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-pt21_pressure"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.pt21_pressure"
|
||||
data-units="PSI"
|
||||
data-min="0"
|
||||
data-max="100"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.pt21_pressure'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="pt21_pressure">
|
||||
<%= channels["transferstation.pt21_pressure"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% if (channels['transferstation.pt22_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Booster Pump Discharge Pressure (PT22)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-pt22_pressure"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.pt22_pressure"
|
||||
data-units="PSI"
|
||||
data-min="0"
|
||||
data-max="100"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.pt22_pressure'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="pt22_pressure">
|
||||
<%= channels["transferstation.pt22_pressure"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (channels['transferstation.ft21_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>System Flow (FT21)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-ft21_flow"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.ft21_flow"
|
||||
data-units="GPM"
|
||||
data-min="0"
|
||||
data-max="1000"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.ft21_flow'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="ft21_flow">
|
||||
<%= channels["transferstation.ft21_flow"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (channels["transferstation.system3_enabled"].value == 1) { %>
|
||||
<div class="row row-flex box-me" id="system3">
|
||||
<div class="col-xs-12 text-center">
|
||||
<h1>System 3</h1>
|
||||
</div>
|
||||
<% if (channels['transferstation.lt31_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Pond Level (LT31)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-lt31_level"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.lt31_level"
|
||||
data-units="ft."
|
||||
data-min="0"
|
||||
data-max="25"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.lt31_level'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="lt31_level">
|
||||
<%= channels["transferstation.lt31_level"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Booster Pump Intake Pressure (PT31)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-pt31_pressure"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.pt31_pressure"
|
||||
data-units="PSI"
|
||||
data-min="0"
|
||||
data-max="100"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.pt31_pressure'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="pt31_pressure">
|
||||
<%= channels["transferstation.pt31_pressure"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% if (channels['transferstation.pt32_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>Booster Pump Discharge Pressure (PT32)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-pt32_pressure"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.pt32_pressure"
|
||||
data-units="PSI"
|
||||
data-min="0"
|
||||
data-max="100"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.pt32_pressure'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="pt32_pressure">
|
||||
<%= channels["transferstation.pt32_pressure"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
<% if (channels['transferstation.ft31_enabled'].value == 1) { %>
|
||||
<div class="col-xs-4 text-center">
|
||||
<h2>System Flow (FT31)</h2>
|
||||
<div class="gauge-box">
|
||||
<div data-labelheight="10"
|
||||
style="height: 170px; background: transparent; margin: 0 auto;"
|
||||
id="gauge-ft31_flow"
|
||||
data-chart="solidgauge"
|
||||
data-nodename="transferstation.ft31_flow"
|
||||
data-units="GPM"
|
||||
data-min="0"
|
||||
data-max="1000"
|
||||
data-decimalplaces="2"
|
||||
data-colors="0.1:#DF5353,0.5:#DDDF0D,0.9:#55BF3B"
|
||||
data-valuefontsize="18px">
|
||||
</div>
|
||||
<div class- "timestamp-box">
|
||||
<a href="#" data-channelId="<%= channels['transferstation.ft31_flow'].channelId %>" class="data-table" title="Download Channel History">
|
||||
<i class="fa fa-download"></i>
|
||||
</a>
|
||||
</div>
|
||||
<span data-timeupdate="ft31_flow">
|
||||
<%= channels["transferstation.ft31_flow"].timestamp %>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
<% } %>
|
||||
|
||||
|
||||
|
||||
|
||||
<style>
|
||||
|
||||
.box-me {
|
||||
position: relative;
|
||||
padding: 0.5em;
|
||||
padding-bottom: 1.5em;
|
||||
border: 1px solid #eee;
|
||||
/*margin: 1em 0;*/
|
||||
}
|
||||
|
||||
.box-me .gauge-box {
|
||||
margin-top: -0.25em;
|
||||
}
|
||||
|
||||
.pad15 {
|
||||
margin: 15px 15px;
|
||||
}
|
||||
|
||||
.box-me h2 {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
font-weight: 400;
|
||||
letter-spacing: 1px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.dynamic-chart-form {
|
||||
background-color: whiteSmoke;
|
||||
padding: 1em 0.5em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
.row-flex {
|
||||
display: -webkit-box;
|
||||
display: -webkit-flex;
|
||||
display: -ms-flexbox;
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.row-flex > [class*='col-'] {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#systemStatusTimelineContainer h2 {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
font-weight: 400;
|
||||
letter-spacing: 1px;
|
||||
z-index: 100;
|
||||
}
|
||||
|
||||
.slice.node-detail hr {
|
||||
border-color: #ccc;
|
||||
}
|
||||
.slice.node-detail #alarms li {
|
||||
margin-bottom: 1em;
|
||||
padding: 0.5em;
|
||||
}
|
||||
.slice.node-detail #alarms li:nth-child(even){
|
||||
background-color: whiteSmoke;
|
||||
}
|
||||
.slice.node-detail #alarms li span {
|
||||
margin-left: 1em;
|
||||
color: #aaa;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
|
||||
$('.val_box').each(function(topLevel){
|
||||
$(this).change(function(){
|
||||
var id = "#" + $(this).closest(".entry-top-level").attr('id');
|
||||
if (id !== "#undefined"){
|
||||
var val = $(id).find('.val_box').val();
|
||||
var tag = $(id).find('.setstatic').attr('data-staticsend', val);
|
||||
console.log($(id).find('.setstatic').attr('data-staticsend'));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
</script>
|
||||
2
POCloud/README.md
Normal file
2
POCloud/README.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# Pond-Level-Sensor
|
||||
Program to determine pond level and transmit the data to Meshify
|
||||
61
POCloud/Scheduler.py
Normal file
61
POCloud/Scheduler.py
Normal file
@@ -0,0 +1,61 @@
|
||||
"""Hold scheduler classes and functions."""
|
||||
import time
|
||||
from Channel import Channel
|
||||
from Maps import transferstation_map as maps
|
||||
_ = None
|
||||
|
||||
plc_ip_address = "192.168.1.10"
|
||||
|
||||
|
||||
class ScheduleRun:
|
||||
"""Hold config for a schedule history run."""
|
||||
|
||||
def __init__(self, index_, type_="Schedule"):
|
||||
"""Initialize the class."""
|
||||
self.index_ = index_
|
||||
self.json = False
|
||||
if type_ in ["Schedule", "History"]:
|
||||
self.type_ = type_
|
||||
else:
|
||||
self.type_ = "Schedule"
|
||||
print("SERIOUS ERROR! {} IS NOT A VALID TYPE FOR ScheduleRun with Index = {}".format(type_, index_))
|
||||
self.channels = [
|
||||
Channel(plc_ip_address, "sch_{}_id{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].id".format(self.type_, self.index_), "DINT", 0.5, 3600),
|
||||
Channel(plc_ip_address, "sch_{}_controlmode{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].controlmode".format(self.type_, self.index_), "STRING", _, 3600, map_=maps['pid_controlmode']),
|
||||
Channel(plc_ip_address, "sch_{}_controlsp{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].controlSetpoint".format(self.type_, self.index_), "REAL", 0.5, 3600),
|
||||
Channel(plc_ip_address, "sch_{}_complparam{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].completionParameter".format(self.type_, self.index_), "STRING", _, 3600, map_=maps['completion_parameter']),
|
||||
Channel(plc_ip_address, "sch_{}_complcomp{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].completionComparison".format(self.type_, self.index_), "STRING", _, 3600, map_=maps['completion_comparison']),
|
||||
Channel(plc_ip_address, "sch_{}_compltarget{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].completionValueTarget".format(self.type_, self.index_), "REAL", 0.5, 3600),
|
||||
Channel(plc_ip_address, "sch_{}_complactual{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].completionValueCurrent".format(self.type_, self.index_), "REAL", 10.0, 3600),
|
||||
Channel(plc_ip_address, "sch_{}_bbltotal{}".format(self.type_, self.index_),
|
||||
"sch_Run{}[{}].BBLTotal".format(self.type_, self.index_), "REAL", 10.0, 3600)
|
||||
]
|
||||
|
||||
def read(self, force_send=False):
|
||||
"""Read values of the schedule history from the PLC."""
|
||||
new_value = False
|
||||
for c in self.channels:
|
||||
if c.read(force_send):
|
||||
new_value = True
|
||||
return new_value
|
||||
|
||||
def jsonify(self):
|
||||
"""Give a JSON-ready object."""
|
||||
return {
|
||||
"id": self.channels[0].value,
|
||||
"control_mode": self.channels[1].value,
|
||||
"control_setpoint": self.channels[2].value,
|
||||
"completion_parameter": self.channels[3].value,
|
||||
"completion_comparison": self.channels[4].value,
|
||||
"completion_value_target": self.channels[5].value,
|
||||
"completion_value_actual": self.channels[6].value,
|
||||
"completion_bbl_total": self.channels[7].value,
|
||||
"timestamp": time.time()
|
||||
}
|
||||
15
POCloud/Sidebar.html
Normal file
15
POCloud/Sidebar.html
Normal file
@@ -0,0 +1,15 @@
|
||||
<a href="#"
|
||||
data-channelId="<%= channels["transferstation.log"].channelId %>"
|
||||
class="data-table btn-block btn btn-theme animated"
|
||||
title="Device Log"><i style='margin-left: 0.5em; cursor: pointer' class="fa fa-th-list icon-theme"></i> Device Log</a>
|
||||
|
||||
<a href="#"
|
||||
data-refreshpause="1"
|
||||
data-staticsend="1"
|
||||
data-channelId="<%= channels["transferstation.sync"].channelId %>"
|
||||
data-techname="<%=channels["transferstation.sync"].techName %>"
|
||||
data-name="<%= channels["transferstation.sync"].name%>"
|
||||
data-nodechannelcurrentId="<%= channels["transferstation.sync"].nodechannelcurrentId %>"
|
||||
id="<%= channels["transferstation.sync"].channelId %>"
|
||||
class="btn btn-large btn-block btn-theme animated setstatic mqtt">
|
||||
<i class="icon-repeat icon-white mqtt" ></i>Sync All Data</a>
|
||||
37
POCloud/Trends.html
Normal file
37
POCloud/Trends.html
Normal file
@@ -0,0 +1,37 @@
|
||||
<div class='col-xs-12' style="padding-top: 1em; margin-bottom: 1em;">
|
||||
<div class="input-daterange input-group" id="datepicker">
|
||||
<input data-chartid="dynamicChart" id="fromDate" data-daysofhistory="7" type="text" class="form-control" name="start">
|
||||
<span class="input-group-addon">to</span>
|
||||
<input class="form-control" data-chartid="dynamicChart" id="toDate" type="text" name="end">
|
||||
<span class='input-group-btn'>
|
||||
<a href="#!" data-chartid="dynamicChart" data-otherchartids="statusTimeline" class="btn chart-update btn-theme">Run</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<hr>
|
||||
<div class='clearfix col-xs-12'
|
||||
style='height: 450px'
|
||||
id="dynamicChart"
|
||||
data-chart="dynamicchart"
|
||||
data-daysofhistory="7"
|
||||
data-chartlabel="Data"
|
||||
data-ylabel=""
|
||||
data-xlabel="Date"
|
||||
data-units=""
|
||||
data-channelnames="transferstation.ft01_flow,transferstation.ft11_flow,transferstation.ft21_flow,transferstation.ft31_flow,transferstation.pt11_pressure,transferstation.pt21_pressure,transferstation.pt31_pressure,transferstation.pt12_pressure,transferstation.pt22_pressure,transferstation.pt32_pressure">
|
||||
</div>
|
||||
<style>
|
||||
.dynamic-chart-form {
|
||||
background-color: whiteSmoke;
|
||||
padding: 1em 0.5em;
|
||||
margin-top: 1em;
|
||||
}
|
||||
#systemStatusTimelineContainer h2 {
|
||||
text-transform: uppercase;
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
font-weight: 400;
|
||||
letter-spacing: 1px;
|
||||
z-index: 100;
|
||||
}
|
||||
</style>
|
||||
14
POCloud/config.txt
Normal file
14
POCloud/config.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
|
||||
"driverFileName":"transferstation.py",
|
||||
"deviceName":"transferstation",
|
||||
"driverId":"0140",
|
||||
"releaseVersion":"1",
|
||||
"files": {
|
||||
"file1":"transferstation.py",
|
||||
"file2":"Channel.py",
|
||||
"file3":"Maps.py",
|
||||
"file4":"Scheduler.py"
|
||||
}
|
||||
|
||||
}
|
||||
32
POCloud/test.html
Normal file
32
POCloud/test.html
Normal file
@@ -0,0 +1,32 @@
|
||||
<div id="pit"></div>
|
||||
<style>
|
||||
#pit {
|
||||
width:25%;
|
||||
height: 400px;
|
||||
border-left: 2px solid #000000;
|
||||
border-right: 2px solid #000000;
|
||||
border-bottom: 2px solid #000000;
|
||||
border-bottom-left-radius: 5px;
|
||||
border-bottom-right-radius: 5px;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
}
|
||||
#pit::before {
|
||||
content: '';
|
||||
position: absolute;
|
||||
background: #04ACFF;
|
||||
width: 100%;
|
||||
bottom: 0;
|
||||
animation: wipe 1s cubic-bezier(.2,.6,.8,.4) forwards;
|
||||
}
|
||||
@keyframes wipe {
|
||||
0% {
|
||||
height: 0;
|
||||
}
|
||||
100% {
|
||||
height: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
</style>
|
||||
134
POCloud/transferstation.py
Normal file
134
POCloud/transferstation.py
Normal file
@@ -0,0 +1,134 @@
|
||||
"""Driver for connecting Pond Level to Meshify."""
|
||||
|
||||
import threading
|
||||
from device_base import deviceBase
|
||||
from Channel import Channel, write_tag, BoolArrayChannels
|
||||
from Maps import transferstation_map as maps
|
||||
from Scheduler import ScheduleRun
|
||||
import json
|
||||
import time
|
||||
|
||||
_ = None
|
||||
|
||||
try:
|
||||
with open("persist.json", 'r') as persist_file:
|
||||
persist = json.load(persist_file)
|
||||
except Exception:
|
||||
persist = {}
|
||||
|
||||
try:
|
||||
persist['last_schedule_history']
|
||||
except KeyError:
|
||||
persist['last_schedule_history'] = {"id": -1}
|
||||
|
||||
_ = None
|
||||
|
||||
plc_ip_address = "192.168.1.10"
|
||||
|
||||
|
||||
def reverse_map(value, map_):
|
||||
"""Perform the opposite of mapping to an object."""
|
||||
for x in map_:
|
||||
if map_[x] == value:
|
||||
return x
|
||||
return None
|
||||
|
||||
|
||||
bit_channels = [
|
||||
BoolArrayChannels(plc_ip_address, 'systemx_enabled', "cfg_SystemEnabled", "BOOL", _, 60*60*60, map_=maps['bit_channels']['system_enabled']),
|
||||
BoolArrayChannels(plc_ip_address, 'ltx1_enabled', "cfg_SystemLTEnabled", "BOOL", _, 60*60*60, map_=maps['bit_channels']['lt_enabled']),
|
||||
BoolArrayChannels(plc_ip_address, 'ftx1_enabled', "cfg_SystemFTEnabled", "BOOL", _, 60*60*60, map_=maps['bit_channels']['ft_enabled']),
|
||||
BoolArrayChannels(plc_ip_address, 'ptx2_enabled', "cfg_SystemBPDischargePTEnabled", "BOOL", _, 60*60*60, map_=maps['bit_channels']['ptx2_enabled']),
|
||||
]
|
||||
|
||||
channels = [
|
||||
Channel(plc_ip_address, "lt01_level", "LTX1_PondLevel[0].Val", "REAL", 0.25, 3600),
|
||||
Channel(plc_ip_address, "lt11_level", "LTX1_PondLevel[1].Val", "REAL", 0.25, 3600),
|
||||
Channel(plc_ip_address, "lt21_level", "LTX1_PondLevel[2].Val", "REAL", 0.25, 3600),
|
||||
Channel(plc_ip_address, "lt31_level", "LTX1_PondLevel[3].Val", "REAL", 0.25, 3600),
|
||||
|
||||
Channel(plc_ip_address, "pt11_pressure", "PTX1_BoosterPumpInlet[1].Val", "REAL", 3.0, 3600),
|
||||
Channel(plc_ip_address, "pt21_pressure", "PTX1_BoosterPumpInlet[2].Val", "REAL", 3.0, 3600),
|
||||
Channel(plc_ip_address, "pt31_pressure", "PTX1_BoosterPumpInlet[3].Val", "REAL", 3.0, 3600),
|
||||
|
||||
Channel(plc_ip_address, "pt12_pressure", "PTX2_BoosterPumpDischarge[1].Val", "REAL", 3.0, 3600),
|
||||
Channel(plc_ip_address, "pt22_pressure", "PTX2_BoosterPumpDischarge[2].Val", "REAL", 3.0, 3600),
|
||||
Channel(plc_ip_address, "pt32_pressure", "PTX2_BoosterPumpDischarge[3].Val", "REAL", 3.0, 3600),
|
||||
|
||||
Channel(plc_ip_address, "ft01_flow", "FTX1_SystemOutput[0].Val", "REAL", 5.0, 3600),
|
||||
Channel(plc_ip_address, "ft11_flow", "FTX1_SystemOutput[1].Val", "REAL", 5.0, 3600),
|
||||
Channel(plc_ip_address, "ft21_flow", "FTX1_SystemOutput[2].Val", "REAL", 5.0, 3600),
|
||||
Channel(plc_ip_address, "ft31_flow", "FTX1_SystemOutput[3].Val", "REAL", 5.0, 3600),
|
||||
|
||||
Channel(plc_ip_address, "cmd_run", "cmd_run", "BOOL", _, 3600, map_=maps['run']),
|
||||
# Channel(plc_ip_address, "ft21_enabled", "cfg_SystemFTEnabled[2]", "BOOL", _, 3600),
|
||||
# Channel(plc_ip_address, "ft31_enabled", "cfg_SystemFTEnabled[3]", "BOOL", _, 3600),
|
||||
]
|
||||
|
||||
|
||||
class start(threading.Thread, deviceBase):
|
||||
"""Start class required by Meshify."""
|
||||
|
||||
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
|
||||
"""Initialize the driver."""
|
||||
threading.Thread.__init__(self)
|
||||
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.finished = threading.Event()
|
||||
self.forceSend = False
|
||||
threading.Thread.start(self)
|
||||
|
||||
# this is a required function for all drivers, its goal is to upload some piece of data
|
||||
# about your device so it can be seen on the web
|
||||
def register(self):
|
||||
"""Register the driver."""
|
||||
self.sendtodb("log", "BOOM! Booted.", 0)
|
||||
|
||||
def run(self):
|
||||
"""Actually run the driver."""
|
||||
global persist
|
||||
wait_sec = 10
|
||||
for i in range(0, wait_sec):
|
||||
print("transferstation driver will start in {} seconds".format(wait_sec - i))
|
||||
time.sleep(1)
|
||||
print("BOOM! Starting transferstation driver...")
|
||||
send_loops = 0
|
||||
while True:
|
||||
if self.forceSend:
|
||||
print "FORCE SEND: TRUE"
|
||||
for c in channels:
|
||||
if c.read(self.forceSend):
|
||||
self.sendtodb(c.mesh_name, c.value, 0)
|
||||
|
||||
for b in bit_channels:
|
||||
if b.read(self.forceSend):
|
||||
for v in b.last_value:
|
||||
self.sendtodb(v, b.last_value[v], 0)
|
||||
|
||||
print("transferstation driver still alive...")
|
||||
if self.forceSend:
|
||||
if send_loops > 2:
|
||||
print("Turning off forceSend")
|
||||
self.forceSend = False
|
||||
send_loops = 0
|
||||
else:
|
||||
send_loops += 1
|
||||
|
||||
def transferstation_sync(self, name, value):
|
||||
"""Sync all data from the driver."""
|
||||
self.forceSend = True
|
||||
self.sendtodb("log", "synced", 0)
|
||||
return True
|
||||
|
||||
def transferstation_writeplctag(self, name, value):
|
||||
"""Write a value to the PLC."""
|
||||
new_val = json.loads(str(value).replace("'", '"'))
|
||||
tag_n = str(new_val['tag']) # "cmd_Start"
|
||||
val_n = new_val['val']
|
||||
w = write_tag(str(plc_ip_address), tag_n, val_n)
|
||||
print("Result of transferstation_writeplctag(self, {}, {}) = {}".format(name, value, w))
|
||||
if w is None:
|
||||
w = "Error writing to PLC..."
|
||||
return w
|
||||
11969
TransferStation.ACD
11969
TransferStation.ACD
File diff suppressed because one or more lines are too long
15
channels.csv
Normal file
15
channels.csv
Normal file
@@ -0,0 +1,15 @@
|
||||
deviceTypeId,name,channelType,subTitle,helpExplanation,io,dataType,defaultValue
|
||||
418,system1_enabled,1,System 1 Enabled,System is configured to run,true,1,0
|
||||
418,system2_enabled,1,System 2 Enabled,System is configured to run,true,1,0
|
||||
418,system3_enabled,1,System 3 Enabled,System is configured to run,true,1,0
|
||||
418,ft01_enabled,1,Shared FT Enabled,Flow Transmitter exists and is wired,true,1,0
|
||||
418,ft11_enabled,1,FT11 Enabled,Flow Transmitter exists and is wired,true,1,0
|
||||
418,ft21_enabled,1,FT21 Enabled,Flow Transmitter exists and is wired,true,1,0
|
||||
418,ft31_enabled,1,FT31 Enabled,Flow Transmitter exists and is wired,true,1,0
|
||||
418,lt01_enabled,1,LT01 Enabled,Level Transmitter exists and is wired,true,1,0
|
||||
418,lt11_enabled,1,LT11 Enabled,Level Transmitter exists and is wired,true,1,0
|
||||
418,lt21_enabled,1,LT21 Enabled,Level Transmitter exists and is wired,true,1,0
|
||||
418,lt31_enabled,1,LT31 Enabled,Level Transmitter exists and is wired,true,1,0
|
||||
418,pt12_enabled,1,PT12 Enabled,Pressure Transmitter exists and is wired,true,1,0
|
||||
418,pt22_enabled,1,PT22 Enabled,Pressure Transmitter exists and is wired,true,1,0
|
||||
418,pt32_enabled,1,PT32 Enabled,Pressure Transmitter exists and is wired,true,1,0
|
||||
|
38
meshify.py
Normal file
38
meshify.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Query Meshify for data."""
|
||||
import requests
|
||||
import json
|
||||
from os import getenv
|
||||
from sys import exit
|
||||
|
||||
MESHIFY_BASE_URL = "https://henrypump.meshify.com/api/v3/"
|
||||
MESHIFY_USERNAME = getenv("MESHIFY_USERNAME")
|
||||
MESHIFY_PASSWORD = getenv("MESHIFY_PASSWORD")
|
||||
MESHIFY_AUTH = requests.auth.HTTPBasicAuth(MESHIFY_USERNAME, MESHIFY_PASSWORD)
|
||||
|
||||
if not MESHIFY_USERNAME or not MESHIFY_PASSWORD:
|
||||
print("Be sure to set the meshify username and password as environment variables MESHIFY_USERNAME and MESHIFY_PASSWORD")
|
||||
exit()
|
||||
|
||||
|
||||
def find_by_name(name, list_of_stuff):
|
||||
"""Find an object in a list of stuff by its name parameter."""
|
||||
for x in list_of_stuff:
|
||||
if x['name'] == name:
|
||||
return x
|
||||
return False
|
||||
|
||||
|
||||
def query_meshify_api(endpoint):
|
||||
"""Make a query to the meshify API."""
|
||||
q_url = MESHIFY_BASE_URL + endpoint
|
||||
q_req = requests.get(q_url, auth=MESHIFY_AUTH)
|
||||
return json.loads(q_req.text) if q_req.status_code == 200 else []
|
||||
|
||||
|
||||
def post_meshify_api(endpoint, data):
|
||||
"""Post data to the meshify API."""
|
||||
q_url = MESHIFY_BASE_URL + endpoint
|
||||
q_req = requests.post(q_url, data=json.dumps(data), auth=MESHIFY_AUTH)
|
||||
if q_req.status_code != 200:
|
||||
print(q_req.status_code)
|
||||
return json.loads(q_req.text) if q_req.status_code == 200 else []
|
||||
BIN
meshify.pyc
Normal file
BIN
meshify.pyc
Normal file
Binary file not shown.
38
postChannels.py
Normal file
38
postChannels.py
Normal file
@@ -0,0 +1,38 @@
|
||||
"""Read a CSV file of channels and post them to Meshify via the API."""
|
||||
|
||||
import csv
|
||||
import meshify
|
||||
import sys
|
||||
|
||||
|
||||
def main(csv_file, devicetype):
|
||||
"""Main function."""
|
||||
csvfile = open(csv_file, 'rU')
|
||||
reader = csv.DictReader(csvfile, dialect=csv.excel)
|
||||
|
||||
channels = []
|
||||
idx = 0
|
||||
for x in reader:
|
||||
channels.append(x)
|
||||
channels[idx]["fromMe"] = False
|
||||
channels[idx]["regex"] = ""
|
||||
channels[idx]["regexErrMsg"] = ""
|
||||
channels[idx]["dataType"] = int(channels[idx]["dataType"])
|
||||
channels[idx]["deviceTypeId"] = int(channels[idx]["deviceTypeId"])
|
||||
channels[idx]["channelType"] = int(channels[idx]["channelType"])
|
||||
channels[idx]["io"] = bool(channels[idx]["io"])
|
||||
idx += 1
|
||||
|
||||
try:
|
||||
this_devicetype = meshify.find_by_name(devicetype, meshify.query_meshify_api("devicetypes"))
|
||||
for c in channels:
|
||||
print(meshify.post_meshify_api("devicetypes/{}/channels".format(this_devicetype['id']), c))
|
||||
except KeyError:
|
||||
print("Could not find key {}".format(devicetype))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) == 3:
|
||||
main(sys.argv[1], sys.argv[2])
|
||||
else:
|
||||
print("Syntax is python postChannels.py <filepath.csv> <devicetype name>")
|
||||
Reference in New Issue
Block a user