updates
This commit is contained in:
@@ -2,15 +2,29 @@
|
||||
import socket
|
||||
import struct
|
||||
from Channel import PLCChannel
|
||||
import urllib
|
||||
import contextlib
|
||||
|
||||
def get_public_ip_address():
|
||||
"""Find the public IP Address of the host device."""
|
||||
def get_private_ip_address():
|
||||
"""Find the private IP Address of the host device."""
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.connect(("8.8.8.8", 80))
|
||||
try:
|
||||
sock.connect(("8.8.8.8", 80))
|
||||
except Exception as e:
|
||||
return e
|
||||
ip_address = sock.getsockname()[0]
|
||||
sock.close()
|
||||
return ip_address
|
||||
|
||||
def get_public_ip_address():
|
||||
ip_address = "0.0.0.0"
|
||||
try:
|
||||
with contextlib.closing(urllib.urlopen("http://checkip.amazonaws.com")) as url:
|
||||
ip_address = url.read()
|
||||
except Exception as e:
|
||||
print("could not resolve check IP: {}".format(e))
|
||||
return ip_address
|
||||
return ip_address[:-1]
|
||||
|
||||
def int_to_float16(int_to_convert):
|
||||
"""Convert integer into float16 representation."""
|
||||
|
||||
298
advvfdipppond/Channel.py
Normal file
298
advvfdipppond/Channel.py
Normal file
@@ -0,0 +1,298 @@
|
||||
"""Define Meshify channel class."""
|
||||
import time
|
||||
import urllib
|
||||
from pycomm.ab_comm.clx import Driver as ClxDriver
|
||||
from pycomm.cip.cip_base import CommError, DataError
|
||||
from file_logger import filelogger as log
|
||||
|
||||
|
||||
|
||||
TAG_DATAERROR_SLEEPTIME = 5
|
||||
|
||||
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, plc_type="CLX"):
|
||||
"""Read a tag from the PLC."""
|
||||
direct = plc_type == "Micro800"
|
||||
clx = ClxDriver()
|
||||
try:
|
||||
if clx.open(addr, direct_connection=direct):
|
||||
try:
|
||||
val = clx.read_tag(tag)
|
||||
clx.close()
|
||||
return val
|
||||
except DataError as err:
|
||||
clx.close()
|
||||
time.sleep(TAG_DATAERROR_SLEEPTIME)
|
||||
log.error("Data Error during readTag({}, {}): {}".format(addr, tag, err))
|
||||
except CommError:
|
||||
# err = c.get_status()
|
||||
clx.close()
|
||||
log.error("Could not connect during readTag({}, {})".format(addr, tag))
|
||||
except AttributeError as err:
|
||||
clx.close()
|
||||
log.error("AttributeError during readTag({}, {}): \n{}".format(addr, tag, err))
|
||||
clx.close()
|
||||
return False
|
||||
|
||||
|
||||
def read_array(addr, tag, start, end, plc_type="CLX"):
|
||||
"""Read an array from the PLC."""
|
||||
direct = plc_type == "Micro800"
|
||||
clx = ClxDriver()
|
||||
if clx.open(addr, direct_connection=direct):
|
||||
arr_vals = []
|
||||
try:
|
||||
for i in range(start, end):
|
||||
tag_w_index = tag + "[{}]".format(i)
|
||||
val = clx.read_tag(tag_w_index)
|
||||
arr_vals.append(round(val[0], 4))
|
||||
if arr_vals:
|
||||
clx.close()
|
||||
return arr_vals
|
||||
else:
|
||||
log.error("No length for {}".format(addr))
|
||||
clx.close()
|
||||
return False
|
||||
except Exception:
|
||||
log.error("Error during readArray({}, {}, {}, {})".format(addr, tag, start, end))
|
||||
err = clx.get_status()
|
||||
clx.close()
|
||||
log.error(err)
|
||||
clx.close()
|
||||
|
||||
|
||||
def write_tag(addr, tag, val, plc_type="CLX"):
|
||||
"""Write a tag value to the PLC."""
|
||||
direct = plc_type == "Micro800"
|
||||
clx = ClxDriver()
|
||||
try:
|
||||
if clx.open(addr, direct_connection=direct):
|
||||
try:
|
||||
initial_val = clx.read_tag(tag)
|
||||
write_status = clx.write_tag(tag, val, initial_val[1])
|
||||
clx.close()
|
||||
return write_status
|
||||
except DataError as err:
|
||||
clx_err = clx.get_status()
|
||||
clx.close()
|
||||
log.error("--\nDataError during writeTag({}, {}, {}, plc_type={}) -- {}\n{}\n".format(addr, tag, val, plc_type, err, clx_err))
|
||||
|
||||
except CommError as err:
|
||||
clx_err = clx.get_status()
|
||||
log.error("--\nCommError during write_tag({}, {}, {}, plc_type={})\n{}\n--".format(addr, tag, val, plc_type, err))
|
||||
clx.close()
|
||||
return False
|
||||
|
||||
|
||||
class Channel(object):
|
||||
"""Holds the configuration for a Meshify channel."""
|
||||
|
||||
def __init__(self, mesh_name, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False):
|
||||
"""Initialize the channel."""
|
||||
self.mesh_name = mesh_name
|
||||
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.value, self.last_send_time)
|
||||
|
||||
def check(self, new_value, force_send=False):
|
||||
"""Check to see if the new_value needs to be stored."""
|
||||
send_needed = False
|
||||
send_reason = ""
|
||||
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 self.value != new_value:
|
||||
if self.map_:
|
||||
if not self.value == self.map_[new_value]:
|
||||
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 - new_value) > 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_[new_value]
|
||||
except KeyError:
|
||||
log.error("Cannot find a map value for {} in {} for {}".format(new_value, self.map_, self.mesh_name))
|
||||
self.value = new_value
|
||||
else:
|
||||
self.value = new_value
|
||||
self.last_send_time = time.time()
|
||||
log.info("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||
return send_needed
|
||||
|
||||
def read(self):
|
||||
"""Read the value."""
|
||||
pass
|
||||
|
||||
|
||||
def identity(sent):
|
||||
"""Return exactly what was sent to it."""
|
||||
return sent
|
||||
|
||||
|
||||
class ModbusChannel(Channel):
|
||||
"""Modbus channel object."""
|
||||
|
||||
def __init__(self, mesh_name, register_number, data_type, chg_threshold, guarantee_sec, channel_size=1, map_=False, write_enabled=False, transform_fn=identity):
|
||||
"""Initialize the channel."""
|
||||
super(ModbusChannel, self).__init__(mesh_name, data_type, chg_threshold, guarantee_sec, map_, write_enabled)
|
||||
self.mesh_name = mesh_name
|
||||
self.register_number = register_number
|
||||
self.channel_size = channel_size
|
||||
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
|
||||
self.transform_fn = transform_fn
|
||||
|
||||
def read(self, mbsvalue):
|
||||
"""Return the transformed read value."""
|
||||
return self.transform_fn(mbsvalue)
|
||||
|
||||
|
||||
class PLCChannel(Channel):
|
||||
"""PLC Channel Object."""
|
||||
|
||||
def __init__(self, ip, mesh_name, plc_tag, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False, plc_type='CLX'):
|
||||
"""Initialize the channel."""
|
||||
super(PLCChannel, self).__init__(mesh_name, data_type, chg_threshold, guarantee_sec, map_, write_enabled)
|
||||
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
|
||||
self.plc_type = plc_type
|
||||
|
||||
def read(self):
|
||||
"""Read the value."""
|
||||
plc_value = None
|
||||
if self.plc_tag and self.plc_ip:
|
||||
read_value = read_tag(self.plc_ip, self.plc_tag, plc_type=self.plc_type)
|
||||
if read_value:
|
||||
plc_value = read_value[0]
|
||||
|
||||
return plc_value
|
||||
|
||||
|
||||
class BoolArrayChannels(Channel):
|
||||
"""Hold the configuration for a set of boolean array channels."""
|
||||
|
||||
def __init__(self, ip, mesh_name, plc_tag, data_type, chg_threshold, guarantee_sec, map_=False, write_enabled=False):
|
||||
"""Initialize the channel."""
|
||||
super(BoolArrayChannels, self).__init__(mesh_name, data_type, chg_threshold, guarantee_sec, map_, write_enabled)
|
||||
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 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:
|
||||
log.error("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:
|
||||
val = read_tag(self.plc_ip, self.plc_tag)
|
||||
if val:
|
||||
bool_arr = binarray(val[0])
|
||||
new_val = {}
|
||||
for idx in self.map_:
|
||||
try:
|
||||
new_val[self.map_[idx]] = bool_arr[idx]
|
||||
except KeyError:
|
||||
log.error("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()
|
||||
log.info("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||
return send_needed
|
||||
89
advvfdipppond/Tags.py
Normal file
89
advvfdipppond/Tags.py
Normal file
@@ -0,0 +1,89 @@
|
||||
from Channel import PLCChannel, ModbusChannel
|
||||
from advvfdipppond import PLC_IP_ADDRESS
|
||||
|
||||
tags = [
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_flowrate","val_Flowmeter","REAL", 10000, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_flowrate", "Val_FM2_FR", "REAL", 1000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_flowrate", "Val_FM3_FR", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_flowrate", "Val_FM4_FR", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_flowrate", "Val_FM5_FR", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_flowrate", "Val_FM6_FR", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_flowrate", "Val_FRTotalOut", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_flowrate", "Val_FRTotalIn", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_todays", "Flowmeter_Totals.Todays_Totalflow", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_todays", "Val_FM2_Todays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_todays", "Val_FM3_Todays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_todays", "Val_FM4_Todays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_todays", "Val_FM5_Todays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_todays", "Val_FM6_Todays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_todays", "Val_TodaysTotalOut", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_todays", "Val_TodaysTotalIn", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_yesterdays", "Flowmeter_Totals.Yesterdays_Totalflow", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_yesterdays", "Val_FM2_Yesterdays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_yesterdays", "Val_FM3_Yesterdays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_yesterdays", "Val_FM4_Yesterdays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_yesterdays", "Val_FM5_Yesterdays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_yesterdays", "Val_FM6_Yesterdays", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_yesterdays", "Val_YesterdaysTotalOut", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_yesterdays", "Val_YesterdaysTotalIn", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_month", "Flowmeter_Totals.CurrentMonth_Totalflow", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_month", "Val_FM2_Months", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_month", "Val_FM3_Months", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_month", "Val_FM4_Months", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_month", "Val_FM5_Months", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_month", "Val_FM6_Months", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_months", "Val_MonthsTotalOut", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_months", "Val_MonthsTotalIn", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_lastmonths", "Flowmeter_Totals.LastMonth_Totalflow", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_lastmonths", "Val_FM2_LastMonths", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_lastmonths", "Val_FM3_LastMonths", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_lastmonths", "Val_FM4_LastMonths", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_lastmonths", "Val_FM5_LastMonths", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_lastmonths", "Val_FM6_LastMonths", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_lastmonths", "Val_LastMonthsTotalOut", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_lastmonths", "Val_LastMonthsTotalIn", "REAL", 10000, 3600, plc_type='CLX'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_level","val_FluidLevel","REAL", 2, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_volume","val_PondVolume","REAL", 2, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "intake_pressure","val_IntakePressure","REAL", 10, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "intake_temperature","val_IntakeTemperature","REAL", 5, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "discharge_pressure","val_TubingPressure","REAL", 10, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "pidcontrolmode","sts_PID_Control","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "well_status","Device_Status_INT","INT", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "vfd_frequency","VFD_SpeedFdbk","REAL", 5, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "flowtotal","Flow_Total[0]","REAL", 100, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "energytotal","Energy_Total[0]","REAL", 10, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "vfd_current","VFD_OutCurrent","REAL", 5, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pump_sensor_status","Downhole_Sensor_Status_INT","INT", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "fluidspecificgravity","cfg_FluidSpecificGravity","REAL", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "flowtotalyesterday","Flow_Total[1]","REAL", 100, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "energytotalyesterday","Energy_Total[1]","REAL", 10, 86400, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_flowrate","alarm_Flowmeter","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_intake_pressure","alarm_IntakePressure","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_intake_temperature","alarm_IntakeTemperature","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_discharge_pressure","alarm_TubingPressure","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_vfd","alarm_VFD","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_lockout","alarm_Lockout","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "run_permissive","Run_Permissive_INT","INT", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "start_permissive","Start_Permissive_INT","INT", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "startcommand","cmd_Start","BOOL", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "stopcommand","cmd_Stop","BOOL", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "flowsetpoint","cfg_PID_FlowSP","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "fluidlevelsetpoint","cfg_PID_FluidLevelSP","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "manualfrequencysetpoint","cfg_PID_ManualSP","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "tubingpressuresetpoint","cfg_PID_TubingPressureSP","REAL", 1, 86400, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_pond_height","alarm_FluidLevel","BOOL", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "pressure_shutdown_limit","AIn_IntakePressure.Val_LoLim","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "pressure_startup_limit","AIn_IntakePressure.Val_HiLim","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "temperature_shutdown_limit","AIn_IntakeTemperature.Val_HiLim","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "temperature_startup_limit","AIn_IntakeTemperature.Val_LoLim","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "sensor_height","cfg_DHSensorDistToIntake","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "last_vfd_fault_code","PowerFlex755.Val_LastFaultCode","INT", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_vfd_fault","sts_CurrentVFDFaultCode","INT", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_io_fault","ControllerFault_IO","BOOL", 1, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "alarm_program_fault","ControllerFault_Program","BOOL", 1, 3600, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "minvfdfrequency","PowerFlex755.Cfg_MinSpdRef","REAL", 1, 86400, plc_type="CLX"),
|
||||
#PLCChannel(PLC_IP_ADDRESS, "maxvfdfrequency","PowerFlex755.Cfg_MaxSpdRef","REAL", 1, 86400, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_net","in_HART_Flowmeter_Net","REAL", 100, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_forward","in_HART_Flowmeter_Fwd","REAL", 100, 3600, plc_type="CLX"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_reverse","in_HART_Flowmeter_Rev","REAL", 100, 3600, plc_type="CLX")
|
||||
]
|
||||
214
advvfdipppond/advvfdipppond.py
Normal file
214
advvfdipppond/advvfdipppond.py
Normal file
@@ -0,0 +1,214 @@
|
||||
"""Driver for advvfdipppond"""
|
||||
|
||||
import threading
|
||||
import json
|
||||
import os
|
||||
import time
|
||||
from random import randint
|
||||
# PERSISTENCE FILE
|
||||
import persistence
|
||||
PERSIST = persistence.load("extra_data.json")
|
||||
if not PERSIST:
|
||||
PERSIST = {'ip_address': '192.168.1.10', 'download_pycomm': True, 'flowmeter_units': 'GPM'}
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
os.system('echo "" > /root/python_firmware/drivers/modbusMap.p')
|
||||
PLC_IP_ADDRESS = PERSIST['ip_address']
|
||||
from device_base import deviceBase
|
||||
import urllib
|
||||
if PERSIST['download_pycomm']:
|
||||
try:
|
||||
urllib.urlretrieve('http://s3.amazonaws.com/pocloud-drivers/pycomm/clx.py', '/root/python_firmware/pycomm/ab_comm/clx.py')
|
||||
urllib.urlretrieve('http://s3.amazonaws.com/pocloud-drivers/pycomm/cip_base.py', '/root/python_firmware/pycomm/cip/cip_base.py')
|
||||
PERSIST['download_pycomm'] = False
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
except Exception as e:
|
||||
print("Could not download latest pycomm update: {}".format(e))
|
||||
|
||||
from Channel import PLCChannel, ModbusChannel,read_tag, write_tag, TAG_DATAERROR_SLEEPTIME
|
||||
from utilities import get_public_ip_address, get_private_ip_address, get_additional_tags, convert_int
|
||||
from file_logger import filelogger as log
|
||||
from Tags import tags
|
||||
|
||||
|
||||
path = "/root/python_firmware/drivers/additional_tags.py"
|
||||
|
||||
f = open(path, "a+")
|
||||
f.seek(0)
|
||||
if os.stat(path).st_size == 0:
|
||||
f.write("from Channel import PLCChannel, ModbusChannel\n")
|
||||
f.write("from advvfdipppond import PLC_IP_ADDRESS\n")
|
||||
f.write("additional_tags = []")
|
||||
f.close()
|
||||
|
||||
|
||||
from additional_tags import additional_tags
|
||||
|
||||
_ = None
|
||||
|
||||
log.info("advvfdipppond startup")
|
||||
|
||||
# GLOBAL VARIABLES
|
||||
WAIT_FOR_CONNECTION_SECONDS = 30
|
||||
IP_CHECK_PERIOD = 60
|
||||
|
||||
CHANNELS = tags + additional_tags
|
||||
|
||||
|
||||
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.force_send = False
|
||||
self.public_ip_address = ""
|
||||
self.private_ip_address = ""
|
||||
self.public_ip_address_last_checked = 0
|
||||
self.ping_counter = 0
|
||||
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)
|
||||
pass
|
||||
|
||||
def run(self):
|
||||
"""Actually run the driver."""
|
||||
for i in range(0, WAIT_FOR_CONNECTION_SECONDS):
|
||||
print("advvfdipppond driver will start in {} seconds".format(WAIT_FOR_CONNECTION_SECONDS - i))
|
||||
time.sleep(1)
|
||||
log.info("BOOM! Starting advvfdipppond driver...")
|
||||
|
||||
|
||||
|
||||
self._check_ip_address()
|
||||
|
||||
self.nodes["advvfdipppond_0199"] = self
|
||||
try:
|
||||
if PERSIST['flowmeter_units']:
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipppond')
|
||||
else:
|
||||
PERSIST['flowmeter_units'] = "GPM"
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipppond')
|
||||
except:
|
||||
PERSIST['flowmeter_units'] = "GPM"
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipppond')
|
||||
send_loops = 0
|
||||
convert_list = ["Device_Status_INT","sts_PID_Control","Downhole_Sensor_Status_INT","alarm_Flowmeter","alarm_IntakePressure",
|
||||
"alarm_IntakeTemperature","alarm_TubingPressure","alarm_VFD","alarm_Lockout","alarm_FluidLevel","Run_Permissive_INT",
|
||||
"Start_Permissive_INT","PowerFlex755.Val_LastFaultCode","sts_CurrentVFDFaultCode"]
|
||||
while True:
|
||||
now = time.time()
|
||||
if self.force_send:
|
||||
log.warning("FORCE SEND: TRUE")
|
||||
|
||||
for chan in CHANNELS:
|
||||
try:
|
||||
val = chan.read()
|
||||
if "hart" in chan.mesh_name and val == None:
|
||||
val = 0.0
|
||||
if chan.check(val, self.force_send):
|
||||
if chan.plc_tag in convert_list:
|
||||
converted_value = convert_int(chan.plc_tag, val)
|
||||
self.sendtodbDev(1, chan.mesh_name, converted_value, 0, 'advvfdipppond')
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'advvfdipppond')
|
||||
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
||||
except Exception as e:
|
||||
log.info("Error: {}".format(e))
|
||||
time.sleep(30) #sleep for 30 seconds after a full poll
|
||||
# print("advvfdipppond driver still alive...")
|
||||
if self.force_send:
|
||||
if send_loops > 2:
|
||||
log.warning("Turning off force_send")
|
||||
self.force_send = False
|
||||
send_loops = 0
|
||||
else:
|
||||
send_loops += 1
|
||||
|
||||
|
||||
if (now - self.public_ip_address_last_checked) > IP_CHECK_PERIOD:
|
||||
self._check_ip_address()
|
||||
|
||||
|
||||
def _check_ip_address(self):
|
||||
"""Check the public IP address and send to Meshify if changed."""
|
||||
self.public_ip_address_last_checked = time.time()
|
||||
test_public_ip = get_public_ip_address()
|
||||
test_public_ip = test_public_ip
|
||||
test_private_ip = get_private_ip_address()
|
||||
if not test_public_ip == self.public_ip_address and not test_public_ip == "0.0.0.0":
|
||||
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'advvfdipppond')
|
||||
self.public_ip_address = test_public_ip
|
||||
if not test_private_ip == self.private_ip_address:
|
||||
self.sendtodbDev(1, 'private_ip_address', test_private_ip, 0, 'advvfdipppond')
|
||||
self.private_ip_address = test_private_ip
|
||||
hostname = "google.com"
|
||||
response = 1
|
||||
try:
|
||||
response = os.system("ping -c 1 " + hostname + " > /dev/null 2>&1")
|
||||
except Exception as e:
|
||||
print("Something went wrong in ping: {}".format(e))
|
||||
|
||||
|
||||
#and then check the response...
|
||||
if response == 0:
|
||||
print hostname, 'is up!'
|
||||
self.ping_counter = 0
|
||||
else:
|
||||
print hostname, 'is down!'
|
||||
self.ping_counter += 1
|
||||
|
||||
if self.ping_counter >= 3:
|
||||
log.info("Rebooting because no internet detected")
|
||||
os.system('reboot')
|
||||
|
||||
|
||||
def advvfdipppond_sync(self, name, value):
|
||||
"""Sync all data from the driver."""
|
||||
self.force_send = True
|
||||
# self.sendtodb("log", "synced", 0)
|
||||
return True
|
||||
|
||||
def advvfdipppond_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']
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), tag_n, val_n, plc_type="CLX")
|
||||
print("Result of advvfdipppond_writeplctag(self, {}, {}) = {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def advvfdipppond_startcmd(self,name, value):
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "cmd_Start" , 1, plc_type="CLX")
|
||||
print("Result of advvfdipppond_writeplctag(self, {}, {}) = {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def advvfdipppond_stopcmd(self,name, value):
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "cmd_Stop" , 1, plc_type="CLX")
|
||||
print("Result of advvfdipppond_writeplctag(self, {}, {}) = {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def advvfdipppond_flowunits(self, name, value):
|
||||
new_val = json.loads(str(value).replace("'", '"'))
|
||||
PERSIST['flowmeter_units'] = new_val
|
||||
persistence.store(PERSIST, "extra_data.json")
|
||||
self.sendtodbDev(1, 'flowunits', PERSIST['flowmeter_units'], 0, 'advvfdipppond')
|
||||
14
advvfdipppond/config.txt
Normal file
14
advvfdipppond/config.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"files": {
|
||||
"file3": "file_logger.py",
|
||||
"file2": "Channel.py",
|
||||
"file1": "advvfdipppond.py",
|
||||
"file6": "persistence.py",
|
||||
"file5": "utilities.py",
|
||||
"file4": "Tags.py"
|
||||
},
|
||||
"deviceName": "advvfdipppond",
|
||||
"releaseVersion": "1",
|
||||
"driverFileName": "advvfdipppond.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
18
advvfdipppond/file_logger.py
Normal file
18
advvfdipppond/file_logger.py
Normal file
@@ -0,0 +1,18 @@
|
||||
"""Logging setup for advvfdipp"""
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import sys
|
||||
|
||||
log_formatter = logging.Formatter('%(asctime)s %(levelname)s %(funcName)s(%(lineno)d) %(message)s')
|
||||
log_file = './advvfdipppond.log'
|
||||
my_handler = RotatingFileHandler(log_file, mode='a', maxBytes=500*1024,
|
||||
backupCount=2, encoding=None, delay=0)
|
||||
my_handler.setFormatter(log_formatter)
|
||||
my_handler.setLevel(logging.INFO)
|
||||
filelogger = logging.getLogger('advvfdipppond')
|
||||
filelogger.setLevel(logging.INFO)
|
||||
filelogger.addHandler(my_handler)
|
||||
|
||||
console_out = logging.StreamHandler(sys.stdout)
|
||||
console_out.setFormatter(log_formatter)
|
||||
filelogger.addHandler(console_out)
|
||||
21
advvfdipppond/persistence.py
Normal file
21
advvfdipppond/persistence.py
Normal file
@@ -0,0 +1,21 @@
|
||||
"""Data persistance functions."""
|
||||
# if more advanced persistence is needed, use a sqlite database
|
||||
import json
|
||||
|
||||
|
||||
def load(filename="persist.json"):
|
||||
"""Load persisted settings from the specified file."""
|
||||
try:
|
||||
with open(filename, 'r') as persist_file:
|
||||
return json.load(persist_file)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
|
||||
def store(persist_obj, filename="persist.json"):
|
||||
"""Store the persisting settings into the specified file."""
|
||||
try:
|
||||
with open(filename, 'w') as persist_file:
|
||||
return json.dump(persist_obj, persist_file, indent=4)
|
||||
except Exception:
|
||||
return False
|
||||
240
advvfdipppond/utilities.py
Normal file
240
advvfdipppond/utilities.py
Normal file
@@ -0,0 +1,240 @@
|
||||
"""Utility functions for the driver."""
|
||||
import socket
|
||||
import struct
|
||||
from Channel import PLCChannel
|
||||
import urllib
|
||||
import contextlib
|
||||
|
||||
def get_private_ip_address():
|
||||
"""Find the private IP Address of the host device."""
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
try:
|
||||
sock.connect(("8.8.8.8", 80))
|
||||
except Exception as e:
|
||||
return e
|
||||
ip_address = sock.getsockname()[0]
|
||||
sock.close()
|
||||
return ip_address
|
||||
|
||||
def get_public_ip_address():
|
||||
ip_address = "0.0.0.0"
|
||||
try:
|
||||
with contextlib.closing(urllib.urlopen("http://checkip.amazonaws.com")) as url:
|
||||
ip_address = url.read()
|
||||
except Exception as e:
|
||||
print("could not resolve check IP: {}".format(e))
|
||||
return ip_address
|
||||
return ip_address[:-1]
|
||||
|
||||
def int_to_float16(int_to_convert):
|
||||
"""Convert integer into float16 representation."""
|
||||
bin_rep = ('0' * 16 + '{0:b}'.format(int_to_convert))[-16:]
|
||||
sign = 1.0
|
||||
if int(bin_rep[0]) == 1:
|
||||
sign = -1.0
|
||||
exponent = float(int(bin_rep[1:6], 2))
|
||||
fraction = float(int(bin_rep[6:17], 2))
|
||||
|
||||
if exponent == float(0b00000):
|
||||
return sign * 2 ** -14 * fraction / (2.0 ** 10.0)
|
||||
elif exponent == float(0b11111):
|
||||
if fraction == 0:
|
||||
return sign * float("inf")
|
||||
return float("NaN")
|
||||
frac_part = 1.0 + fraction / (2.0 ** 10.0)
|
||||
return sign * (2 ** (exponent - 15)) * frac_part
|
||||
|
||||
|
||||
def ints_to_float(int1, int2):
|
||||
"""Convert 2 registers into a floating point number."""
|
||||
mypack = struct.pack('>HH', int1, int2)
|
||||
f_unpacked = struct.unpack('>f', mypack)
|
||||
print("[{}, {}] >> {}".format(int1, int2, f_unpacked[0]))
|
||||
return f_unpacked[0]
|
||||
|
||||
|
||||
def degf_to_degc(temp_f):
|
||||
"""Convert deg F to deg C."""
|
||||
return (temp_f - 32.0) * (5.0/9.0)
|
||||
|
||||
|
||||
def degc_to_degf(temp_c):
|
||||
"""Convert deg C to deg F."""
|
||||
return temp_c * 1.8 + 32.0
|
||||
|
||||
def get_additional_tags(tag_dict):
|
||||
tags_array = tag_dict['additional_tags']
|
||||
channel_array = []
|
||||
for x in tags_array:
|
||||
try:
|
||||
print "Making channel {}".format(x)
|
||||
channel_array.append(PLCChannel(tag_dict['ip_address'], x['mesh_name'], x['plc_tag'], x['data_type'],x['chg_threshold'],x['guarantee_sec'],plc_type='CLX'))
|
||||
except Exception:
|
||||
print "Nothing to write or bad key"
|
||||
return channel_array
|
||||
|
||||
def convert_int(plc_tag, value):
|
||||
well_status_codes = {
|
||||
0: "Running",
|
||||
1: "Pumped Off",
|
||||
2: "Alarmed",
|
||||
3: "Locked Out",
|
||||
4: "Stopped"
|
||||
}
|
||||
|
||||
pid_control_codes = {
|
||||
0: "Flow",
|
||||
1: "Fluid Level",
|
||||
2: "Tubing Pressure",
|
||||
3: "Manual"
|
||||
}
|
||||
|
||||
downhole_codes = {
|
||||
0: "OK",
|
||||
1: "Connecting",
|
||||
2: "Open Circuit",
|
||||
3: "Shorted",
|
||||
4: "Cannot Decode"
|
||||
}
|
||||
|
||||
permissive_codes = {
|
||||
0: "OK",
|
||||
1: "Flow",
|
||||
2: "Intake Pressure",
|
||||
3: "Intake Temperature",
|
||||
4: "Tubing Pressure",
|
||||
5: "VFD",
|
||||
6: "Fluid Level",
|
||||
7: "Min. Downtime"
|
||||
}
|
||||
|
||||
alarm_codes = {
|
||||
0: "OK",
|
||||
1: "Alarm"
|
||||
}
|
||||
|
||||
alarm_vfd_codes = {
|
||||
0: "OK",
|
||||
1: "Locked Out"
|
||||
}
|
||||
|
||||
vfd_fault_codes = {
|
||||
0: "No Fault",
|
||||
2: "Auxiliary Input",
|
||||
3: "Power Loss",
|
||||
4: "UnderVoltage",
|
||||
5: "OverVoltage",
|
||||
7: "Motor Overload",
|
||||
8: "Heatsink OverTemp",
|
||||
9: "Thermister OverTemp",
|
||||
10: "Dynamic Brake OverTemp",
|
||||
12: "Hardware OverCurrent",
|
||||
13: "Ground Fault",
|
||||
14: "Ground Warning",
|
||||
15: "Load Loss",
|
||||
17: "Input Phase Loss",
|
||||
18: "Motor PTC Trip",
|
||||
19: "Task Overrun",
|
||||
20: "Torque Prove Speed Band",
|
||||
21: "Output Phase Loss",
|
||||
24: "Decel Inhibit",
|
||||
25: "OverSpeed Limit",
|
||||
26: "Brake Slipped",
|
||||
27: "Torque Prove Conflict",
|
||||
28: "TP Encls Confict",
|
||||
29: "Analog In Loss",
|
||||
33: "Auto Restarts Exhausted",
|
||||
35: "IPM OverCurrent",
|
||||
36: "SW OverCurrent",
|
||||
38: "Phase U to Ground",
|
||||
39: "Phase V to Ground",
|
||||
40: "Phase W to Ground",
|
||||
41: "Phase UV Short",
|
||||
42: "Phase VW Short",
|
||||
43: "Phase WU Short",
|
||||
44: "Phase UNeg to Ground",
|
||||
45: "Phase VNeg to Ground",
|
||||
46: "Phase WNeg to Ground",
|
||||
48: "System Defaulted",
|
||||
49: "Drive Powerup",
|
||||
51: "Clear Fault Queue",
|
||||
55: "Control Board Overtemp",
|
||||
59: "Invalid Code",
|
||||
61: "Shear Pin 1",
|
||||
62: "Shear Pin 2",
|
||||
64: "Drive Overload",
|
||||
66: "OW Torque Level",
|
||||
67: "Pump Off",
|
||||
71: "Port 1 Adapter",
|
||||
72: "Port 2 Adapter",
|
||||
73: "Port 3 Adapter",
|
||||
74: "Port 4 Adapter",
|
||||
75: "Port 5 Adapter",
|
||||
76: "Port 6 Adapter",
|
||||
77: "IR Volts Range",
|
||||
78: "FluxAmps Ref Range",
|
||||
79: "Excessive Load",
|
||||
80: "AutoTune Aborted",
|
||||
81: "Port 1 DPI Loss",
|
||||
82: "Port 2 DPI Loss",
|
||||
83: "Port 3 DPI Loss",
|
||||
84: "Port 4 DPI Loss",
|
||||
85: "Port 5 DPI Loss",
|
||||
86: "Port 6 DPI Loss",
|
||||
87: "IXo Voltage Range",
|
||||
91: "Primary Velocity Feedback Loss",
|
||||
93: "Hardware Enable Check",
|
||||
94: "Alternate Velocity Feedback Loss",
|
||||
95: "Auxiliary Velocity Feedback Loss",
|
||||
96: "Position Feedback Loss",
|
||||
97: "Auto Tach Switch",
|
||||
100: "Parameter Checksum",
|
||||
101: "Power Down NVS Blank",
|
||||
102: "NVS Not Blank",
|
||||
103: "Power Down NVS Incompatible",
|
||||
104: "Power Board Checksum",
|
||||
106: "Incompat MCB-PB",
|
||||
107: "Replaced MCB-PB",
|
||||
108: "Analog Calibration Checksum",
|
||||
110: "Invalid Power Board Data",
|
||||
111: "Power Board Invalid ID",
|
||||
112: "Power Board App Min Version",
|
||||
113: "Tracking DataError",
|
||||
115: "Power Down Table Full",
|
||||
116: "Power Down Entry Too Large",
|
||||
117: "Power Down Data Checksum",
|
||||
118: "Power Board Power Down Checksum",
|
||||
124: "App ID Changed",
|
||||
125: "Using Backup App",
|
||||
134: "Start on Power Up",
|
||||
137: "External Precharge Error",
|
||||
138: "Precharge Open",
|
||||
141: "Autotune Enc Angle",
|
||||
142: "Autotune Speed Restricted",
|
||||
143: "Autotune Current Regulator",
|
||||
144: "Autotune Inertia",
|
||||
145: "Autotune Travel",
|
||||
13035: "Net IO Timeout",
|
||||
13037: "Net IO Timeout"
|
||||
|
||||
}
|
||||
|
||||
plc_tags = {
|
||||
"Device_Status_INT": well_status_codes.get(value, "Invalid Code"),
|
||||
"sts_PID_Control": pid_control_codes.get(value, "Invalid Code"),
|
||||
"Downhole_Sensor_Status_INT": downhole_codes.get(value, "Invalid Code"),
|
||||
"alarm_Flowmeter": alarm_codes.get(value, "Invalid Code"),
|
||||
"alarm_IntakePressure": alarm_codes.get(value, "Invalid Code"),
|
||||
"alarm_IntakeTemperature": alarm_codes.get(value, "Invalid Code"),
|
||||
"alarm_TubingPressure": alarm_codes.get(value, "Invalid Code"),
|
||||
"alarm_VFD": alarm_codes.get(value, "Invalid Code"),
|
||||
"alarm_Lockout": alarm_vfd_codes.get(value, "Invalid Code"),
|
||||
"alarm_FluidLevel": alarm_codes.get(value, "Invalid Code"),
|
||||
"Run_Permissive_INT": permissive_codes.get(value, "Invalid Code"),
|
||||
"Start_Permissive_INT": permissive_codes.get(value, "Invalid Code"),
|
||||
"PowerFlex755.Val_LastFaultCode": vfd_fault_codes.get(value, "Invalid Code"),
|
||||
"sts_CurrentVFDFaultCode": vfd_fault_codes.get(value, "Invalid Code")
|
||||
}
|
||||
|
||||
return plc_tags.get(plc_tag, "Invalid Tag")
|
||||
|
||||
@@ -15,7 +15,7 @@ tags = [
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_fr","val_fm2_fr","REAL", 5, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_t1","val_fm2_t1","REAL", 50, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_t2","val_fm2_t2","REAL", 50, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_t3","val_fm2_t3","REAL", 50, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_t3","val_fm3_t3","REAL", 50, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_yesterday","val_fm2_yesterday","REAL", 100, 86400, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_today","val_fm2_today","REAL", 25, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "val_fm2_lastmonth","val_fm2_lastmonth","REAL", 100, 86400, plc_type="Micro800"),
|
||||
|
||||
@@ -26,7 +26,11 @@ CHANNELS = tags
|
||||
|
||||
# PERSISTENCE FILE
|
||||
PERSIST = persistence.load()
|
||||
|
||||
if not PERSIST:
|
||||
PERSIST = {
|
||||
"ignore_list": []
|
||||
}
|
||||
persistence.store(PERSIST)
|
||||
|
||||
class start(threading.Thread, deviceBase):
|
||||
"""Start class required by Meshify."""
|
||||
@@ -75,7 +79,10 @@ class start(threading.Thread, deviceBase):
|
||||
for chan in CHANNELS:
|
||||
val = chan.read()
|
||||
if chan.check(val, self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'flowmeterskid')
|
||||
if chan.mesh_name in PERSIST["ignore_list"]:
|
||||
self.sendtodbDev(1, chan.mesh_name, None, 0, 'flowmeterskid')
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'flowmeterskid')
|
||||
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
||||
|
||||
# print("flowmeterskid driver still alive...")
|
||||
@@ -131,3 +138,15 @@ class start(threading.Thread, deviceBase):
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def flowmeterskid_ignorechannel(self, name, value):
|
||||
if value not in PERSIST["ignore_list"]:
|
||||
PERSIST["ignore_list"].append(value)
|
||||
persistence.store(PERSIST)
|
||||
return True
|
||||
|
||||
def flowmeterskid_observechannel(self, name, value):
|
||||
if value in PERSIST["ignore_list"]:
|
||||
PERSIST["ignore_list"].remove(value)
|
||||
persistence.store(PERSIST)
|
||||
return True
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"file4": "Tags.py"
|
||||
},
|
||||
"deviceName": "plcfreshwater",
|
||||
"releaseVersion": "11",
|
||||
"releaseVersion": "12",
|
||||
"driverFileName": "plcfreshwater.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
@@ -53,7 +53,7 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "11"
|
||||
self.version = "12"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
@@ -276,11 +276,11 @@ class start(threading.Thread, deviceBase):
|
||||
#if a comms error use the stored values else use the latested values
|
||||
if val == None:
|
||||
PERSIST['Previous Months'] = PERSIST['Current Months']
|
||||
PERSIST['Current Month'] = 0
|
||||
PERSIST['Current Months'] = 0
|
||||
PERSIST['Monthly Holding'] = PERSIST['Lifetime']
|
||||
else:
|
||||
PERSIST['Previous Months'] = val - PERSIST['Monthly Holding']
|
||||
PERSIST['Current Month'] = 0
|
||||
PERSIST['Current Months'] = 0
|
||||
PERSIST['Monthly Holding'] = val
|
||||
PERSIST['Month'] = month
|
||||
self.sendtodbDev(1, 'total_fm_month_gal', PERSIST['Current Months'], 0, 'plcfreshwater')
|
||||
|
||||
512
promagmbs/modbusMap.json
Normal file
512
promagmbs/modbusMap.json
Normal file
@@ -0,0 +1,512 @@
|
||||
{
|
||||
"1": {
|
||||
"c": "M1-485",
|
||||
"b": "9600",
|
||||
"addresses": {
|
||||
"2": {
|
||||
"4-1": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "0",
|
||||
"vn": "Volume Flow",
|
||||
"ct": "number",
|
||||
"le": "32",
|
||||
"grp": "600",
|
||||
"la": 0.0,
|
||||
"chn": "volume_flow",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"da": "2",
|
||||
"lrt": 1515775636.862535,
|
||||
"a": "2008",
|
||||
"c": "5",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-1",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-100000",
|
||||
"t": "floatbs",
|
||||
"vm": null
|
||||
},
|
||||
"4-3": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "0",
|
||||
"vn": "Conductivity",
|
||||
"ct": "number",
|
||||
"le": "32",
|
||||
"grp": "600",
|
||||
"la": NaN,
|
||||
"chn": "conductivity",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"da": "2",
|
||||
"lrt": 1515775621.262141,
|
||||
"a": "2012",
|
||||
"c": "0.5",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-3",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-10000",
|
||||
"t": "floatbs",
|
||||
"vm": null
|
||||
},
|
||||
"4-4": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "0",
|
||||
"vn": "Totalizer 1",
|
||||
"ct": "number",
|
||||
"le": "32",
|
||||
"grp": "600",
|
||||
"la": 245249.88,
|
||||
"chn": "totalizer_1",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"da": "2",
|
||||
"lrt": 1515775638.257201,
|
||||
"a": "2609",
|
||||
"c": "50.0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-4",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-10000000",
|
||||
"t": "floatbs",
|
||||
"vm": null
|
||||
},
|
||||
"4-5": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "0",
|
||||
"vn": "Totalizer 2",
|
||||
"ct": "number",
|
||||
"le": "32",
|
||||
"grp": "600",
|
||||
"la": 265849.72,
|
||||
"chn": "totalizer_2",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"da": "2",
|
||||
"lrt": 1515775574.650748,
|
||||
"a": "2809",
|
||||
"c": "50",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-5",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-10000000",
|
||||
"t": "floatbs",
|
||||
"vm": null
|
||||
},
|
||||
"4-6": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "0",
|
||||
"vn": "Totalizer 3",
|
||||
"ct": "number",
|
||||
"le": "32",
|
||||
"grp": "600",
|
||||
"la": 0,
|
||||
"chn": "totalizer_3",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"da": "2",
|
||||
"lrt": 1515624472.5080974,
|
||||
"r": "-10000000-10000000",
|
||||
"a": "3009",
|
||||
"c": "50",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-6",
|
||||
"s": "On",
|
||||
"mv": "0",
|
||||
"t": "floatbs",
|
||||
"vm": null
|
||||
},
|
||||
"4-7": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "",
|
||||
"vn": "Volume Flow Units",
|
||||
"ct": "number",
|
||||
"le": "16",
|
||||
"grp": "86400",
|
||||
"la": 45,
|
||||
"chn": "volume_flow_units",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"da": "2",
|
||||
"lrt": 1515711271.343798,
|
||||
"a": "2102",
|
||||
"c": "0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-7",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-100",
|
||||
"t": "int",
|
||||
"vm": {
|
||||
"24": "Ml/s",
|
||||
"25": "Ml/min",
|
||||
"26": "Ml/h",
|
||||
"27": "Ml/d",
|
||||
"20": "hl/s",
|
||||
"21": "hl/min",
|
||||
"22": "hl/h",
|
||||
"23": "hl/d",
|
||||
"0": "cm3/s",
|
||||
"4": "dm3/s",
|
||||
"8": "m3/s",
|
||||
"59": "BBL/d (US beer)",
|
||||
"58": "BBL/h (US beer)",
|
||||
"55": "BBL/d (US liq.)",
|
||||
"54": "BBL/h (US liq.)",
|
||||
"57": "BBL/min (US beer)",
|
||||
"56": "BBL/s (US beer)",
|
||||
"51": "Mgal/d",
|
||||
"50": "Mgal/h",
|
||||
"53": "BBL/min (US liq.)",
|
||||
"52": "BBL/s (US liq.)",
|
||||
"88": "kgal/s (us)",
|
||||
"89": "kgal/min (us)",
|
||||
"82": "BBL/h (imp oil)",
|
||||
"83": "BBL/d (imp oil)",
|
||||
"80": "BBL/s (imp oil)",
|
||||
"81": "BBL/min (imp oil)",
|
||||
"86": "User vol / hour",
|
||||
"87": "User vol / day",
|
||||
"84": "User vol / s",
|
||||
"85": "User vol / min",
|
||||
"3": "cm3/d",
|
||||
"7": "dm3/d",
|
||||
"39": "ft3/d",
|
||||
"38": "ft3/h",
|
||||
"33": "af/min",
|
||||
"32": "af/s",
|
||||
"37": "ft3/min",
|
||||
"36": "ft3/s",
|
||||
"35": "af/d",
|
||||
"34": "af/h",
|
||||
"60": "BBL/s (US oil)",
|
||||
"61": "BBL/min (US oil)",
|
||||
"62": "BBL/h (US oil)",
|
||||
"63": "BBL/d (US oil)",
|
||||
"64": "BBL/s (US tank)",
|
||||
"65": "BBL/min (US tank)",
|
||||
"66": "BBL/h (US tank)",
|
||||
"67": "BBL/d (US tank)",
|
||||
"68": "gal/s (imp)",
|
||||
"69": "gal/min (imp)",
|
||||
"2": "cm3/h",
|
||||
"6": "dm3/h",
|
||||
"91": "kgal/d (us)",
|
||||
"90": "kgal/h (us)",
|
||||
"11": "m3/d",
|
||||
"10": "m3/h",
|
||||
"13": "mL/min",
|
||||
"12": "mL/s",
|
||||
"15": "mL/d",
|
||||
"14": "mL/h",
|
||||
"17": "l/min",
|
||||
"16": "l/s",
|
||||
"19": "l/d",
|
||||
"18": "l/h",
|
||||
"48": "Mgal/s",
|
||||
"49": "Mgal/min",
|
||||
"46": "gal/h",
|
||||
"47": "gal/d",
|
||||
"44": "gal/s",
|
||||
"45": "gal/min",
|
||||
"42": "fl oz/h",
|
||||
"43": "fl oz/d",
|
||||
"40": "fl oz/s",
|
||||
"41": "fl oz/min",
|
||||
"1": "cm3/min",
|
||||
"5": "dm3/min",
|
||||
"9": "m3/min",
|
||||
"77": "BBL/min (imp beer)",
|
||||
"76": "BBL/s (imp beer)",
|
||||
"75": "Mgal/d (imp)",
|
||||
"74": "Mgal/h (imp)",
|
||||
"73": "Mgal/min (imp)",
|
||||
"72": "Mgal/s (imp)",
|
||||
"71": "gal/d (imp)",
|
||||
"70": "gal/h (imp)",
|
||||
"79": "BBL/d (imp beer)",
|
||||
"78": "BBL/h (imp beer)"
|
||||
}
|
||||
},
|
||||
"4-8": {
|
||||
"r": "0-22",
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "",
|
||||
"vn": "Volume Units",
|
||||
"ct": "number",
|
||||
"le": "16",
|
||||
"grp": "86400",
|
||||
"la": 11,
|
||||
"chn": "",
|
||||
"un": "",
|
||||
"dn": "M1",
|
||||
"vm": {
|
||||
"20": "BBL (imp oil)",
|
||||
"21": "User vol.",
|
||||
"22": "kgal (us)",
|
||||
"1": "dm3",
|
||||
"0": "cm3",
|
||||
"3": "ml",
|
||||
"2": "m3",
|
||||
"5": "hl",
|
||||
"4": "l",
|
||||
"6": "Ml Mega",
|
||||
"9": "ft3",
|
||||
"8": "af",
|
||||
"11": "gal (us)",
|
||||
"10": "fl oz (us)",
|
||||
"13": "BBL (US liq)",
|
||||
"12": "Mgal (us)",
|
||||
"15": "BBL (US oil)",
|
||||
"14": "BBL (US beer)",
|
||||
"17": "gal (imp)",
|
||||
"16": "BBL (US tank)",
|
||||
"19": "BBL (imp beer)",
|
||||
"18": "Mgal (imp)"
|
||||
},
|
||||
"lrt": 1515711271.8358026,
|
||||
"da": "2",
|
||||
"a": "2103",
|
||||
"c": "0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-8",
|
||||
"s": "On",
|
||||
"mv": "0",
|
||||
"t": "int"
|
||||
},
|
||||
"4-9": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "",
|
||||
"vn": "Conductivity Unit",
|
||||
"ct": "number",
|
||||
"le": "16",
|
||||
"grp": "86400",
|
||||
"la": 8,
|
||||
"chn": "",
|
||||
"un": "",
|
||||
"dn": "M1",
|
||||
"vm": null,
|
||||
"lrt": 1515711272.327509,
|
||||
"da": "2",
|
||||
"a": "2120",
|
||||
"c": "0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-9",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-10",
|
||||
"t": "int"
|
||||
},
|
||||
"4-12": {
|
||||
"r": "0-56",
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "",
|
||||
"vn": "Totalizer 1 Units",
|
||||
"ct": "number",
|
||||
"le": "16",
|
||||
"grp": "86400",
|
||||
"la": 11,
|
||||
"chn": "totalizer_1_units",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"vm": {
|
||||
"20": "BBL (imp oil)",
|
||||
"21": "User vol.",
|
||||
"22": "kGal (us)",
|
||||
"1": "dm3",
|
||||
"0": "cm3",
|
||||
"3": "ml",
|
||||
"2": "m3",
|
||||
"5": "hl",
|
||||
"4": "l",
|
||||
"6": "Ml Mega",
|
||||
"9": "ft3",
|
||||
"8": "af",
|
||||
"11": "gal (us)",
|
||||
"10": "fl oz (us)",
|
||||
"13": "BBL (US liq)",
|
||||
"12": "Mgal (us)",
|
||||
"15": "BBL (US oil)",
|
||||
"14": "BBL (US beer)",
|
||||
"17": "gal (imp)",
|
||||
"16": "BBL (US tank)",
|
||||
"19": "BBL (imp beer)",
|
||||
"18": "Mgal (imp)",
|
||||
"56": "User mass",
|
||||
"51": "kg",
|
||||
"50": "g",
|
||||
"53": "oz",
|
||||
"52": "t",
|
||||
"55": "STon",
|
||||
"54": "lb"
|
||||
},
|
||||
"lrt": 1515711272.82556,
|
||||
"da": "2",
|
||||
"a": "4603",
|
||||
"c": "0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-12",
|
||||
"s": "On",
|
||||
"mv": "0",
|
||||
"t": "int"
|
||||
},
|
||||
"4-13": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "",
|
||||
"vn": "Totalizer 2 Units",
|
||||
"ct": "number",
|
||||
"le": "16",
|
||||
"grp": "86400",
|
||||
"la": 11,
|
||||
"chn": "totalizer_2_units",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"vm": {
|
||||
"20": "BBL (imp oil)",
|
||||
"21": "User vol.",
|
||||
"22": "kGal (us)",
|
||||
"1": "dm3",
|
||||
"0": "cm3",
|
||||
"3": "ml",
|
||||
"2": "m3",
|
||||
"5": "hl",
|
||||
"4": "l",
|
||||
"6": "Ml Mega",
|
||||
"9": "ft3",
|
||||
"8": "af",
|
||||
"11": "gal (us)",
|
||||
"10": "fl oz (us)",
|
||||
"13": "BBL (US liq)",
|
||||
"12": "Mgal (us)",
|
||||
"15": "BBL (US oil)",
|
||||
"14": "BBL (US beer)",
|
||||
"17": "gal (imp)",
|
||||
"16": "BBL (US tank)",
|
||||
"19": "BBL (imp beer)",
|
||||
"18": "Mgal (imp)",
|
||||
"56": "User mass",
|
||||
"51": "kg",
|
||||
"50": "g",
|
||||
"53": "oz",
|
||||
"52": "t",
|
||||
"55": "STon",
|
||||
"54": "lb"
|
||||
},
|
||||
"lrt": 1515711273.323234,
|
||||
"da": "2",
|
||||
"a": "4604",
|
||||
"c": "0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-13",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-56",
|
||||
"t": "int"
|
||||
},
|
||||
"4-14": {
|
||||
"ah": "",
|
||||
"bytary": null,
|
||||
"al": "",
|
||||
"vn": "Totalizer 3 Units",
|
||||
"ct": "number",
|
||||
"le": "16",
|
||||
"grp": "86400",
|
||||
"la": 11,
|
||||
"chn": "totalizer_3_units",
|
||||
"un": "1",
|
||||
"dn": "promagmbs",
|
||||
"vm": {
|
||||
"20": "BBL (imp oil)",
|
||||
"21": "User vol.",
|
||||
"22": "kGal (us)",
|
||||
"1": "dm3",
|
||||
"0": "cm3",
|
||||
"3": "ml",
|
||||
"2": "m3",
|
||||
"5": "hl",
|
||||
"4": "l",
|
||||
"6": "Ml Mega",
|
||||
"9": "ft3",
|
||||
"8": "af",
|
||||
"11": "gal (us)",
|
||||
"10": "fl oz (us)",
|
||||
"13": "BBL (US liq)",
|
||||
"12": "Mgal (us)",
|
||||
"15": "BBL (US oil)",
|
||||
"14": "BBL (US beer)",
|
||||
"17": "gal (imp)",
|
||||
"16": "BBL (US tank)",
|
||||
"19": "BBL (imp beer)",
|
||||
"18": "Mgal (imp)",
|
||||
"56": "User mass",
|
||||
"51": "kg",
|
||||
"50": "g",
|
||||
"53": "oz",
|
||||
"52": "t",
|
||||
"55": "STon",
|
||||
"54": "lb"
|
||||
},
|
||||
"lrt": 1515711273.829602,
|
||||
"da": "2",
|
||||
"a": "4605",
|
||||
"c": "0",
|
||||
"misc_u": "",
|
||||
"f": "3",
|
||||
"mrt": "60",
|
||||
"m": "none",
|
||||
"m1ch": "4-14",
|
||||
"mv": "0",
|
||||
"s": "On",
|
||||
"r": "0-56",
|
||||
"t": "int"
|
||||
}
|
||||
}
|
||||
},
|
||||
"f": "Off",
|
||||
"p": "None",
|
||||
"s": "2"
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,66 +2,81 @@ from Channel import PLCChannel, ModbusChannel
|
||||
from tenflowmeterskid import PLC_IP_ADDRESS
|
||||
|
||||
tags = [
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_flowrate","Val_FM1_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_flowrate","Val_FM2_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_flowrate","Val_FM3_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_flowrate","Val_FM4_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_flowrate","Val_FM5_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_flowrate","Val_FM6_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_flowrate","Val_FM7_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_flowrate","Val_FM8_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_flowrate","Val_FM9_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_flowrate","Val_FM10_FR","REAL", 250, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_lifetime","Val_FM1_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_lifetime","Val_FM2_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_lifetime","Val_FM3_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_lifetime","Val_FM4_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_lifetime","Val_FM5_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_lifetime","Val_FM6_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_lifetime","Val_FM7_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_lifetime","Val_FM8_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_lifetime","Val_FM9_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_lifetime","Val_FM10_T1","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_month","Val_Flowmeter1MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_month","Val_Flowmeter2MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_month","Val_Flowmeter3MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_month","Val_Flowmeter4MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_month","Val_Flowmeter5MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_month","Val_Flowmeter6MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_month","Val_Flowmeter7MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_month","Val_Flowmeter8MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_month","Val_Flowmeter9MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_month","Val_Flowmeter10MonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_lastmonth","Val_Flowmeter1LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_lastmonth","Val_Flowmeter2LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_lastmonth","Val_Flowmeter3LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_lastmonth","Val_Flowmeter4LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_lastmonth","Val_Flowmeter5LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_lastmonth","Val_Flowmeter6LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_lastmonth","Val_Flowmeter7LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_lastmonth","Val_Flowmeter8LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_lastmonth","Val_Flowmeter9LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_lastmonth","Val_Flowmeter10LastMonthTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_yesterdays","Val_Flowmeter1YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_yesterdays","Val_Flowmeter2YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_yesterdays","Val_Flowmeter3YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_yesterdays","Val_Flowmeter4YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_yesterdays","Val_Flowmeter5YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_yesterdays","Val_Flowmeter6YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_yesterdays","Val_Flowmeter7YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_yesterdays","Val_Flowmeter8YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_yesterdays","Val_Flowmeter9YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_yesterdays","Val_Flowmeter10YesterdaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_todays","Val_Flowmeter1TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_todays","Val_Flowmeter2TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_todays","Val_Flowmeter3TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_todays","Val_Flowmeter4TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_todays","Val_Flowmeter5TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_todays","Val_Flowmeter6TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_todays","Val_Flowmeter7TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_todays","Val_Flowmeter8TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_todays","Val_Flowmeter9TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_todays","Val_Flowmeter10TodaysTotal","REAL", 100, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_flowrate","Val_FM1_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_flowrate","Val_FM2_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_flowrate","Val_FM3_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_flowrate","Val_FM4_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_flowrate","Val_FM5_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_flowrate","Val_FM6_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_flowrate","Val_FM7_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_flowrate","Val_FM8_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_flowrate","Val_FM9_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_flowrate","Val_FM10_FR","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_flowrate", "Val_FRTotalIn", "REAL",1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_flowrate", "Val_FRTotalOut", "REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_lifetime","Val_FM1_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_lifetime","Val_FM2_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_lifetime","Val_FM3_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_lifetime","Val_FM4_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_lifetime","Val_FM5_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_lifetime","Val_FM6_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_lifetime","Val_FM7_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_lifetime","Val_FM8_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_lifetime","Val_FM9_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_lifetime","Val_FM10_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "forward_out_lifetime","Val_Out_T1","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "net_out_lifetime","Val_Out_T2","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "reverse_out_lifetime","Val_Out_T3","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_lifetime", "Val_T1TotalIn", "REAL",1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_lifetime", "Val_T1TotalOut", "REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_month","Val_Flowmeter1MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_month","Val_Flowmeter2MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_month","Val_Flowmeter3MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_month","Val_Flowmeter4MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_month","Val_Flowmeter5MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_month","Val_Flowmeter6MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_month","Val_Flowmeter7MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_month","Val_Flowmeter8MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_month","Val_Flowmeter9MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_month","Val_Flowmeter10MonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_month", "Val_MonthTotalIn", "REAL",1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_month", "Val_MonthTotalOut", "REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_lastmonth","Val_Flowmeter1LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_lastmonth","Val_Flowmeter2LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_lastmonth","Val_Flowmeter3LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_lastmonth","Val_Flowmeter4LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_lastmonth","Val_Flowmeter5LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_lastmonth","Val_Flowmeter6LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_lastmonth","Val_Flowmeter7LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_lastmonth","Val_Flowmeter8LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_lastmonth","Val_Flowmeter9LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_lastmonth","Val_Flowmeter10LastMonthTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_lastmonth", "Val_LastMonthTotalIn", "REAL",1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_lastmonth", "Val_LastMonthTotalOut", "REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_yesterdays","Val_Flowmeter1YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_yesterdays","Val_Flowmeter2YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_yesterdays","Val_Flowmeter3YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_yesterdays","Val_Flowmeter4YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_yesterdays","Val_Flowmeter5YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_yesterdays","Val_Flowmeter6YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_yesterdays","Val_Flowmeter7YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_yesterdays","Val_Flowmeter8YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_yesterdays","Val_Flowmeter9YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_yesterdays","Val_Flowmeter10YesterdaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_yesterday", "Val_YesterdaysTotalIn", "REAL",1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_yesterday", "Val_YesterdaysTotalOut", "REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm1_todays","Val_Flowmeter1TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm2_todays","Val_Flowmeter2TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm3_todays","Val_Flowmeter3TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm4_todays","Val_Flowmeter4TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm5_todays","Val_Flowmeter5TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm6_todays","Val_Flowmeter6TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm7_todays","Val_Flowmeter7TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm8_todays","Val_Flowmeter8TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm9_todays","Val_Flowmeter9TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "fm10_todays","Val_Flowmeter10TodaysTotal","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_in_today", "Val_TodaysTotalIn", "REAL",1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "total_out_today", "Val_TodaysTotalOut", "REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_raw_min","pond1scaling.rawmin","REAL", 5, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_raw_max","pond1scaling.rawmax","REAL", 5, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_eu_min","pond1scaling.eumin","REAL", 5, 3600, plc_type="Micro800"),
|
||||
@@ -74,11 +89,11 @@ tags = [
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_2_offset","pond2offset","REAL", 5, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_height","pond1Height","REAL", 5, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_2_height","pond2height","REAL", 5, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_volume","pond1volume","REAL", 100000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_2_volume","pond2volume","REAL", 100000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_sum_volume","pondVolumeTotal","REAL", 300000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_volume","pond1volume","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_2_volume","pond2volume","REAL", 1000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_sum_volume","pondVolumeTotal","REAL", 3000000000, 3600, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_high_spt","SPT_Pond_1_High_Level","REAL", 1, 86400, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_2_high_spt","SPT_Pond_2_High_Level","REAL", 1, 86400, plc_type="Micro800"),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_1_alarm","Pond1HiAlarm","BOOL", 0, 3600, plc_type="Micro800", map_={0: "Good", 1: "High", None: "Error"}),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond_2_alarm","Pond2HiAlarm","BOOL", 0, 3600, plc_type="Micro800", map_={0: "Good", 1: "High", None: "Error"})
|
||||
]
|
||||
]
|
||||
|
||||
@@ -8,7 +8,7 @@ import os
|
||||
from device_base import deviceBase
|
||||
from Channel import PLCChannel, ModbusChannel,read_tag, write_tag, TAG_DATAERROR_SLEEPTIME
|
||||
import persistence
|
||||
from utilities import get_public_ip_address
|
||||
from utilities import get_public_ip_address, get_private_ip_address
|
||||
from file_logger import filelogger as log
|
||||
PLC_IP_ADDRESS = "192.168.1.12"
|
||||
from Tags import tags
|
||||
@@ -26,6 +26,11 @@ CHANNELS = tags
|
||||
|
||||
# PERSISTENCE FILE
|
||||
PERSIST = persistence.load()
|
||||
if not PERSIST:
|
||||
PERSIST = {
|
||||
"ignore_list": []
|
||||
}
|
||||
persistence.store(PERSIST)
|
||||
|
||||
CALIBRATION_TABLES = [[],[], [], ]
|
||||
|
||||
@@ -45,6 +50,7 @@ class start(threading.Thread, deviceBase):
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
self.private_ip_address = ""
|
||||
self.public_ip_address_last_checked = 0
|
||||
threading.Thread.start(self)
|
||||
|
||||
@@ -76,7 +82,10 @@ class start(threading.Thread, deviceBase):
|
||||
for chan in CHANNELS:
|
||||
val = chan.read()
|
||||
if chan.check(val, self.force_send):
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'tenflowmeterskid')
|
||||
if chan.mesh_name in PERSIST["ignore_list"]:
|
||||
self.sendtodbDev(1, chan.mesh_name, None, 0, 'tenflowmeterskid')
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'tenflowmeterskid')
|
||||
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
||||
|
||||
for pond_index in range(1, 3):
|
||||
@@ -100,11 +109,21 @@ class start(threading.Thread, deviceBase):
|
||||
"""Check the public IP address and send to Meshify if changed."""
|
||||
self.public_ip_address_last_checked = time.time()
|
||||
test_public_ip = get_public_ip_address()
|
||||
if not test_public_ip == self.public_ip_address:
|
||||
test_public_ip = test_public_ip
|
||||
test_private_ip = get_private_ip_address()
|
||||
if not test_public_ip == self.public_ip_address and not test_public_ip == "0.0.0.0":
|
||||
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'tenflowmeterskid')
|
||||
self.public_ip_address = test_public_ip
|
||||
if not test_private_ip == self.private_ip_address:
|
||||
self.sendtodbDev(1, 'private_ip_address', test_private_ip, 0, 'tenflowmeterskid')
|
||||
self.private_ip_address = test_private_ip
|
||||
hostname = "google.com"
|
||||
response = os.system("ping -c 1 " + hostname)
|
||||
response = 1
|
||||
try:
|
||||
response = os.system("ping -c 1 " + hostname + " > /dev/null 2>&1")
|
||||
except Exception as e:
|
||||
print("Something went wrong in ping: {}".format(e))
|
||||
|
||||
|
||||
#and then check the response...
|
||||
if response == 0:
|
||||
@@ -297,3 +316,15 @@ class start(threading.Thread, deviceBase):
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def tenflowmeterskid_ignorechannel(self, name, value):
|
||||
if value not in PERSIST["ignore_list"]:
|
||||
PERSIST["ignore_list"].append(value)
|
||||
persistence.store(PERSIST)
|
||||
return True
|
||||
|
||||
def tenflowmeterskid_observechannel(self, name, value):
|
||||
if value in PERSIST["ignore_list"]:
|
||||
PERSIST["ignore_list"].remove(value)
|
||||
persistence.store(PERSIST)
|
||||
return True
|
||||
@@ -1,19 +1,31 @@
|
||||
"""Utility functions for the driver."""
|
||||
import socket
|
||||
import struct
|
||||
import urllib
|
||||
import contextlib
|
||||
|
||||
|
||||
def get_public_ip_address():
|
||||
"""Find the public IP Address of the host device."""
|
||||
def get_private_ip_address():
|
||||
"""Find the private IP Address of the host device."""
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
try:
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
sock.connect(("8.8.8.8", 80))
|
||||
ip_address = sock.getsockname()[0]
|
||||
sock.close()
|
||||
except Exception as e:
|
||||
return e
|
||||
ip_address = sock.getsockname()[0]
|
||||
sock.close()
|
||||
return ip_address
|
||||
|
||||
def get_public_ip_address():
|
||||
ip_address = "0.0.0.0"
|
||||
try:
|
||||
with contextlib.closing(urllib.urlopen("http://checkip.amazonaws.com")) as url:
|
||||
ip_address = url.read()
|
||||
except Exception as e:
|
||||
print("could not resolve check IP: {}".format(e))
|
||||
return ip_address
|
||||
return ip_address[:-1]
|
||||
|
||||
|
||||
|
||||
def int_to_float16(int_to_convert):
|
||||
"""Convert integer into float16 representation."""
|
||||
|
||||
Reference in New Issue
Block a user