More Meshify Scheduler fixes
This commit is contained in:
11818
Advanced_VFD_IPP_L19.ACD
11818
Advanced_VFD_IPP_L19.ACD
File diff suppressed because one or more lines are too long
@@ -131,7 +131,6 @@ class Channel:
|
|||||||
elif force_send:
|
elif force_send:
|
||||||
send_needed = True
|
send_needed = True
|
||||||
send_reason = "forced"
|
send_reason = "forced"
|
||||||
|
|
||||||
if send_needed:
|
if send_needed:
|
||||||
self.last_value = self.value
|
self.last_value = self.value
|
||||||
if self.map_:
|
if self.map_:
|
||||||
@@ -143,5 +142,5 @@ class Channel:
|
|||||||
else:
|
else:
|
||||||
self.value = v[0]
|
self.value = v[0]
|
||||||
self.last_send_time = time.time()
|
self.last_send_time = time.time()
|
||||||
# print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
print("Sending {} for {} - {}".format(self.value, self.mesh_name, send_reason))
|
||||||
return send_needed
|
return send_needed
|
||||||
|
|||||||
@@ -2,3 +2,14 @@
|
|||||||
data-channelId="<%= channels["advvfdipp.log"].channelId %>"
|
data-channelId="<%= channels["advvfdipp.log"].channelId %>"
|
||||||
class="data-table btn-block btn btn-theme animated"
|
class="data-table btn-block btn btn-theme animated"
|
||||||
title="Device Log"><i style='margin-left: 0.5em; cursor: pointer' class="fa fa-th-list icon-theme"></i> Device Log</a>
|
title="Device Log"><i style='margin-left: 0.5em; cursor: pointer' class="fa fa-th-list icon-theme"></i> Device Log</a>
|
||||||
|
|
||||||
|
<a href="#"
|
||||||
|
data-refreshpause="1"
|
||||||
|
data-staticsend="1"
|
||||||
|
data-channelId="<%= channels["advvfdipp.sync"].channelId %>"
|
||||||
|
data-techname="<%=channels["advvfdipp.sync"].techName %>"
|
||||||
|
data-name="<%= channels["advvfdipp.sync"].name%>"
|
||||||
|
data-nodechannelcurrentId="<%= channels["advvfdipp.sync"].nodechannelcurrentId %>"
|
||||||
|
id="<%= channels["advvfdipp.sync"].channelId %>"
|
||||||
|
class="btn btn-large btn-block btn-theme animated setstatic mqtt">
|
||||||
|
<i class="icon-repeat icon-white mqtt" ></i>Sync All Data</a>
|
||||||
|
|||||||
@@ -7,37 +7,42 @@ _ = None
|
|||||||
plc_ip_address = "10.20.4.36"
|
plc_ip_address = "10.20.4.36"
|
||||||
|
|
||||||
|
|
||||||
class ScheduleHistoryRun:
|
class ScheduleRun:
|
||||||
"""Hold config for a schedule history run."""
|
"""Hold config for a schedule history run."""
|
||||||
|
|
||||||
def __init__(self, index_):
|
def __init__(self, index_, type_="Schedule"):
|
||||||
"""Initialize the class."""
|
"""Initialize the class."""
|
||||||
self.index_ = index_
|
self.index_ = index_
|
||||||
self.json = False
|
self.json = False
|
||||||
|
if type_ in ["Schedule", "History"]:
|
||||||
|
self.type_ = type_
|
||||||
|
else:
|
||||||
|
self.type_ = "Schedule"
|
||||||
|
print("SERIOUS ERROR! {} IS NOT A VALID TYPE FOR ScheduleRun with Index = {}".format(type_, index_))
|
||||||
self.channels = [
|
self.channels = [
|
||||||
Channel(plc_ip_address, "sch_hist_id{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_id{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].id".format(self.index_), "DINT", 0.5, 3600),
|
"sch_Run{}[{}].id".format(self.type_, self.index_), "DINT", 0.5, 3600),
|
||||||
Channel(plc_ip_address, "sch_hist_controlmode{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_controlmode{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].controlmode".format(self.index_), "STRING", _, 3600, map_=maps['pid_controlmode']),
|
"sch_Run{}[{}].controlmode".format(self.type_, self.index_), "STRING", _, 3600, map_=maps['pid_controlmode']),
|
||||||
Channel(plc_ip_address, "sch_hist_controlsp{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_controlsp{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].controlSetpoint".format(self.index_), "REAL", 0.5, 3600),
|
"sch_Run{}[{}].controlSetpoint".format(self.type_, self.index_), "REAL", 0.5, 3600),
|
||||||
Channel(plc_ip_address, "sch_hist_complparam{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_complparam{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].completionParameter".format(self.index_), "STRING", _, 3600, map_=maps['completion_parameter']),
|
"sch_Run{}[{}].completionParameter".format(self.type_, self.index_), "STRING", _, 3600, map_=maps['completion_parameter']),
|
||||||
Channel(plc_ip_address, "sch_hist_complcomp{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_complcomp{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].completionComparison".format(self.index_), "STRING", _, 3600, map_=maps['completion_comparison']),
|
"sch_Run{}[{}].completionComparison".format(self.type_, self.index_), "STRING", _, 3600, map_=maps['completion_comparison']),
|
||||||
Channel(plc_ip_address, "sch_hist_compltarget{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_compltarget{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].completionValueTarget".format(self.index_), "REAL", 0.5, 3600),
|
"sch_Run{}[{}].completionValueTarget".format(self.type_, self.index_), "REAL", 0.5, 3600),
|
||||||
Channel(plc_ip_address, "sch_hist_complactual{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_complactual{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].completionValueCurrent".format(self.index_), "REAL", 10.0, 3600),
|
"sch_Run{}[{}].completionValueCurrent".format(self.type_, self.index_), "REAL", 10.0, 3600),
|
||||||
Channel(plc_ip_address, "sch_hist_bbltotal{}".format(self.index_),
|
Channel(plc_ip_address, "sch_{}_bbltotal{}".format(self.type_, self.index_),
|
||||||
"sch_RunHistory[{}].BBLTotal".format(self.index_), "REAL", 10.0, 3600)
|
"sch_Run{}[{}].BBLTotal".format(self.type_, self.index_), "REAL", 10.0, 3600)
|
||||||
]
|
]
|
||||||
|
|
||||||
def read(self):
|
def read(self, force_send=False):
|
||||||
"""Read values of the schedule history from the PLC."""
|
"""Read values of the schedule history from the PLC."""
|
||||||
new_value = False
|
new_value = False
|
||||||
for c in self.channels:
|
for c in self.channels:
|
||||||
if c.read(force_send=False):
|
if c.read(force_send):
|
||||||
new_value = True
|
new_value = True
|
||||||
return new_value
|
return new_value
|
||||||
|
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
|
|
||||||
import threading
|
import threading
|
||||||
from device_base import deviceBase
|
from device_base import deviceBase
|
||||||
from Channel import Channel
|
from Channel import Channel, write_tag
|
||||||
from Maps import adv_vfd_ipp_map as maps
|
from Maps import adv_vfd_ipp_map as maps
|
||||||
from Scheduler import ScheduleHistoryRun
|
from Scheduler import ScheduleRun
|
||||||
import json
|
import json
|
||||||
|
import time
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open("persist.json", 'r') as persist_file:
|
with open("persist.json", 'r') as persist_file:
|
||||||
@@ -22,6 +23,15 @@ _ = None
|
|||||||
|
|
||||||
plc_ip_address = "10.20.4.36"
|
plc_ip_address = "10.20.4.36"
|
||||||
|
|
||||||
|
|
||||||
|
def reverse_map(value, map_):
|
||||||
|
"""Perform the opposite of mapping to an object."""
|
||||||
|
for x in map_:
|
||||||
|
if map_[x] == value:
|
||||||
|
return x
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
channels = [
|
channels = [
|
||||||
Channel(plc_ip_address, "flowrate", "val_Flowmeter", "REAL", 5.0, 3600),
|
Channel(plc_ip_address, "flowrate", "val_Flowmeter", "REAL", 5.0, 3600),
|
||||||
Channel(plc_ip_address, "fluidlevel", "val_FluidLevel", "REAL", 10.0, 3600),
|
Channel(plc_ip_address, "fluidlevel", "val_FluidLevel", "REAL", 10.0, 3600),
|
||||||
@@ -58,14 +68,21 @@ channels = [
|
|||||||
Channel(plc_ip_address, "temperatureshutdownlimit", "AIn_IntakeTemperature.Val_HiLim", "REAL", 0.5, 14400),
|
Channel(plc_ip_address, "temperatureshutdownlimit", "AIn_IntakeTemperature.Val_HiLim", "REAL", 0.5, 14400),
|
||||||
Channel(plc_ip_address, "temperaturestartuplimit", "AIn_IntakeTemperature.Val_LoLim", "REAL", 0.5, 14400),
|
Channel(plc_ip_address, "temperaturestartuplimit", "AIn_IntakeTemperature.Val_LoLim", "REAL", 0.5, 14400),
|
||||||
Channel(plc_ip_address, "sensorheight", "cfg_DHSensorDistToIntake", "REAL", 0.5, 14400),
|
Channel(plc_ip_address, "sensorheight", "cfg_DHSensorDistToIntake", "REAL", 0.5, 14400),
|
||||||
Channel(plc_ip_address, "sch_enabled", "sch_enabled", "BOOL", _, 3600),
|
Channel(plc_ip_address, "sch_enabled", "sch_enabled", "BOOL", _, 3600)
|
||||||
]
|
]
|
||||||
|
|
||||||
scheduler_history = [
|
scheduler_history = [
|
||||||
ScheduleHistoryRun(0), ScheduleHistoryRun(1), ScheduleHistoryRun(2),
|
ScheduleRun(0, type_="History"), ScheduleRun(1, type_="History"), ScheduleRun(2, type_="History"),
|
||||||
ScheduleHistoryRun(3), ScheduleHistoryRun(4), ScheduleHistoryRun(5),
|
ScheduleRun(3, type_="History"), ScheduleRun(4, type_="History"), ScheduleRun(5, type_="History"),
|
||||||
ScheduleHistoryRun(6), ScheduleHistoryRun(7), ScheduleHistoryRun(8),
|
ScheduleRun(6, type_="History"), ScheduleRun(7, type_="History"), ScheduleRun(8, type_="History"),
|
||||||
ScheduleHistoryRun(9)
|
ScheduleRun(9, type_="History")
|
||||||
|
]
|
||||||
|
|
||||||
|
scheduler_schedule = [
|
||||||
|
ScheduleRun(0, type_="Schedule"), ScheduleRun(1, type_="Schedule"), ScheduleRun(2, type_="Schedule"),
|
||||||
|
ScheduleRun(3, type_="Schedule"), ScheduleRun(4, type_="Schedule"), ScheduleRun(5, type_="Schedule"),
|
||||||
|
ScheduleRun(6, type_="Schedule"), ScheduleRun(7, type_="Schedule"), ScheduleRun(8, type_="Schedule"),
|
||||||
|
ScheduleRun(9, type_="Schedule")
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
@@ -87,11 +104,17 @@ class start(threading.Thread, deviceBase):
|
|||||||
# about your device so it can be seen on the web
|
# about your device so it can be seen on the web
|
||||||
def register(self):
|
def register(self):
|
||||||
"""Register the driver."""
|
"""Register the driver."""
|
||||||
self.channels["status"]["last_value"] = ""
|
self.sendtodb("log", "BOOM! Booted.", 0)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Actually run the driver."""
|
"""Actually run the driver."""
|
||||||
global persist
|
global persist
|
||||||
|
wait_sec = 30
|
||||||
|
for i in range(0, wait_sec):
|
||||||
|
print("advvfdipp driver will start in {} seconds".format(wait_sec - i))
|
||||||
|
time.sleep(1)
|
||||||
|
print("BOOM! Starting advvfdipp driver...")
|
||||||
|
send_loops = 0
|
||||||
while True:
|
while True:
|
||||||
if self.forceSend:
|
if self.forceSend:
|
||||||
print "FORCE SEND: TRUE"
|
print "FORCE SEND: TRUE"
|
||||||
@@ -105,16 +128,45 @@ class start(threading.Thread, deviceBase):
|
|||||||
if this_sch_h['id'] > persist['last_schedule_history']['id']:
|
if this_sch_h['id'] > persist['last_schedule_history']['id']:
|
||||||
persist['last_schedule_history'] = this_sch_h
|
persist['last_schedule_history'] = this_sch_h
|
||||||
print(json.dumps(this_sch_h, indent=4))
|
print(json.dumps(this_sch_h, indent=4))
|
||||||
self.sendtodbJSON("run_history", this_sch_h, this_sch_h['timestamp'])
|
self.sendtodbJSON("run_history", json.dumps(this_sch_h), this_sch_h['timestamp'])
|
||||||
with open("persist.json", 'w') as persist_file:
|
with open("persist.json", 'w') as persist_file:
|
||||||
json.dump(persist, persist_file, indent=4)
|
json.dump(persist, persist_file, indent=4)
|
||||||
|
|
||||||
|
for sch_s in scheduler_schedule:
|
||||||
|
if sch_s.read(self.forceSend):
|
||||||
|
self.sendtodbJSON("run_schedule", json.dumps(sch_s.jsonify()), 0)
|
||||||
|
|
||||||
print("advvfdipp driver still alive...")
|
print("advvfdipp driver still alive...")
|
||||||
if self.forceSend:
|
if self.forceSend:
|
||||||
self.forceSend = False
|
if send_loops > 2:
|
||||||
|
print("Turning off forceSend")
|
||||||
|
self.forceSend = False
|
||||||
|
send_loops = 0
|
||||||
|
else:
|
||||||
|
send_loops += 1
|
||||||
|
|
||||||
def advvfdipp_sync(self, name, value):
|
def advvfdipp_sync(self, name, value):
|
||||||
"""Sync all data from the driver."""
|
"""Sync all data from the driver."""
|
||||||
self.forceSend = True
|
self.forceSend = True
|
||||||
self.sendtodb("log", "synced", 0)
|
self.sendtodb("log", "synced", 0)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def advvfdipp_addtoschedule(self, name, value):
|
||||||
|
"""Add an entry into the scheduler."""
|
||||||
|
new_sch = json.loads(value)
|
||||||
|
try:
|
||||||
|
id = int(new_sch['id'])
|
||||||
|
control_mode = {"tag": "sch_RunSchedule[{}].controlMode".format(id), "val": reverse_map(new_sch['control_mode'], maps['pid_controlmode'])}
|
||||||
|
control_setpoint = {"tag": "sch_RunSchedule[{}].controlSetpoint".format(id), "val": new_sch['control_setpoint']}
|
||||||
|
completion_parameter = {"tag": "sch_RunSchedule[{}].completionParameter".format(id), "val": reverse_map(new_sch['completion_parameter'], maps['completion_parameter'])}
|
||||||
|
completion_comparison = {"tag": "sch_RunSchedule[{}].completionComparison".format(id), "val": reverse_map(new_sch['completion_comparison'], maps['completion_comparison'])}
|
||||||
|
completion_value_target = {"tag": "sch_RunSchedule[{}].completionValueTarget".format(id), "val": new_sch['completion_value_target']}
|
||||||
|
|
||||||
|
ch_to_write = [id, control_mode, control_setpoint, completion_parameter, completion_comparison, completion_value_target]
|
||||||
|
for ch in ch_to_write:
|
||||||
|
w = write_tag(plc_ip_address, ch['tag'], ch['val'])
|
||||||
|
print(w)
|
||||||
|
return True
|
||||||
|
except KeyError:
|
||||||
|
print("part of the schedule entry is missing")
|
||||||
|
return False
|
||||||
|
|||||||
Reference in New Issue
Block a user