Send to rado platform; show_dbdata, db loads after start

This commit is contained in:
rasta5man 2024-12-02 16:57:26 +01:00
parent ed0fe5b15d
commit f63ac50497
22 changed files with 6380 additions and 2279 deletions

View file

@ -3,6 +3,7 @@ exports.title = 'Modbus reader';
exports.version = '2.0.0';
exports.group = 'Worksys';
exports.color = '#2134B0';
exports.input = 1;
exports.output = ["red", "white", "yellow"];
exports.click = false;
exports.author = 'Rastislav Kovac';
@ -31,7 +32,10 @@ const SEND_TO = {
const numberOfNotResponding = {};
let tbName = null;
let mainSocket;
//number of phases inRVO
let phases;
//phases where voltage is 0 (set)
let noVoltage;
exports.install = function(instance) {
@ -55,10 +59,19 @@ exports.install = function(instance) {
// lampSwitchNotification helper variables
this.onNotificationSent = false;
this.offNotificationSent = false;
this.phases = this.buildPhases();
this.startSocket();
}
buildPhases = () => {
let a = [];
for (let i = 1; i<= phases; i++) {
a.push(`Phase_${i}_voltage`)
}
return a;
}
startSocket = () => {
let obj = this;
@ -228,9 +241,7 @@ exports.install = function(instance) {
this.allValues = {};
break;
}
}
}
setNewStream = () =>
@ -282,7 +293,7 @@ exports.install = function(instance) {
if(!(values.hasOwnProperty("Phase_1_voltage") || values.hasOwnProperty("Phase_2_voltage") || values.hasOwnProperty("Phase_3_voltage"))) return;
Object.keys(values).map(singleValue => {
if (["Phase_1_voltage", "Phase_2_voltage", "Phase_3_voltage"].includes(singleValue))
if (this.phases.includes(singleValue))
{
let l = singleValue.split("_");
let phase = parseInt(l[1]);
@ -291,13 +302,13 @@ exports.install = function(instance) {
if(values[singleValue] == 0)
{
FLOW.OMS_no_voltage.add(phase);
noVoltage.add(phase);
sendNotification("modbus_reader: checkNullVoltage", tbName, "no_voltage_on_phase", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase );
// console.log('no voltage')
}
else
{
FLOW.OMS_no_voltage.delete(phase);
noVoltage.delete(phase);
// console.log('voltage detected')
sendNotification("modbus_reader: checkNullVoltage", tbName, "voltage_on_phase_restored", {phase: phase}, "", SEND_TO.tb, instance, "voltage" + phase);
}
@ -330,18 +341,23 @@ exports.install = function(instance) {
}
const isObjectEmpty = (objectName) => {
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
return Object.keys(objectName).length === 0 && objectName.constructor === Object;
}
setTimeout(() => {
function main() {
phases = FLOW.GLOBALS.settings.phases;
tbName = FLOW.GLOBALS.settings.rvoTbName;
noVoltage = FLOW.GLOBALS.settings.no_voltage;
mainSocket = new SocketWithClients();
tbName = FLOW.OMS_rvo_tbname;
// this notification is to show, that flow (unipi) has been restarted
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
}
}, 25000);
instance.on("0", function(_) {
main();
})
}