Merge remote-tracking branch 'origin/main'
This commit is contained in:
commit
259f5217b2
|
@ -677,8 +677,8 @@ internal static class Program
|
||||||
var request = s3Config.CreatePutRequest(s3Path);
|
var request = s3Config.CreatePutRequest(s3Path);
|
||||||
|
|
||||||
// This is temporary for Wittman, but now it's for all Installation
|
// This is temporary for Wittman, but now it's for all Installation
|
||||||
await File.WriteAllTextAsync("/var/www/html/status.csv", csv.SplitLines().Where(l => !l.Contains("Secret")).JoinLines());
|
//await File.WriteAllTextAsync("/var/www/html/status.csv", csv.SplitLines().Where(l => !l.Contains("Secret")).JoinLines());
|
||||||
|
|
||||||
//Use this for no compression
|
//Use this for no compression
|
||||||
//var response = await request.PutAsync(new StringContent(csv));
|
//var response = await request.PutAsync(new StringContent(csv));
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ namespace InnovEnergy.App.SchneiderDriver;
|
||||||
public static class Config
|
public static class Config
|
||||||
{
|
{
|
||||||
public const String Version = "1.0";
|
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 Byte ModbusNodeId = 1;
|
||||||
public const String OwnAddress = "192.168.1.246";
|
public const String OwnAddress = "192.168.1.246";
|
||||||
public const String PeerAddress = "192.168.1.82";
|
public const String PeerAddress = "192.168.1.82";
|
||||||
|
|
|
@ -193,29 +193,36 @@ def update_state_from_dictionaries(current_warnings, current_alarms, node_number
|
||||||
alarms_number_list = []
|
alarms_number_list = []
|
||||||
for node_number in node_numbers:
|
for node_number in node_numbers:
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for alarm_value in current_alarms.values():
|
for i, alarm_value in enumerate(current_alarms.values()):
|
||||||
if alarm_value:
|
if int(list(current_alarms.keys())[i].split("/")[3]) == int(node_number):
|
||||||
cnt+=1
|
if alarm_value:
|
||||||
alarms_number_list.append(cnt)
|
cnt+=1
|
||||||
|
alarms_number_list.append(cnt)
|
||||||
|
|
||||||
|
|
||||||
warnings_number_list = []
|
warnings_number_list = []
|
||||||
for node_number in node_numbers:
|
for node_number in node_numbers:
|
||||||
cnt = 0
|
cnt = 0
|
||||||
for warning_value in current_warnings.values():
|
for i, warning_value in enumerate(current_warnings.values()):
|
||||||
if warning_value:
|
if int(list(current_warnings.keys())[i].split("/")[3]) == int(node_number):
|
||||||
cnt+=1
|
if warning_value:
|
||||||
|
cnt+=1
|
||||||
warnings_number_list.append(cnt)
|
warnings_number_list.append(cnt)
|
||||||
|
|
||||||
# Evaluate alarms
|
# Evaluate alarms
|
||||||
if any(changed_alarms.values()):
|
if any(changed_alarms.values()):
|
||||||
for i, changed_alarm in enumerate(changed_alarms.values()):
|
for i, changed_alarm in enumerate(changed_alarms.values()):
|
||||||
if changed_alarm and list(current_alarms.values())[i]:
|
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()):
|
if any(changed_warnings.values()):
|
||||||
for i, changed_warning in enumerate(changed_warnings.values()):
|
for i, changed_warning in enumerate(changed_warnings.values()):
|
||||||
if changed_warning and list(current_warnings.values())[i]:
|
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()):
|
if any(current_alarms.values()):
|
||||||
status_message["Status"]=2
|
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_warnings = current_warnings.copy()
|
||||||
previous_alarms = current_alarms.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
|
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
|
alive = True # global alive flag, watchdog_task clears it, update_task sets it
|
||||||
|
|
||||||
|
start_time = time.time()
|
||||||
|
|
||||||
def create_update_task(modbus, service, batteries):
|
def create_update_task(modbus, service, batteries):
|
||||||
|
global start_time
|
||||||
# type: (Modbus, DBusService, Iterable[Battery]) -> Callable[[],bool]
|
# type: (Modbus, DBusService, Iterable[Battery]) -> Callable[[],bool]
|
||||||
"""
|
"""
|
||||||
Creates an update task which runs the main update function
|
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)
|
csv_signals = signals.create_csv_signals(first(batteries).firmware_version)
|
||||||
node_numbers = [battery.slave_address for battery in batteries]
|
node_numbers = [battery.slave_address for battery in batteries]
|
||||||
|
print("NODE NUMBERSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS")
|
||||||
warnings_signals, alarm_signals = signals.read_warning_and_alarm_flags()
|
warnings_signals, alarm_signals = signals.read_warning_and_alarm_flags()
|
||||||
current_warnings = {}
|
current_warnings = {}
|
||||||
current_alarms = {}
|
current_alarms = {}
|
||||||
|
|
||||||
def update_task():
|
def update_task():
|
||||||
|
global start_time
|
||||||
# type: () -> bool
|
# type: () -> bool
|
||||||
|
|
||||||
global alive
|
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
|
# Iterate over each node and signal to create rows in the new format
|
||||||
for i, node in enumerate(node_numbers):
|
for i, node in enumerate(node_numbers):
|
||||||
for s in warnings_signals:
|
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])
|
value = s.get_value(statuses[i])
|
||||||
current_warnings[signal_name] = value
|
current_warnings[signal_name] = value
|
||||||
for s in alarm_signals:
|
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])
|
value = s.get_value(statuses[i])
|
||||||
current_alarms[signal_name] = value
|
current_alarms[signal_name] = value
|
||||||
|
|
||||||
|
@ -535,7 +550,11 @@ def create_update_task(modbus, service, batteries):
|
||||||
|
|
||||||
publish_values_on_dbus(service, _signals, statuses)
|
publish_values_on_dbus(service, _signals, statuses)
|
||||||
|
|
||||||
create_csv_files(csv_signals, statuses, node_numbers, alarms_number_list, warnings_number_list)
|
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)
|
upload_status_to_innovenergy(_socket, statuses)
|
||||||
|
|
||||||
|
@ -548,7 +567,7 @@ def create_update_task(modbus, service, batteries):
|
||||||
return update_task
|
return update_task
|
||||||
|
|
||||||
def manage_csv_files(directory_path, max_files=20):
|
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)))
|
csv_files.sort(key=lambda x: os.path.getctime(os.path.join(directory_path, x)))
|
||||||
# Remove oldest files if exceeds maximum
|
# Remove oldest files if exceeds maximum
|
||||||
while len(csv_files) > max_files:
|
while len(csv_files) > max_files:
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue