Merge branch 'main' of 91.92.155.224:Innovenergy/Innovenergy_trunk
This commit is contained in:
commit
ace65fb21a
|
@ -6,6 +6,7 @@ using InnovEnergy.App.Backend.Database;
|
||||||
using InnovEnergy.App.Backend.DataTypes;
|
using InnovEnergy.App.Backend.DataTypes;
|
||||||
using RabbitMQ.Client;
|
using RabbitMQ.Client;
|
||||||
using RabbitMQ.Client.Events;
|
using RabbitMQ.Client.Events;
|
||||||
|
using InnovEnergy.Lib.Mailer;
|
||||||
|
|
||||||
namespace InnovEnergy.App.Backend.Websockets;
|
namespace InnovEnergy.App.Backend.Websockets;
|
||||||
|
|
||||||
|
@ -61,6 +62,20 @@ public static class RabbitMqManager
|
||||||
Console.WriteLine("----------------------------------------------");
|
Console.WriteLine("----------------------------------------------");
|
||||||
|
|
||||||
int installationId = (int)Db.Installations.Where(f => f.Product == receivedStatusMessage.Product && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.Id).FirstOrDefault();
|
int installationId = (int)Db.Installations.Where(f => f.Product == receivedStatusMessage.Product && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.Id).FirstOrDefault();
|
||||||
|
string installationName = (string)Db.Installations.Where(f => f.Product == receivedStatusMessage.Product && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.InstallationName).FirstOrDefault();
|
||||||
|
int bucketId = (int)Db.Installations.Where(f => f.Product == receivedStatusMessage.Product && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.S3BucketId).FirstOrDefault();
|
||||||
|
int productId = (int)Db.Installations.Where(f => f.Product == receivedStatusMessage.Product && f.S3BucketId == receivedStatusMessage.InstallationId).Select(f => f.Product).FirstOrDefault();
|
||||||
|
string monitorLink = "";
|
||||||
|
if (productId == 0)
|
||||||
|
{
|
||||||
|
monitorLink =
|
||||||
|
$"https://monitor.innov.energy/installations/list/installation/{bucketId}/batteryview";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
monitorLink =
|
||||||
|
$"https://monitor.innov.energy/salidomo_installations/list/installation/{bucketId}/batteryview";
|
||||||
|
}
|
||||||
Console.WriteLine("Received a message from installation: " + installationId + " , product is: "+receivedStatusMessage.Product+ " and status is: " + receivedStatusMessage.Status);
|
Console.WriteLine("Received a message from installation: " + installationId + " , product is: "+receivedStatusMessage.Product+ " and status is: " + receivedStatusMessage.Status);
|
||||||
|
|
||||||
//This is a heartbit message, just update the timestamp for this installation.
|
//This is a heartbit message, just update the timestamp for this installation.
|
||||||
|
@ -109,6 +124,25 @@ public static class RabbitMqManager
|
||||||
DeviceCreatedTheMessage = alarm.CreatedBy,
|
DeviceCreatedTheMessage = alarm.CreatedBy,
|
||||||
Seen = false
|
Seen = false
|
||||||
}; Console.WriteLine("Add an alarm for installation "+installationId);
|
}; Console.WriteLine("Add an alarm for installation "+installationId);
|
||||||
|
// Send replace battery email to support team if this alarm is "NeedToReplaceBattery"
|
||||||
|
if (alarm.Description == "NeedToReplaceBattery")
|
||||||
|
{
|
||||||
|
Console.WriteLine("Send replace battery email to the support team for installation "+installationId);
|
||||||
|
string recipient = "support@innov.energy";
|
||||||
|
string subject = "Battery Alarm: 2 or more strings broken";
|
||||||
|
string text = $"Dear InnovEnergy Support Team,\n" +
|
||||||
|
$"\n"+
|
||||||
|
$"Installation Name: {installationName}\n"+
|
||||||
|
$"\n"+
|
||||||
|
$"Installation Monitor Link: {monitorLink}\n"+
|
||||||
|
$"\n"+
|
||||||
|
$"Please exchange: {alarm.CreatedBy}\n"+
|
||||||
|
$"\n"+
|
||||||
|
$"Error created date and time: {alarm.Date} {alarm.Time}\n"+
|
||||||
|
$"\n"+
|
||||||
|
$"Thank you for your great support:)";
|
||||||
|
Mailer.Send("InnovEnergy Support Team", recipient, subject, text);
|
||||||
|
}
|
||||||
//Create a new error and add it to the database
|
//Create a new error and add it to the database
|
||||||
Db.HandleError(newError, installationId);
|
Db.HandleError(newError, installationId);
|
||||||
}
|
}
|
||||||
|
|
|
@ -677,7 +677,7 @@ 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,15 +193,18 @@ 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 int(list(current_alarms.keys())[i].split("/")[3]) == int(node_number):
|
||||||
if alarm_value:
|
if alarm_value:
|
||||||
cnt+=1
|
cnt+=1
|
||||||
alarms_number_list.append(cnt)
|
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 int(list(current_warnings.keys())[i].split("/")[3]) == int(node_number):
|
||||||
if warning_value:
|
if warning_value:
|
||||||
cnt+=1
|
cnt+=1
|
||||||
warnings_number_list.append(cnt)
|
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()):
|
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)
|
||||||
|
|
||||||
|
elapsed_time = time.time() - start_time
|
||||||
|
if elapsed_time >= 30:
|
||||||
create_csv_files(csv_signals, statuses, node_numbers, alarms_number_list, warnings_number_list)
|
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