update: send a csv file every 30 seconds
fix: number of alarms and warnings calculation
This commit is contained in:
parent
fc5e814ffa
commit
d4f34c3190
|
@ -6,7 +6,7 @@ namespace InnovEnergy.App.SchneiderDriver;
|
|||
public static class Config
|
||||
{
|
||||
public const String Version = "1.0";
|
||||
public const String BusName = "com.victronenergy.grid.Schnieder";
|
||||
public const String BusName = "com.victronenergy.grid";
|
||||
public const Byte ModbusNodeId = 1;
|
||||
public const String OwnAddress = "192.168.1.246";
|
||||
public const String PeerAddress = "192.168.1.82";
|
||||
|
|
|
@ -193,15 +193,18 @@ def update_state_from_dictionaries(current_warnings, current_alarms, node_number
|
|||
alarms_number_list = []
|
||||
for node_number in node_numbers:
|
||||
cnt = 0
|
||||
for alarm_value in current_alarms.values():
|
||||
for i, alarm_value in enumerate(current_alarms.values()):
|
||||
if int(list(current_alarms.keys())[i].split("/")[3]) == int(node_number):
|
||||
if alarm_value:
|
||||
cnt+=1
|
||||
alarms_number_list.append(cnt)
|
||||
|
||||
|
||||
warnings_number_list = []
|
||||
for node_number in node_numbers:
|
||||
cnt = 0
|
||||
for warning_value in current_warnings.values():
|
||||
for i, warning_value in enumerate(current_warnings.values()):
|
||||
if int(list(current_warnings.keys())[i].split("/")[3]) == int(node_number):
|
||||
if warning_value:
|
||||
cnt+=1
|
||||
warnings_number_list.append(cnt)
|
||||
|
@ -210,12 +213,16 @@ def update_state_from_dictionaries(current_warnings, current_alarms, node_number
|
|||
if any(changed_alarms.values()):
|
||||
for i, changed_alarm in enumerate(changed_alarms.values()):
|
||||
if changed_alarm and list(current_alarms.values())[i]:
|
||||
status_message["Alarms"].append(AlarmOrWarning(list(current_alarms.keys())[i],"System").to_dict())
|
||||
description = list(current_alarms.keys())[i].split("/")[-1]
|
||||
device_created = "Battery node " + list(current_alarms.keys())[i].split("/")[3]
|
||||
status_message["Alarms"].append(AlarmOrWarning(description, device_created).to_dict())
|
||||
|
||||
if any(changed_warnings.values()):
|
||||
for i, changed_warning in enumerate(changed_warnings.values()):
|
||||
if changed_warning and list(current_warnings.values())[i]:
|
||||
status_message["Warnings"].append(AlarmOrWarning(list(current_warnings.keys())[i],"System").to_dict())
|
||||
description = list(current_warnings.keys())[i].split("/")[-1]
|
||||
device_created = "Battery node " + list(current_warnings.keys())[i].split("/")[3]
|
||||
status_message["Warnings"].append(AlarmOrWarning(description, device_created).to_dict())
|
||||
|
||||
if any(current_alarms.values()):
|
||||
status_message["Status"]=2
|
||||
|
@ -242,6 +249,10 @@ def update_state_from_dictionaries(current_warnings, current_alarms, node_number
|
|||
|
||||
previous_warnings = current_warnings.copy()
|
||||
previous_alarms = current_alarms.copy()
|
||||
#print("ALARMS LIST")
|
||||
#print(alarms_number_list)
|
||||
#print("WARNINGS LIST")
|
||||
#print(warnings_number_list)
|
||||
|
||||
return status_message, alarms_number_list, warnings_number_list
|
||||
|
||||
|
@ -492,8 +503,10 @@ def reset_batteries(modbus, batteries):
|
|||
|
||||
alive = True # global alive flag, watchdog_task clears it, update_task sets it
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
def create_update_task(modbus, service, batteries):
|
||||
global start_time
|
||||
# type: (Modbus, DBusService, Iterable[Battery]) -> Callable[[],bool]
|
||||
"""
|
||||
Creates an update task which runs the main update function
|
||||
|
@ -504,11 +517,13 @@ def create_update_task(modbus, service, batteries):
|
|||
|
||||
csv_signals = signals.create_csv_signals(first(batteries).firmware_version)
|
||||
node_numbers = [battery.slave_address for battery in batteries]
|
||||
print("NODE NUMBERSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS")
|
||||
warnings_signals, alarm_signals = signals.read_warning_and_alarm_flags()
|
||||
current_warnings = {}
|
||||
current_alarms = {}
|
||||
|
||||
def update_task():
|
||||
global start_time
|
||||
# type: () -> bool
|
||||
|
||||
global alive
|
||||
|
@ -523,11 +538,11 @@ def create_update_task(modbus, service, batteries):
|
|||
# Iterate over each node and signal to create rows in the new format
|
||||
for i, node in enumerate(node_numbers):
|
||||
for s in warnings_signals:
|
||||
signal_name = insert_id(s.name, i+1)
|
||||
signal_name = insert_id(s.name, node)
|
||||
value = s.get_value(statuses[i])
|
||||
current_warnings[signal_name] = value
|
||||
for s in alarm_signals:
|
||||
signal_name = insert_id(s.name, i+1)
|
||||
signal_name = insert_id(s.name, node)
|
||||
value = s.get_value(statuses[i])
|
||||
current_alarms[signal_name] = value
|
||||
|
||||
|
@ -535,7 +550,11 @@ def create_update_task(modbus, service, batteries):
|
|||
|
||||
publish_values_on_dbus(service, _signals, statuses)
|
||||
|
||||
elapsed_time = time.time() - start_time
|
||||
if elapsed_time >= 30:
|
||||
create_csv_files(csv_signals, statuses, node_numbers, alarms_number_list, warnings_number_list)
|
||||
start_time = time.time()
|
||||
print("Elapsed time {:.2f} seconds".format(elapsed_time))
|
||||
|
||||
upload_status_to_innovenergy(_socket, statuses)
|
||||
|
||||
|
@ -548,7 +567,7 @@ def create_update_task(modbus, service, batteries):
|
|||
return update_task
|
||||
|
||||
def manage_csv_files(directory_path, max_files=20):
|
||||
csv_files = [f for f in os.listdir(directory_path)]
|
||||
csv_files = [f for f in os.listdir(directory_path) if os.path.isfile(os.path.join(directory_path, f))]
|
||||
csv_files.sort(key=lambda x: os.path.getctime(os.path.join(directory_path, x)))
|
||||
# Remove oldest files if exceeds maximum
|
||||
while len(csv_files) > max_files:
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue