updated configs

This commit is contained in:
Nico Melone
2022-03-09 15:34:08 -06:00
parent 4fcc83760d
commit 9b3296a04b
19 changed files with 521 additions and 49 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
advvfdipp/.DS_Store vendored Normal file

Binary file not shown.

BIN
dualactuator/.DS_Store vendored Normal file

Binary file not shown.

BIN
flow-monitor/.DS_Store vendored Normal file

Binary file not shown.

BIN
plcfreshwater/.DS_Store vendored Normal file

Binary file not shown.

View File

@@ -8,7 +8,7 @@
"file4": "Tags.py"
},
"deviceName": "plcfreshwater",
"releaseVersion": "14",
"releaseVersion": "16",
"driverFileName": "plcfreshwater.py",
"driverId": "0100"
}

View File

@@ -1,4 +1,5 @@
"""Driver for plcfreshwater"""
import logging
import threading
import json
import time
@@ -53,7 +54,7 @@ class start(threading.Thread, deviceBase):
mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "14"
self.version = "16"
self.finished = threading.Event()
self.force_send = False
self.public_ip_address = ""
@@ -81,7 +82,7 @@ class start(threading.Thread, deviceBase):
print("plcfreshwater driver will start in {} seconds".format(WAIT_FOR_CONNECTION_SECONDS - i))
time.sleep(1)
global TOPIC_MAC, PLC_IP_ADDRESS, log, write_tag, PERSIST
global TOPIC_MAC, PLC_IP_ADDRESS, log, write_tag, read_tag, PERSIST
TOPIC_MAC = self.mac
@@ -204,14 +205,17 @@ class start(threading.Thread, deviceBase):
self.totals_counter = 0
if self.totals_counter >= 3:
self.fix_totals()
log.info("Would've run fix_totals!!!!")
self.totals_counter = 0
def fix_totals(self):
Daily_Holding = PERSIST["Daily Holding"] - PERSIST["Monthly Holding"]
resp = write_tag(self.plcip, "Lifetime_Flow_Meter_Gal", PERSIST["Lifetime"] - PERSIST["Monthly Holding"], plc_type="Micro800")
new_lifetime = PERSIST["Lifetime"] - PERSIST["Monthly Holding"]
resp = write_tag(self.plcip, "Lifetime_Flow_Meter_Gal", new_lifetime, plc_type="Micro800")
if resp == True:
PERSIST["Daily Holding"] = Daily_Holding
PERSIST["Monthly Holding"] = 0.0
PERSIST["Lifetime"] = new_lifetime
persistence.store(PERSIST, 'totalizers_{}.json'.format(self.mac))
log.info("RESETTING TOTALIZERS!!!")
@@ -254,7 +258,6 @@ class start(threading.Thread, deviceBase):
try:
if val - PERSIST["Lifetime"] > 0:
self.totalizing = True
PERSIST['Lifetime'] = val
else:
self.totalizing = False
except:

View File

@@ -2,7 +2,7 @@
"driverFileName": "plcpond.py",
"deviceName": "plcpond",
"driverId": "0220",
"releaseVersion": "5",
"releaseVersion": "7",
"files": {
"file1": "plcpond.py",
"file2": "utilities.py",

View File

@@ -8,7 +8,8 @@ import logging
from random import randint
from device_base import deviceBase
from Channel import PLCChannel, read_tag, write_tag, TAG_DATAERROR_SLEEPTIME
from utilities import get_public_ip_address
from utilities import get_public_ip_address, get_private_ip_address
from datetime import datetime as dt
import persistence
_ = None
@@ -42,6 +43,22 @@ if not PERSIST:
}
persistence.store(PERSIST, 'persist.json')
TOTALIZER = persistence.load('totalizers.json')
if not TOTALIZER:
TOTALIZER = {
'Todays': 0,
'Yesterdays': 0,
'Current Months': 0,
'Previous Months': 0,
'Monthly Holding': 0,
'Daily Holding': 0,
'Lifetime': 0,
'Day': 0,
'Month': 0,
'Last Report': 0
}
persistence.store(TOTALIZER, 'totalizers.json')
CHANNELS = [
PLCChannel(PLC_IP_ADDRESS, "cfgnumberofponds", "cfgNumberOfPonds", "REAL", 0.5, 3600, map_=False, write_enabled=False, plc_type='Micro800'),
PLCChannel(PLC_IP_ADDRESS, "pond1height", "pond1Height", "REAL", 5.0, 3600, map_=False, write_enabled=False, plc_type='Micro800'),
@@ -60,10 +77,10 @@ if PERSIST['flowmeter_enable']:
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'totalizer_1', 'Val_FlowMeterT1', 'REAL', 1000, 3600, plc_type='Micro800'))
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'totalizer_2', 'Val_FlowMeterT2', 'REAL', 1000, 3600, plc_type='Micro800'))
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'totalizer_3', 'Val_FlowMeterT3', 'REAL', 1000, 3600, plc_type='Micro800'))
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'today_flow', 'Val_FlowMeterToday', 'REAL', 1000, 3600, plc_type='Micro800'))
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'yesterday_flow', 'Val_FlowMeterYesterday', 'REAL', 1000, 3600, plc_type='Micro800'))
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'current_month_flow', 'Val_FlowMeterMonth', 'REAL', 1000, 3600, plc_type='Micro800'))
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'prev_month_flow', 'Val_FlowMeterLastMonth ', 'REAL', 1000, 3600, plc_type='Micro800'))
#CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'today_flow', 'Val_FlowMeterToday', 'REAL', 1000, 3600, plc_type='Micro800'))
#CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'yesterday_flow', 'Val_FlowMeterYesterday', 'REAL', 1000, 3600, plc_type='Micro800'))
#CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'current_month_flow', 'Val_FlowMeterMonth', 'REAL', 1000, 3600, plc_type='Micro800'))
#CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'prev_month_flow', 'Val_FlowMeterLastMonth ', 'REAL', 1000, 3600, plc_type='Micro800'))
CALIBRATION_TABLES = [[],[], [], [], []] # position 0 is a dummy table
@@ -79,7 +96,7 @@ class start(threading.Thread, deviceBase):
deviceBase.__init__(self, name=name, number=number, mac=mac, Q=Q, mcu=mcu, companyId=companyId, offset=offset, mqtt=mqtt, Nodes=Nodes)
self.daemon = True
self.version = "5"
self.version = "7"
self.finished = threading.Event()
self.force_send = False
threading.Thread.start(self)
@@ -101,6 +118,8 @@ class start(threading.Thread, deviceBase):
public_ip_address = get_public_ip_address()
self.sendtodbDev(1, 'public_ip_address', public_ip_address, 0, 'plcpond')
private_ip_address = get_private_ip_address()
self.sendtodbDev(1, 'private_ip_address', private_ip_address, 0, 'plcpond')
watchdog = self.plcpond_watchdog()
self.sendtodbDev(1, 'watchdog', watchdog, 0, 'plcpond')
watchdog_send_timestamp = time.time()
@@ -111,40 +130,45 @@ class start(threading.Thread, deviceBase):
watchdog_loops = 0
watchdog_check_after = 5000
while True:
if self.force_send:
logger.warning("FORCE SEND: TRUE")
try:
if self.force_send:
logger.warning("FORCE SEND: TRUE")
for c in CHANNELS:
v = c.read()
if v is not None: # read returns None if it fails
if c.check(v, self.force_send):
self.sendtodbDev(1, c.mesh_name, c.value, 0, 'plcpond')
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
for c in CHANNELS:
v = c.read()
if v is not None: # read returns None if it fails
if c.mesh_name in ["totalizer_1"]:
self.totalize(v)
if c.check(v, self.force_send):
self.sendtodbDev(1, c.mesh_name, c.value, 0, 'plcpond')
#time.sleep(TAG_DATAERROR_SLEEPTIME) # sleep to allow Micro800 to handle ENET requests
for pond_index in range(1, 5):
self.read_pond_calibration(pond_index)
for pond_index in range(1, 5):
self.read_pond_calibration(pond_index)
# print("plcpond driver still alive...")
if self.force_send:
if send_loops > 2:
logger.warning("Turning off force_send")
self.force_send = False
send_loops = 0
else:
send_loops += 1
# print("plcpond driver still alive...")
if self.force_send:
if send_loops > 2:
logger.warning("Turning off force_send")
self.force_send = False
send_loops = 0
else:
send_loops += 1
watchdog_loops += 1
if watchdog_loops >= watchdog_check_after:
test_watchdog = self.plcpond_watchdog()
if not test_watchdog == watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD:
self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'plcpond')
watchdog = test_watchdog
watchdog_loops += 1
if watchdog_loops >= watchdog_check_after:
test_watchdog = self.plcpond_watchdog()
if not test_watchdog == watchdog or (time.time() - watchdog_send_timestamp) > WATCHDOG_SEND_PERIOD:
self.sendtodbDev(1, 'watchdog', test_watchdog, 0, 'plcpond')
watchdog = test_watchdog
test_public_ip = get_public_ip_address()
if not test_public_ip == public_ip_address:
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'plcpond')
public_ip_address = test_public_ip
watchdog_loops = 0
test_public_ip = get_public_ip_address()
if not test_public_ip == public_ip_address:
self.sendtodbDev(1, 'public_ip_address', test_public_ip, 0, 'plcpond')
public_ip_address = test_public_ip
watchdog_loops = 0
except Exception as e:
logger.error("Something went wrong in read: {}".format(e))
def read_pond_calibration(self, pond_number):
@@ -260,3 +284,73 @@ class start(threading.Thread, deviceBase):
if w is None:
w = "Error writing to PLC..."
return w
def totalize(self, val):
right_now = dt.today()
month = right_now.month
day = right_now.day
#Totalize Today, Yesterday, Month, Last Month
#if the stored day is 0 then it's a fresh run of this should initalize values now
if TOTALIZER['Day'] == 0:
TOTALIZER['Day'] = day
TOTALIZER['Month'] = month
TOTALIZER['Daily Holding'] = val
TOTALIZER['Monthly Holding'] = val
persistence.store(TOTALIZER, 'totalizers.json')
#Communication error during initialization check if lifetime has reported properly and update holdings
if TOTALIZER['Daily Holding'] == None and not(val == None):
TOTALIZER['Daily Holding'] = val
TOTALIZER['Monthly Holding'] = val
try:
if val - TOTALIZER['Daily Holding'] - TOTALIZER['Todays'] > 500 or time.time() - TOTALIZER['Last Report'] > 3600 or self.force_send:
TOTALIZER['Todays'] = val - TOTALIZER['Daily Holding']
TOTALIZER['Current Months'] = val - TOTALIZER['Monthly Holding']
TOTALIZER['Lifetime'] = val
self.sendtodbDev(1, 'today_flow', TOTALIZER['Todays'], 0, 'plcpond')
self.sendtodbDev(1, 'current_month_flow', TOTALIZER['Current Months'], 0, 'plcpond')
self.sendtodbDev(1, 'yesterday_flow', TOTALIZER['Yesterdays'], 0, 'plcpond')
if self.force_send:
self.sendtodbDev(1, 'prev_month_flow', TOTALIZER['Previous Months'], 0, 'plcpond')
TOTALIZER['Last Report'] = time.time()
except:
if time.time() - TOTALIZER['Last Report'] > 3600 or self.force_send:
self.sendtodbDev(1, 'today_flow', TOTALIZER['Todays'], 0, 'plcpond')
self.sendtodbDev(1, 'current_month_flow', TOTALIZER['Current Months'], 0, 'plcpond')
self.sendtodbDev(1, 'yesterday_flow', TOTALIZER['Yesterdays'], 0, 'plcpond')
if self.force_send:
self.sendtodbDev(1, 'prev_month_flow', TOTALIZER['Previous Months'], 0, 'plcpond')
TOTALIZER['Last Report'] = time.time()
#If the current day doesn't equal the stored day roll the dailies over
if not(day == TOTALIZER['Day']):
#if a comms error use the stored values else use the latested values
if val == None:
TOTALIZER['Yesterdays'] = TOTALIZER['Todays']
TOTALIZER['Todays'] = 0
TOTALIZER['Daily Holding'] = TOTALIZER['Lifetime']
else:
TOTALIZER['Yesterdays'] = val - TOTALIZER['Daily Holding']
TOTALIZER['Todays'] = 0
TOTALIZER['Daily Holding'] = val
TOTALIZER['Lifetime'] = val
TOTALIZER['Day'] = day
self.sendtodbDev(1, 'today_flow', TOTALIZER['Todays'], 0, 'plcpond')
self.sendtodbDev(1, 'yesterday_flow', TOTALIZER['Yesterdays'], 0, 'plcpond')
TOTALIZER['Last Report'] = time.time()
#the day has rolled over if the month also rolls over
if not(month == TOTALIZER['Month']):
#if a comms error use the stored values else use the latested values
if val == None:
TOTALIZER['Previous Months'] = TOTALIZER['Current Months']
TOTALIZER['Current Months'] = 0
TOTALIZER['Monthly Holding'] = TOTALIZER['Lifetime']
else:
TOTALIZER['Previous Months'] = val - TOTALIZER['Monthly Holding']
TOTALIZER['Current Months'] = 0
TOTALIZER['Monthly Holding'] = val
TOTALIZER['Month'] = month
self.sendtodbDev(1, 'current_month_flow', TOTALIZER['Current Months'], 0, 'plcpond')
self.sendtodbDev(1, 'prev_month_flow', TOTALIZER['Previous Months'], 0, 'plcpond')
TOTALIZER['Last Report'] = time.time()
persistence.store(TOTALIZER, 'totalizers.json')

View File

@@ -1,16 +1,30 @@
"""Utility functions for the driver."""
import socket
import struct
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():
"""Find the public IP Address of the host device."""
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
ip = s.getsockname()[0]
s.close()
return ip
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
promagmbs/.DS_Store vendored Normal file

Binary file not shown.

Binary file not shown.

View File

@@ -5,7 +5,7 @@
"file1": "promagmbs.py"
},
"deviceName": "promagmbs",
"driverId": "0190",
"driverId": "0199",
"releaseVersion": "4",
"driverFileName": "promagmbs.py"
}

360
promagmbs/device_base.py Normal file
View File

@@ -0,0 +1,360 @@
import types
import traceback
import binascii
import threading
import time
import thread
import os
import struct
import sys
import textwrap
import Queue
import json
class deviceBase():
def __init__(self, name=None, number=None, mac=None, Q=None, mcu=None, companyId=None, offset=None, mqtt=None, Nodes=None):
self.offset = offset
self.company = companyId
self.name = name
self.number = number
self.q = Q
self.deviceName = name + '_[' + mac + ':' + number[0:2] + ':' + number[2:] + ']!'
self.chName = "M1" + '_[' + mac + ':'
self.chName2 = '_[' + mac + ':'
print 'device name is:'
print self.deviceName
mac2 = mac.replace(":", "")
self.mac = mac2.upper()
self.address = 1
self.debug = True
self.mcu = mcu
self.firstRun = True
self.mqtt = mqtt
self.nodes = Nodes
#local dictionary of derived nodes ex: localNodes[tank_0199] = self
self.localNodes = {}
os.system("chmod 777 /root/reboot")
os.system("echo nameserver 8.8.8.8 > /etc/resolv.conf")
#Queue for imcoming sets
self.loraQ = Queue.Queue()
self.knownIDs = []
thread.start_new_thread(self.getSetsThread, ())
def getSetsThread(self):
while True:
try:
item = self.loraQ.get(block=True, timeout=600)
try:
print "here is the item from the sets q"
print item
if len(item) == 2:
techname = str(json.loads(item[1])[0]['payload']['name'].split(".")[0])
channel = str(json.loads(item[1])[0]['payload']['name'].split(".")[1])
name = techname.split("_")[0]
id = techname.split("_")[1][1:-2].replace(":","").upper()
value = json.loads(item[1])[0]['payload']['value']
msgId = json.loads(item[1])[0]['msgId']
print channel, value, id, name, msgId
success = self.specificSets(channel, value, id, name)
if success == True:
print "SUCCESS ON SET"
if int(msgId) == 0:
return
lc = self.getTime()
value = str(self.mac) + " Success Setting: " + channel + " To: " + value
msg = """[ { "value":"%s", "timestamp":"%s", "msgId":"%s" } ]""" % (value, str(lc), msgId)
print value
print msg
topic = "meshify/responses/" + str(msgId)
print topic
self.q.put([topic, str(msg), 2])
else:
lc = self.getTime()
if success == False:
reason = "(Internal Gateway/Device Error)"
else:
reason = success
value = str(self.mac) + " Failed Setting: " + channel + " To: " + value + " " + reason
msg = """[ { "value":"%s", "timestamp":"%s", "msgId":"%s" } ]""" % (value, str(lc), msgId)
topic = "meshify/responses/" + msgId
self.q.put([topic, str(msg), 2])
except:
if int(msgId) == 0:
return
lc = self.getTime()
value = str(self.mac) + " Failed Setting: " + channel + " To: " + value + " (No Callback Found)"
msg = """[ { "value":"%s", "timestamp":"%s", "msgId":"%s" } ]""" % (value, str(lc), msgId)
topic = "meshify/responses/" + msgId
self.q.put([topic, str(msg), 2])
print 'no Set callback found for channel: ' + funcName
except:
print "sets queue timeout, restarting..."
def sendtodbDevLora(self, id, channel, value, timestamp, deviceName):
mac = self.mac
if deviceName == "mainMeshify":
zigmac = "_[01:00:00:00:00:" + id[0:2] + ":" + id[2:4] + ":" + id[4:6] + "]!"
else:
zigmac = "_[00:00:00:00:00:" + id[0:2] + ":" + id[2:4] + ":" + id[4:6] + "]!"
dname = deviceName + zigmac
#define dname, make id into techname and mac
if id not in self.knownIDs:
self.knownIDs.append(id)
self.mcu.xbees[dname] = self.loraQ
#meshify/db/330/C493000354FB/ilora/c493000354fb2A6E/a1-v
#[ { "value":"0.5635", "timestamp":"1486039316" } ]
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbLocLora(self, id, channel, value, timestamp, deviceName):
mac = id
while len(mac) < 12:
mac = "0" + mac
if deviceName == "mainMeshify":
zigmac = "_[01:00:00:00:00:" + id[0:2] + ":" + id[2:4] + ":" + id[4:6] + "]!"
else:
zigmac = "_[00:00:00:00:00:" + id[0:2] + ":" + id[2:4] + ":" + id[4:6] + "]!"
dname = deviceName + zigmac
#define dname, make id into techname and mac
if id not in self.knownIDs:
self.knownIDs.append(id)
topic = str(("meshify/sets/" + str(self.company) + "/" + mac + "/#"))
self.mqtt.subscribe(topic, 0)
topic = str(("meshify/sets/" + "1" + "/" + mac + "/#"))
self.mqtt.subscribe(topic, 0)
self.mcu.xbees[dname] = self.loraQ
#meshify/db/330/C493000354FB/ilora/c493000354fb2A6E/a1-v
#[ { "value":"0.5635", "timestamp":"1486039316" } ]
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbLocLoraCom(self, id, channel, value, timestamp, deviceName):
mac = "1" + id
while len(mac) < 12:
mac = "0" + mac
if deviceName == "mainMeshify":
zigmac = "_[01:00:00:00:00:" + id[0:2] + ":" + id[2:4] + ":" + id[4:6] + "]!"
else:
zigmac = "_[00:00:00:00:01:" + id[0:2] + ":" + id[2:4] + ":" + id[4:6] + "]!"
dname = deviceName + zigmac
#define dname, make id into techname and mac
if id not in self.knownIDs:
self.knownIDs.append(id)
topic = str(("meshify/sets/" + str(self.company) + "/" + mac + "/#"))
self.mqtt.subscribe(topic, 0)
topic = str(("meshify/sets/" + "1" + "/" + mac + "/#"))
self.mqtt.subscribe(topic, 0)
self.mcu.xbees[dname] = self.loraQ
#meshify/db/330/C493000354FB/ilora/c493000354fb2A6E/a1-v
#[ { "value":"0.5635", "timestamp":"1486039316" } ]
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbLoc(self, ch, channel, value, timestamp, deviceName, mac):
#this will add your derived nodes the master nodes list, allowing them to receive sets!!
localNodesName = deviceName + "_" + str(ch) + "99"
if not self.localNodes.has_key(localNodesName):
self.localNodes[localNodesName] = True
self.nodes[localNodesName] = self
#make the techname
lst = textwrap.wrap(str(mac), width=2)
tech = ""
for i in range(len(lst)):
tech += lst[i].lower() + ":"
chName2 = '_[' + tech
if int(ch) < 10:
ch = "0" + str(int(ch))
if len(ch) > 2:
ch = ch[:-2]
dname = deviceName + chName2 + str(ch) + ":98]!"
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbDevJSON(self, ch, channel, value, timestamp, deviceName):
if int(ch) < 10:
ch = "0" + str(int(ch))
dname = deviceName + self.chName2 + str(ch) + ":99]!"
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, self.mac, dname, channel)
print topic
msg = """[ { "value":%s, "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbLora(self, ch, channel, value, timestamp, deviceName):
if ":" not in ch:
ch = ch[0:2] + ":" + ch[2:4]
#this will add your derived nodes the master nodes list, allowing them to receive sets!!
localNodesName = deviceName + "_" + str(ch).replace(':', "")
if not self.localNodes.has_key(localNodesName):
self.localNodes[localNodesName] = True
self.nodes[localNodesName] = self
dname = deviceName + self.chName2 + str(ch) + "]!"
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, self.mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbDev(self, ch, channel, value, timestamp, deviceName):
#this will add your derived nodes the master nodes list, allowing them to receive sets!!
localNodesName = deviceName + "_" + str(ch) + "99"
if not self.localNodes.has_key(localNodesName):
self.localNodes[localNodesName] = True
self.nodes[localNodesName] = self
if int(ch) < 10:
ch = "0" + str(int(ch))
dname = deviceName + self.chName2 + str(ch) + ":99]!"
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, self.mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbCH(self, ch, channel, value, timestamp):
if int(ch) < 10:
ch = "0" + str(ch)
dname = self.chName + str(ch) + ":99]!"
if int(timestamp) == 0:
timestamp = self.getTime()
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, self.mac, dname, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodb(self, channel, value, timestamp):
if int(timestamp) == 0:
timestamp = self.getTime()
if timestamp < 1400499858:
return
else:
timestamp = str(int(timestamp) + int(self.offset))
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, self.mac, self.deviceName, channel)
print topic
msg = """[ { "value":"%s", "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def sendtodbJSON(self, channel, value, timestamp):
if int(timestamp) == 0:
timestamp = self.getTime()
if timestamp < 1400499858:
return
else:
timestamp = str(int(timestamp) + int(self.offset))
topic = 'meshify/db/%s/%s/%s/%s' % (self.company, self.mac, self.deviceName, channel)
print topic
msg = """[ { "value":%s, "timestamp":"%s" } ]""" % (str(value), str(timestamp))
print msg
self.q.put([topic, msg, 0])
def getTime(self):
return str(int(time.time() + int(self.offset)))

BIN
promagmbs/device_base.pyc Normal file

Binary file not shown.

0
promagmbs/promagmbs.log Normal file
View File

BIN
promagmbs/promagmbs.pyc Normal file

Binary file not shown.

BIN
promagmbs/utilities.pyc Normal file

Binary file not shown.

1
rigpump/tag.json Normal file
View File

@@ -0,0 +1 @@
{"1": {"c": "ETHERNET/IP", "b": "192.168.1.10", "addresses": {"300": {"2-2": {"ah": "", "bytary": null, "al": "", "vn": "VFD Current", "ct": "number", "le": "16", "grp": "3600", "la": 0.0, "chn": "vfd_current", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.446133, "a": "VFD_OutCurrent", "c": "1.0", "misc_u": "Amps", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-2", "mv": "0", "s": "On", "r": "0-250", "t": "int", "vm": null}, "2-3": {"ah": "", "bytary": null, "al": "", "vn": "VFD Frequency", "ct": "number", "le": "16", "grp": "3600", "la": 0.0, "chn": "vfd_frequency", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.518855, "r": "0-75", "a": "VFD_SpeedFdbk", "c": "0.5", "misc_u": "Hz", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-3", "s": "On", "mv": "0", "t": "int", "vm": null}, "2-1": {"ah": "", "bytary": null, "al": "", "vn": "Discharge Pressure", "ct": "number", "le": "16", "grp": "3600", "la": 20.0, "chn": "discharge_pressure", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.644362, "a": "val_DischargePressure", "c": "5.0", "misc_u": "PSI", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-1", "mv": "0", "s": "On", "r": "0-500", "t": "int", "vm": null}, "2-6": {"ah": "", "bytary": null, "al": "", "vn": "Discharge Pressure Setpoint", "ct": "number", "le": "16", "grp": "3600", "la": 45.0, "chn": "discharge_pressure_setpoint", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.730308, "a": "cfg_PID_DischargePressureSP", "c": "0.5", "misc_u": "PSI", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-6", "mv": "0", "s": "On", "r": "0-500", "t": "int", "vm": null}, "2-7": {"ah": "", "bytary": null, "al": "", "vn": "VFD Frequency Setpoint", "ct": "number", "le": "16", "grp": "3600", "la": 45.0, "chn": "vfd_frequency_setpoint", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.798552, "a": "cfg_PID_ManualSP", "c": "0.5", "misc_u": "Hz", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-7", "mv": "0", "s": "On", "r": "0-75", "t": "int", "vm": null}, "2-4": {"ah": "", "bytary": null, "al": "", "vn": "Device Status", "ct": "number", "le": "16", "grp": "3600", "la": 64, "chn": "device_status", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.8616178, "a": "RigPump.State", "c": "1", "misc_u": "", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-4", "mv": "0", "s": "On", "r": "0-32768", "t": "int", "vm": {"1": "Running", "128": "Overpressure", "64": "Idle", "1024": "Faulted"}}, "2-5": {"ah": "", "bytary": null, "al": "", "vn": "Flow Rate Setpoint", "ct": "number", "le": "16", "grp": "3600", "la": 55.0, "chn": "flow_rate_setpoint", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.928473, "a": "cfg_PID_FlowSP", "c": "0.1", "misc_u": "BPM", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-5", "mv": "0", "s": "On", "r": "0-5000", "t": "int", "vm": null}, "2-8": {"ah": "", "bytary": null, "al": "0", "vn": "Auto/Manual Mode", "ct": "number", "le": "16", "grp": "3600", "la": 0, "chn": "auto_manual", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910120.996027, "r": "0-1", "a": "mode_Auto", "c": "0", "misc_u": "", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-8", "s": "On", "mv": "0", "t": "int", "vm": {"1": "Auto", "0": "Manual"}}, "2-9": {"ah": "", "bytary": null, "al": "0", "vn": "Control Mode", "ct": "number", "le": "16", "grp": "3600", "la": 0, "chn": "auto_control_mode", "r": "0-1", "dn": "rigpump", "da": "300", "lrt": 1575910121.059379, "a": "controlMode", "c": "0", "misc_u": "", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-9", "mv": "0", "s": "On", "un": "1", "t": "int", "vm": {"1": "Flow", "0": "Pressure"}}, "2-10": {"ah": "", "bytary": null, "al": "", "vn": "Energy Today", "ct": "number", "le": "16", "grp": "3600", "la": 0.0, "chn": "energy_today", "un": "1", "dn": "rigpump", "vm": null, "lrt": 1575910121.126346, "da": "300", "a": "Energy_Total[0]", "c": "10", "misc_u": "kWh", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-10", "mv": "0", "s": "On", "r": "0-250", "t": "int"}, "2-11": {"ah": "", "bytary": null, "al": "", "vn": "Flow Rate", "ct": "number", "le": "16", "grp": "3600", "la": 15.0, "chn": "flow_rate", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575910121.195685, "a": "val_Flowmeter", "c": "5.0", "misc_u": "BPM", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-11", "mv": "0", "s": "On", "r": "0-50000", "t": "int", "vm": null}, "2-12": {"ah": "", "bytary": null, "al": "", "vn": "Energy Yesterday", "ct": "number", "le": "16", "grp": "3600", "la": 0, "chn": "energy_yesterday", "un": "1", "dn": "rigpump", "da": "300", "lrt": 1575909846.276182, "r": "0-250", "a": "Energy_Total[1]", "c": "10", "misc_u": "kWh", "f": "1", "mrt": "60", "m": "none", "m1ch": "2-12", "s": "On", "mv": "0", "t": "int", "vm": null}}}, "f": "Off", "p": "", "s": "1"}, "2": {"c": "M1-232", "b": "9600", "addresses": {}, "f": "Off", "p": "", "s": "1"}}