new channels for piflow/plcpond
This commit is contained in:
@@ -2,11 +2,12 @@
|
||||
"driverFileName": "plcpond.py",
|
||||
"deviceName": "plcpond",
|
||||
"driverId": "0220",
|
||||
"releaseVersion": "3",
|
||||
"releaseVersion": "4",
|
||||
"files": {
|
||||
"file1": "plcpond.py",
|
||||
"file2": "utilities.py",
|
||||
"file3": "Channel.py",
|
||||
"file4": "file_logger.py"
|
||||
"file4": "file_logger.py",
|
||||
"file5": "persistence.py"
|
||||
}
|
||||
}
|
||||
21
plcpond/persistence.py
Normal file
21
plcpond/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
|
||||
@@ -9,7 +9,7 @@ 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
|
||||
|
||||
import persistence
|
||||
|
||||
_ = None
|
||||
|
||||
@@ -34,22 +34,37 @@ logger.info("plcpond startup")
|
||||
# GLOBAL VARIABLES
|
||||
WATCHDOG_SEND_PERIOD = 3600 # Seconds, the longest amount of time before sending the watchdog status
|
||||
PLC_IP_ADDRESS = "192.168.1.12"
|
||||
|
||||
PERSIST = persistence.load('persist.json')
|
||||
if not PERSIST:
|
||||
PERSIST = {
|
||||
'flowmeter_enable': False
|
||||
}
|
||||
persistence.store(PERSIST, 'persist.json')
|
||||
|
||||
CHANNELS = [
|
||||
PLCChannel(PLC_IP_ADDRESS, "cfgnumberofponds", "cfgNumberOfPonds", "REAL", 0.5, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond1height", "pond1Height", "REAL", 1.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond2height", "pond2Height", "REAL", 1.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond3height", "pond3Height", "REAL", 1.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond4height", "pond4Height", "REAL", 1.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond1volume", "pond1Volume", "REAL", 500.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond2volume", "pond2Volume", "REAL", 500.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond3volume", "pond3Volume", "REAL", 500.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond4volume", "pond4Volume", "REAL", 500.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
|
||||
PLCChannel(PLC_IP_ADDRESS, "pondvolumetotal", "pondVolumeTotal", "REAL", 1000.0, 600, map_=False, write_enabled=False, plc_type='Micro800')
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond1volume", "pond1Volume", "REAL", 10000.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond2volume", "pond2Volume", "REAL", 10000.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond3volume", "pond3Volume", "REAL", 10000.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pond4volume", "pond4Volume", "REAL", 10000.0, 600, map_=False, write_enabled=False, plc_type='Micro800'),
|
||||
PLCChannel(PLC_IP_ADDRESS, "pondvolumetotal", "pondVolumeTotal", "REAL", 200000.0, 600, map_=False, write_enabled=False, plc_type='Micro800')
|
||||
]
|
||||
|
||||
if PERSIST['flowmeter_enable']:
|
||||
CHANNELS.append(PLCChannel(PLC_IP_ADDRESS, 'volume_flow', 'Val_FlowMeterFR', 'REAL', 500, 3600, plc_type='Micro800'))
|
||||
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'))
|
||||
|
||||
CALIBRATION_TABLES = [[],[], [], [], []] # position 0 is a dummy table
|
||||
|
||||
|
||||
@@ -64,7 +79,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 = "3"
|
||||
self.version = "4"
|
||||
self.finished = threading.Event()
|
||||
self.force_send = False
|
||||
threading.Thread.start(self)
|
||||
|
||||
Reference in New Issue
Block a user