changes
This commit is contained in:
BIN
abbflow/.DS_Store
vendored
Normal file
BIN
abbflow/.DS_Store
vendored
Normal file
Binary file not shown.
BIN
advvfdipp/.DS_Store
vendored
BIN
advvfdipp/.DS_Store
vendored
Binary file not shown.
@@ -8,7 +8,7 @@
|
||||
"file4": "Tags.py"
|
||||
},
|
||||
"deviceName": "dual_flowmeter",
|
||||
"releaseVersion": "9",
|
||||
"releaseVersion": "10",
|
||||
"driverFileName": "dual_flowmeter.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
@@ -8,7 +8,7 @@ from random import randint
|
||||
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
|
||||
|
||||
# PERSISTENCE FILE
|
||||
@@ -52,10 +52,11 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "9"
|
||||
self.version = "10"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
self.private_ip_address = ""
|
||||
self.public_ip_address_last_checked = 0
|
||||
self.watchdog = False
|
||||
self.watchdog_last_checked = 0
|
||||
@@ -125,9 +126,13 @@ 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()
|
||||
test_private_ip = get_private_ip_address()
|
||||
if not test_public_ip == self.public_ip_address:
|
||||
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'dual_flowmeter')
|
||||
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, 'dual_flowmeter')
|
||||
self.private_ip_address = test_private_ip
|
||||
|
||||
def dual_flowmeter_watchdog(self):
|
||||
"""Write a random integer to the PLC and then 1 seconds later check that it has been decremented by 1."""
|
||||
|
||||
@@ -1,19 +1,29 @@
|
||||
"""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."""
|
||||
|
||||
BIN
flow-monitor/.DS_Store
vendored
BIN
flow-monitor/.DS_Store
vendored
Binary file not shown.
139
flow-monitor/inhand/flowmonitor.py
Normal file
139
flow-monitor/inhand/flowmonitor.py
Normal file
@@ -0,0 +1,139 @@
|
||||
# Enter your python code.
|
||||
import json
|
||||
from datetime import datetime as dt
|
||||
from common.Logger import logger
|
||||
from quickfaas.remotebus import publish
|
||||
import re, uuid
|
||||
from paho.mqtt import client
|
||||
|
||||
payload = {}
|
||||
|
||||
try:
|
||||
with open("/var/user/files/totalizers.json", "r") as t:
|
||||
totalizers = json.load(t)
|
||||
if not totalizers:
|
||||
logger.info("-----INITIALIZING TOTALIZERS-----")
|
||||
totalizers = {
|
||||
"day": 0,
|
||||
"month": 0,
|
||||
"lifetime": 0,
|
||||
"dayHolding": 0,
|
||||
"monthHolding": 0
|
||||
}
|
||||
except:
|
||||
totalizers = {
|
||||
"day": 0,
|
||||
"month": 0,
|
||||
"lifetime": 0,
|
||||
"dayHolding": 0,
|
||||
"monthHolding": 0
|
||||
}
|
||||
|
||||
|
||||
lwtData = {
|
||||
"init":False,
|
||||
"client": client.Client(client_id=str(uuid.uuid4()), clean_session=True, userdata=None, protocol=client.MQTTv311, transport="tcp")
|
||||
}
|
||||
def lwt(mac):
|
||||
try:
|
||||
#if not lwtData["connected"]:
|
||||
if not lwtData["init"]:
|
||||
logger.info("INITIALIZING LWT CLIENT")
|
||||
lwtData["client"].username_pw_set(username="admin", password="columbus")
|
||||
lwtData["client"].will_set("meshify/db/194/_/mainHP/" + mac + ":00:00/connected",json.dumps([{"value":False}]))
|
||||
lwtData["init"] = True
|
||||
logger.info("Connecting to MQTT Broker for LWT purposes!!!!!!!")
|
||||
lwtData["client"].connect("mq194.imistaway.net",1883, 600)
|
||||
lwtData["client"].publish("meshify/db/194/_/mainHP/" + mac + ":00:00/connected", json.dumps([{"value":True}]))
|
||||
except Exception as e:
|
||||
logger.error("LWT DID NOT DO THE THING")
|
||||
logger.error(e)
|
||||
|
||||
|
||||
def sendData(message,wizard_api):
|
||||
logger.debug(message)
|
||||
mac = __topic__.split("/")[-1] #':'.join(re.findall('..', '%012x' % uuid.getnode()))
|
||||
lwt(mac)
|
||||
try:
|
||||
publishFlowrate( message["values"]["flowmonitor"]["flowrate"]["raw_data"], message["values"]["flowmonitor"]["flow_unit"]["raw_data"])
|
||||
totalizeDay(message["values"]["flowmonitor"]["totalizer_1"]["raw_data"],message["values"]["flowmonitor"]["totalizer_1_unit"]["raw_data"])
|
||||
totalizeMonth(message["values"]["flowmonitor"]["totalizer_1"]["raw_data"],message["values"]["flowmonitor"]["totalizer_1_unit"]["raw_data"])
|
||||
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
def saveTotalizers():
|
||||
try:
|
||||
with open("/var/user/files/totalizers.json", "w") as t:
|
||||
json.dump(totalizers,t)
|
||||
except Exception as e:
|
||||
logger.error(e)
|
||||
|
||||
|
||||
def publishFlowrate(fr, unit):
|
||||
if unit == 45:
|
||||
publish(__topic__ + ":01:40/" + "gpm_flow", json.dumps([{"value": f"{fr}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bpd_flow", json.dumps([{"value": f"{fr*((60*24)/42)}"}]),__qos__)
|
||||
elif unit == 63:
|
||||
publish(__topic__ + ":01:40/" + "bpd_flow", json.dumps([{"value": f"{fr}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gpm_flow", json.dumps([{"value": f"{fr * (42/(24*60))}"}]),__qos__)
|
||||
|
||||
|
||||
def totalizeDay(lifetime,unit):
|
||||
now = dt.now()
|
||||
reset = False
|
||||
value = lifetime - totalizers["dayHolding"]
|
||||
if not int(now.strftime("%d")) == int(totalizers["day"]):
|
||||
totalizers["dayHolding"] = lifetime
|
||||
totalizers["day"] = int(now.strftime("%d"))
|
||||
saveTotalizers()
|
||||
reset = True
|
||||
if unit == 11:
|
||||
publish(__topic__ + ":01:40/" + "gal_total", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total", json.dumps([{"value": f"{value/42}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "lifetime_flow_meter_gal", json.dumps([{"value": f"{lifetime}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "lifetime_flow_meter_bbls", json.dumps([{"value": f"{lifetime/42}"}]),__qos__)
|
||||
if reset:
|
||||
publish(__topic__ + ":01:40/" + "gal_total", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total_yesterday", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_yesterday", json.dumps([{"value": f"{value/42}"}]),__qos__)
|
||||
elif unit == 15:
|
||||
publish(__topic__ + ":01:40/" + "bbl_total", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total", json.dumps([{"value": f"{value*42}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "lifetime_flow_meter_bbls", json.dumps([{"value": f"{lifetime}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "lifetime_flow_meter_gal", json.dumps([{"value": f"{lifetime*42}"}]),__qos__)
|
||||
if reset:
|
||||
publish(__topic__ + ":01:40/" + "bbl_total", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_yesterday", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total_yesterday", json.dumps([{"value": f"{value*42}"}]),__qos__)
|
||||
|
||||
|
||||
|
||||
def totalizeMonth(lifetime, unit):
|
||||
now = dt.now()
|
||||
reset = False
|
||||
value = lifetime - totalizers["monthHolding"]
|
||||
if not int(now.strftime("%m")) == int(totalizers["month"]):
|
||||
totalizers["monthHolding"] = lifetime
|
||||
totalizers["month"] = now.strftime("%m")
|
||||
saveTotalizers()
|
||||
reset = True
|
||||
if unit == 11:
|
||||
publish(__topic__ + ":01:40/" + "gal_total_thismonth", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_thismonth", json.dumps([{"value": f"{value/42}"}]),__qos__)
|
||||
if reset:
|
||||
publish(__topic__ + ":01:40/" + "gal_total_thismonth", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_thismonth", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total_lastmonth", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_lastmonth", json.dumps([{"value": f"{value/42}"}]),__qos__)
|
||||
elif unit == 15:
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_thismonth", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total_thismonth", json.dumps([{"value": f"{value*42}"}]),__qos__)
|
||||
if reset:
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_thismonth", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total_thismonth", json.dumps([{"value": f"{0}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "bbl_total_lastmonth", json.dumps([{"value": f"{value}"}]),__qos__)
|
||||
publish(__topic__ + ":01:40/" + "gal_total_lastmonth", json.dumps([{"value": f"{value*42}"}]),__qos__)
|
||||
BIN
plcfreshwater/.DS_Store
vendored
BIN
plcfreshwater/.DS_Store
vendored
Binary file not shown.
BIN
promagmbs/.DS_Store
vendored
BIN
promagmbs/.DS_Store
vendored
Binary file not shown.
@@ -60,6 +60,7 @@ class start(threading.Thread, deviceBase):
|
||||
self.public_ip_address = ""
|
||||
self.public_ip_address_last_checked = 0
|
||||
self.private_ip_address = ""
|
||||
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
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"file4": "Tags.py"
|
||||
},
|
||||
"deviceName": "tankalarms",
|
||||
"releaseVersion": "1",
|
||||
"releaseVersion": "3",
|
||||
"driverFileName": "tankalarms.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
@@ -40,7 +40,7 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "1"
|
||||
self.version = "3"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
@@ -151,11 +151,10 @@ class start(threading.Thread, deviceBase):
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
return False
|
||||
"""
|
||||
|
||||
def tankalarms_water_hihi_spt(self, name, value):
|
||||
log.info("Value received is {}".format(value))
|
||||
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "WaterTx_HHSP", 1, plc_type="Micro800")
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "WaterTx_HHSP", float(value), plc_type="Micro800")
|
||||
log.info("Result of tankalarms_water_hihi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
@@ -164,31 +163,27 @@ class start(threading.Thread, deviceBase):
|
||||
|
||||
def tankalarms_water_hi_spt(self, name, value):
|
||||
log.info("Value received is {}".format(value))
|
||||
if value == 1 or value == "1":
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "WaterTx_HSP", 1, plc_type="Micro800")
|
||||
log.info("Result of tankalarms_water_hi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
return False
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "WaterTx_HSP", float(value), plc_type="Micro800")
|
||||
log.info("Result of tankalarms_water_hi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
def tankalarms_oil_hihi_spt(self, name, value):
|
||||
log.info("Value received is {}".format(value))
|
||||
if value == 1 or value == "1":
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "OilTx_HHSP", 1, plc_type="Micro800")
|
||||
log.info("Result of tankalarms_oil_hihi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
return False
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "OilTx_HHSP", float(value), plc_type="Micro800")
|
||||
log.info("Result of tankalarms_oil_hihi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
|
||||
def tankalarms_oil_hi_spt(self, name, value):
|
||||
log.info("Value received is {}".format(value))
|
||||
if value == 1 or value == "1":
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "OilTx_HSP", 1, plc_type="Micro800")
|
||||
log.info("Result of tankalarms_oil_hi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
return False
|
||||
"""
|
||||
write_res = write_tag(str(PLC_IP_ADDRESS), "OilTx_HSP", float(value), plc_type="Micro800")
|
||||
log.info("Result of tankalarms_oil_hi_spt {}, {}, {}".format(name, value, write_res))
|
||||
if write_res is None:
|
||||
write_res = "Error writing to PLC..."
|
||||
return write_res
|
||||
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
"file4": "Tags.py"
|
||||
},
|
||||
"deviceName": "tenflowmeterskid",
|
||||
"releaseVersion": "4",
|
||||
"releaseVersion": "5",
|
||||
"driverFileName": "tenflowmeterskid.py",
|
||||
"driverId": "0100"
|
||||
}
|
||||
@@ -64,7 +64,7 @@ class start(threading.Thread, deviceBase):
|
||||
mqtt=mqtt, Nodes=Nodes)
|
||||
|
||||
self.daemon = True
|
||||
self.version = "4"
|
||||
self.version = "5"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
self.public_ip_address = ""
|
||||
@@ -100,23 +100,27 @@ class start(threading.Thread, deviceBase):
|
||||
log.warning("FORCE SEND: TRUE")
|
||||
|
||||
for chan in CHANNELS:
|
||||
val = chan.read()
|
||||
if chan.mesh_name == "total_in_flowrate":
|
||||
val = sum(self.flowrates)
|
||||
if chan.check(val, self.force_send) or self.check_new_day(chan.mesh_name[:-9]):
|
||||
if chan.mesh_name in PERSIST["ignore_list"]:
|
||||
if "lifetime" in chan.mesh_name and chan.mesh_name not in ['forward_out_lifetime', 'reverse_out_lifetime', 'net_out_lifetime']:
|
||||
self.totalizer_null(chan.mesh_name[:-9])
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, None, 0, 'tenflowmeterskid')
|
||||
try:
|
||||
val = chan.read()
|
||||
if chan.mesh_name == "total_in_flowrate":
|
||||
val = sum(self.flowrates)
|
||||
if chan.check(val, self.force_send) or self.check_new_day(chan.mesh_name[:-9]):
|
||||
if chan.mesh_name in PERSIST["ignore_list"]:
|
||||
if "lifetime" in chan.mesh_name and chan.mesh_name not in ['forward_out_lifetime', 'reverse_out_lifetime', 'net_out_lifetime']:
|
||||
self.totalizer_null(chan.mesh_name[:-9])
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, None, 0, 'tenflowmeterskid')
|
||||
|
||||
elif "lifetime" in chan.mesh_name and chan.mesh_name not in ['forward_out_lifetime', 'reverse_out_lifetime', 'net_out_lifetime']:
|
||||
self.totalize(val, chan.mesh_name[:-9])
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'tenflowmeterskid')
|
||||
if "flowrate" in chan.mesh_name and chan.mesh_name not in ["total_in_flowrate","total_out_flowrate"]:
|
||||
self.flowrates[int(chan.mesh_name.split("_")[0][2:]) - 1] = val
|
||||
except Exception as e:
|
||||
log.error("Error in reading {}".format(chan.mesh_name))
|
||||
log.error(e)
|
||||
|
||||
elif "lifetime" in chan.mesh_name and chan.mesh_name not in ['forward_out_lifetime', 'reverse_out_lifetime', 'net_out_lifetime']:
|
||||
self.totalize(val, chan.mesh_name[:-9])
|
||||
else:
|
||||
self.sendtodbDev(1, chan.mesh_name, chan.value, 0, 'tenflowmeterskid')
|
||||
if "flowrate" in chan.mesh_name and chan.mesh_name not in ["total_in_flowrate","total_out_flowrate"]:
|
||||
self.flowrates[int(chan.mesh_name.split("_")[0][2:]) - 1] = val
|
||||
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
|
||||
|
||||
for pond_index in range(1, 3):
|
||||
self.read_pond_calibration(pond_index)
|
||||
@@ -133,6 +137,7 @@ class start(threading.Thread, deviceBase):
|
||||
|
||||
if (now - self.public_ip_address_last_checked) > IP_CHECK_PERIOD:
|
||||
self._check_ip_address()
|
||||
time.sleep(5) # sleep to allow Micro800 to handle ENET requests
|
||||
|
||||
def check_new_day(self, totalizer):
|
||||
right_now = dt.today()
|
||||
|
||||
Reference in New Issue
Block a user