Add language notifications; Add power door handel
This commit is contained in:
parent
d97d90cf95
commit
0876e73c68
12 changed files with 445 additions and 581 deletions
|
|
@ -20,9 +20,12 @@ key:string|weight:string|sk:string|en:string
|
||||||
+|power_supply_works_correctly|NOTICE|Napájací zdroj pracuje správne|Power supply works correctly|...............
|
+|power_supply_works_correctly|NOTICE|Napájací zdroj pracuje správne|Power supply works correctly|...............
|
||||||
+|battery_level_is_low|ERROR|Batéria má nízku úroveň napätia|Battery level is low|...............
|
+|battery_level_is_low|ERROR|Batéria má nízku úroveň napätia|Battery level is low|...............
|
||||||
+|battery_level_is_ok|NOTICE|Batéria má správnu úroveň napätia|Battery level is OK|...............
|
+|battery_level_is_ok|NOTICE|Batéria má správnu úroveň napätia|Battery level is OK|...............
|
||||||
+|door_opened|NOTICE|Dvere boli otvorené|Door has been opeed|...............
|
+|door_main_open|NOTICE|Hlavné dvere boli otvorené|Main door has been opened|...............
|
||||||
+|door_closed|NOTICE|Dvere boli zatvorené|Door has been closed|...............
|
+|door_em_open|NOTICE|Dvere silovej časti boli otvorené|Power door has been opened|...............
|
||||||
+|door_opened_without_permission|WARNING|Dvere boli otvorené bez povolenia - zapnutá siréna|Door opened without permision - alarm is on|...............
|
+|door_main_open_without_permission|WARNING|Hlavné dvere boli otvorené bez povolenia - zapnutá siréna|Main door has been opened without permission - alarm is on|...............
|
||||||
|
+|door_em_open_without_permission|WARNING|Dvere silovej časti boli otvorené bez povolenia|Power door has been opened without permission|...............
|
||||||
|
+|door_main_close|NOTICE|Hlavné dvere boli zatvorené|Main door has been closed|...............
|
||||||
|
+|door_em_close|NOTICE|Dvere silovej časti boli zatvorené|Power door has been closed|...............
|
||||||
+|state_of_contactor_for_line|INFORMATIONAL|Stav stýkača pre líniu č. ${line} je ${value}|State of contactor for line no. ${line} is ${value}|...............
|
+|state_of_contactor_for_line|INFORMATIONAL|Stav stýkača pre líniu č. ${line} je ${value}|State of contactor for line no. ${line} is ${value}|...............
|
||||||
+|local_database_is_corrupted|CRITICAL|||...............
|
+|local_database_is_corrupted|CRITICAL|||...............
|
||||||
+|electrometer_nok|ERROR|Elektromer neodpovedá|Electrometer is not responding|...............
|
+|electrometer_nok|ERROR|Elektromer neodpovedá|Electrometer is not responding|...............
|
||||||
|
|
@ -34,5 +37,5 @@ key:string|weight:string|sk:string|en:string
|
||||||
+|twilight_sensor_ok|NOTICE|Sensor súmraku znovu odpovedá|Twilight sensor is responding again|...............
|
+|twilight_sensor_ok|NOTICE|Sensor súmraku znovu odpovedá|Twilight sensor is responding again|...............
|
||||||
+|lamps_have_turned_on|NOTICE|Lampy sa zapli|Lamps have turned on|...............
|
+|lamps_have_turned_on|NOTICE|Lampy sa zapli|Lamps have turned on|...............
|
||||||
+|lamps_have_turned_off|NOTICE|Lampy sa vypli|Lamps have turned off|...............
|
+|lamps_have_turned_off|NOTICE|Lampy sa vypli|Lamps have turned off|...............
|
||||||
+|flow_restart|NOTICE|Restart flowu|Flow has been restarted|...............
|
+|flow_restart|NOTICE|FLOW bol reštartovaný|FLOW has been restarted|...............
|
||||||
+|nodes_db_changed|NOTICE|Zmena v node databaze|Node db has changed|...............
|
+|nodes_db_changed|NOTICE|Zmena v node databáze|Node db has changed|...............
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
var SunCalc = require('./helper/suncalc');
|
var SunCalc = require('./helper/suncalc');
|
||||||
const DataToTbHandler = require('./helper/DataToTbHandler');
|
const DataToTbHandler = require('./helper/DataToTbHandler');
|
||||||
const ErrorToServiceHandler = require('./helper/ErrorToServiceHandler');
|
const errorHandler = require('./helper/ErrorToServiceHandler');
|
||||||
const { sendNotification } = require('./helper/notification_reporter');
|
const { sendNotification } = require('./helper/notification_reporter');
|
||||||
const process = require('process');
|
const process = require('process');
|
||||||
const { errLogger, logger, monitor } = require('./helper/logger');
|
const { errLogger, logger, monitor } = require('./helper/logger');
|
||||||
|
|
@ -127,8 +127,6 @@ exports.install = function(instance) {
|
||||||
//prikazy kt sa budu spustat na dany node - see config.js in terminal-oms.app. (1 - dimming)
|
//prikazy kt sa budu spustat na dany node - see config.js in terminal-oms.app. (1 - dimming)
|
||||||
let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 87, 89];
|
let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 87, 89];
|
||||||
|
|
||||||
const errorHandler = new ErrorToServiceHandler();
|
|
||||||
|
|
||||||
let rotary_switch_state;
|
let rotary_switch_state;
|
||||||
let lux_sensor;
|
let lux_sensor;
|
||||||
let state_of_breaker = {};//key is line, value is On/Off
|
let state_of_breaker = {};//key is line, value is On/Off
|
||||||
|
|
@ -165,8 +163,6 @@ exports.install = function(instance) {
|
||||||
tbHandler = new DataToTbHandler(SEND_TO.tb);
|
tbHandler = new DataToTbHandler(SEND_TO.tb);
|
||||||
tbHandler.setSender(exports.title);
|
tbHandler.setSender(exports.title);
|
||||||
|
|
||||||
errorHandler.setProjectsId(SETTINGS.project_id);
|
|
||||||
|
|
||||||
let now = new Date();
|
let now = new Date();
|
||||||
console.log("CMD Manager installed", now.toLocaleString("sk-SK"));
|
console.log("CMD Manager installed", now.toLocaleString("sk-SK"));
|
||||||
|
|
||||||
|
|
@ -186,7 +182,6 @@ exports.install = function(instance) {
|
||||||
}, 120000);
|
}, 120000);
|
||||||
reportEdgeDateTimeAndNumberOfLuminaires();
|
reportEdgeDateTimeAndNumberOfLuminaires();
|
||||||
|
|
||||||
|
|
||||||
setCorrectTime = setInterval(setCorrectPlcTimeOnceADay, 60000 * 60); // 1 hour
|
setCorrectTime = setInterval(setCorrectPlcTimeOnceADay, 60000 * 60); // 1 hour
|
||||||
setCorrectPlcTimeOnceADay();
|
setCorrectPlcTimeOnceADay();
|
||||||
|
|
||||||
|
|
@ -1155,7 +1150,7 @@ exports.install = function(instance) {
|
||||||
params.type = "cmd-master";
|
params.type = "cmd-master";
|
||||||
params.register = 4;
|
params.register = 4;
|
||||||
params.address = 0;
|
params.address = 0;
|
||||||
params.timestamp = Date.now() + 60000;
|
params.timestamp = 0;
|
||||||
params.addMinutesToTimestamp = 5;
|
params.addMinutesToTimestamp = 5;
|
||||||
params.tbname = SETTINGS.rvoTbName;
|
params.tbname = SETTINGS.rvoTbName;
|
||||||
params.info = "Master node FW verzia";
|
params.info = "Master node FW verzia";
|
||||||
|
|
@ -1579,6 +1574,7 @@ exports.install = function(instance) {
|
||||||
let readBytes = 11;
|
let readBytes = 11;
|
||||||
let timeout = 4000;
|
let timeout = 4000;
|
||||||
|
|
||||||
|
|
||||||
// await keyword is important, otherwise incorrect data is returned!
|
// await keyword is important, otherwise incorrect data is returned!
|
||||||
await writeData(rsPort, resp, readBytes, timeout).then(function(data) {
|
await writeData(rsPort, resp, readBytes, timeout).then(function(data) {
|
||||||
|
|
||||||
|
|
@ -1592,7 +1588,6 @@ exports.install = function(instance) {
|
||||||
//ak sa odpoved zacina 0 - je to v poriadku, inak je NOK
|
//ak sa odpoved zacina 0 - je to v poriadku, inak je NOK
|
||||||
let message = result.message; // OK, NOK
|
let message = result.message; // OK, NOK
|
||||||
let message_type = result.type;
|
let message_type = result.type;
|
||||||
let error = result.error;
|
|
||||||
|
|
||||||
if (params.hasOwnProperty("debug")) {
|
if (params.hasOwnProperty("debug")) {
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
|
|
@ -1643,11 +1638,6 @@ exports.install = function(instance) {
|
||||||
if (register == 4) values["edge_fw_version"] = SETTINGS.edge_fw_version;
|
if (register == 4) values["edge_fw_version"] = SETTINGS.edge_fw_version;
|
||||||
}
|
}
|
||||||
|
|
||||||
//odoslanie príkazu z terminálu - dáta
|
|
||||||
if (type == "cmd-terminal") {
|
|
||||||
sendNotification("CMD Manager: process cmd", SETTINGS.rvoTbName, "command_was_sent_from_terminal_interface", {}, params, SEND_TO.tb, instance);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (params.debug) {
|
if (params.debug) {
|
||||||
//logger.debug("saveToTb", saveToTb, tbname, values);
|
//logger.debug("saveToTb", saveToTb, tbname, values);
|
||||||
}
|
}
|
||||||
|
|
@ -1879,16 +1869,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
logger.debug(0, "RPC runSyncExec - Promise Resolved:" + status);
|
logger.debug(0, "RPC runSyncExec - Promise Resolved:" + status);
|
||||||
|
|
||||||
//APP START
|
|
||||||
let dataToInfoSender = { id: SETTINGS.project_id, name: SETTINGS.rvo_name };
|
|
||||||
dataToInfoSender.fw_version = SETTINGS.edge_fw_version;
|
|
||||||
dataToInfoSender.startdate = new Date().toISOString().slice(0, 19).replace('T', ' ');
|
|
||||||
dataToInfoSender.__force__ = true;
|
|
||||||
|
|
||||||
instance.send(SEND_TO.infoSender, dataToInfoSender);
|
|
||||||
|
|
||||||
logger.debug(0, "---------------------------->START message send to service", dataToInfoSender);
|
|
||||||
|
|
||||||
}).catch(function(reason) {
|
}).catch(function(reason) {
|
||||||
instance.send(SEND_TO.debug, "CMD manager - RPC runSyncExec - promise rejected:" + reason);
|
instance.send(SEND_TO.debug, "CMD manager - RPC runSyncExec - promise rejected:" + reason);
|
||||||
});
|
});
|
||||||
|
|
@ -1986,7 +1966,7 @@ exports.install = function(instance) {
|
||||||
//logger.debug(tasks);
|
//logger.debug(tasks);
|
||||||
|
|
||||||
logger.debug("-->CMD MANAGER - RUN TASKS");
|
logger.debug("-->CMD MANAGER - RUN TASKS");
|
||||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
interval = setInterval(runTasks, 5000);
|
||||||
}
|
}
|
||||||
else if (cmd == "reload_relays") {
|
else if (cmd == "reload_relays") {
|
||||||
loadRelaysData(flowdata.data.line);
|
loadRelaysData(flowdata.data.line);
|
||||||
|
|
@ -2627,7 +2607,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dimming, CCT
|
//Dimming, CCT
|
||||||
if (register == 1) {
|
else if (register == 1) {
|
||||||
let brightness = 0;
|
let brightness = 0;
|
||||||
let dimming = byte0;
|
let dimming = byte0;
|
||||||
if (dimming > 128) {
|
if (dimming > 128) {
|
||||||
|
|
@ -2648,125 +2628,87 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
if (register == 4) {
|
else if (register == 4) {
|
||||||
values["master_node_version"] = bytes[1] + "." + bytes[2];
|
values["master_node_version"] = bytes[1] + "." + bytes[2];
|
||||||
//logger.debug("FW Version", register, bytes);
|
//logger.debug("FW Version", register, bytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Napätie
|
//Napätie
|
||||||
if (register == 74) {
|
else if (register == 74) {
|
||||||
let voltage = (bytesToInt(bytes) * 0.1).toFixed(1);
|
let voltage = (bytesToInt(bytes) * 0.1).toFixed(1);
|
||||||
values["voltage"] = Number(voltage);
|
values["voltage"] = Number(voltage);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Prúd
|
//Prúd
|
||||||
if (register == 75) {
|
else if (register == 75) {
|
||||||
let current = bytesToInt(bytes);
|
let current = bytesToInt(bytes);
|
||||||
values["current"] = current;
|
values["current"] = current;
|
||||||
}
|
}
|
||||||
|
|
||||||
//výkon
|
//výkon
|
||||||
if (register == 76) {
|
else if (register == 76) {
|
||||||
let power = (bytesToInt(bytes) * 0.1).toFixed(2);
|
let power = (bytesToInt(bytes) * 0.1).toFixed(2);
|
||||||
values["power"] = Number(power);
|
values["power"] = Number(power);
|
||||||
}
|
}
|
||||||
|
|
||||||
//účinník
|
//účinník
|
||||||
if (register == 77) {
|
else if (register == 77) {
|
||||||
let power_factor = Math.cos(bytesToInt(bytes) * 0.1).toFixed(2);
|
let power_factor = Math.cos(bytesToInt(bytes) * 0.1).toFixed(2);
|
||||||
values["power_factor"] = Number(power_factor);
|
values["power_factor"] = Number(power_factor);
|
||||||
}
|
}
|
||||||
|
|
||||||
//frekvencia
|
//frekvencia
|
||||||
if (register == 78) {
|
else if (register == 78) {
|
||||||
let frequency = (bytesToInt(bytes) * 0.1).toFixed(2);
|
let frequency = (bytesToInt(bytes) * 0.1).toFixed(2);
|
||||||
values["frequency"] = Number(frequency);
|
values["frequency"] = Number(frequency);
|
||||||
}
|
}
|
||||||
|
|
||||||
//energia
|
//energia
|
||||||
if (register == 79) {
|
else if (register == 79) {
|
||||||
let energy = bytesToInt(bytes);
|
let energy = bytesToInt(bytes);
|
||||||
|
//Energiu treba reportovať v kWh -> delit 1000
|
||||||
//Energiu treba reportovať v kWh. Teda číslo, ktoré príde treba podeliť 1000. Toto som ti možno zle napísal.
|
|
||||||
|
|
||||||
values["energy"] = energy / 1000;
|
values["energy"] = energy / 1000;
|
||||||
}
|
}
|
||||||
|
|
||||||
//doba života
|
//doba života
|
||||||
if (register == 80) {
|
else if (register == 80) {
|
||||||
let lifetime = (bytesToInt(bytes) / 60).toFixed(2);
|
let lifetime = (bytesToInt(bytes) / 60).toFixed(2);
|
||||||
values["lifetime"] = Number(lifetime);
|
values["lifetime"] = Number(lifetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
//nastavenie profilu
|
//nastavenie profilu
|
||||||
if (register == 8) {
|
else if (register == 8) {
|
||||||
let time_schedule_settings = bytesToInt(bytes);
|
let time_schedule_settings = bytesToInt(bytes);
|
||||||
values["time_schedule_settings"] = time_schedule_settings;
|
values["time_schedule_settings"] = time_schedule_settings;
|
||||||
}
|
}
|
||||||
|
|
||||||
//naklon - nateraz sa z nodu nevycitava! kvoli problemom s accelerometrom a vracanymi hodnotami, posielame temp a x y z vo funkcii accelerometerData()
|
//naklon - nateraz sa z nodu nevycitava! kvoli problemom s accelerometrom a vracanymi hodnotami, posielame temp a x y z vo funkcii accelerometerData()
|
||||||
if (register == 84) {
|
else if (register == 84) {
|
||||||
const temp = byte3 >= 128 ? (byte3 - 128) * (-1) : byte3;
|
values["temperature"] = byte3 >= 128 ? (byte3 - 128) * (-1) : byte3;
|
||||||
const inclination_x = byte2 >= 128 ? (byte2 - 128) * (-1) : byte2;
|
values["inclination_x"] = byte2 >= 128 ? (byte2 - 128) * (-1) : byte2;
|
||||||
const inclination_y = byte1 >= 128 ? (byte1 - 128) * (-1) : byte1;
|
values["inclination_y"] = byte1 >= 128 ? (byte1 - 128) * (-1) : byte1;
|
||||||
const inclination_z = byte0 >= 128 ? (byte0 - 128) * (-1) : byte0;
|
values["inclination_z"] = byte0 >= 128 ? (byte0 - 128) * (-1) : byte0;
|
||||||
|
|
||||||
if (temp === undefined) temp = 999;
|
|
||||||
if (inclination_x === undefined) inclination_x = 999;
|
|
||||||
if (inclination_y === undefined) inclination_y = 999;
|
|
||||||
if (inclination_z === undefined) inclination_z = 999;
|
|
||||||
|
|
||||||
values["temperature"] = temp;
|
|
||||||
values["inclination_x"] = inclination_x;
|
|
||||||
values["inclination_y"] = inclination_y;
|
|
||||||
values["inclination_z"] = inclination_z;
|
|
||||||
}
|
|
||||||
|
|
||||||
let h = byte3;
|
|
||||||
let m = byte2;
|
|
||||||
|
|
||||||
let timestamp;
|
|
||||||
|
|
||||||
if (register == 87 || register == 6 || register == 7) {
|
|
||||||
//if(byte3 < 10) h = "0" + byte3;
|
|
||||||
//if(byte2 < 10) m = "0" + byte2;
|
|
||||||
//if(byte1 < 10) s = "0" + byte1;
|
|
||||||
|
|
||||||
var d = new Date();
|
|
||||||
d.setHours(h, m, 0, 0);
|
|
||||||
timestamp = d.getTime();
|
|
||||||
}
|
|
||||||
|
|
||||||
//aktuálny čas
|
|
||||||
if (register == 87) {
|
|
||||||
//Byte3 - hodiny, Byte 2 - minúty, Byte 1 -sek.
|
|
||||||
//values["actual_time"] = h + ":" + m + ":" + s;
|
|
||||||
|
|
||||||
values["actual_time"] = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//čas súmraku
|
|
||||||
if (register == 6) {
|
|
||||||
//Byte3 - hodiny, Byte 2 - minúty, Byte 1 -sek.
|
|
||||||
//values["dusk_time"] = h + ":" + m + ":" + s;
|
|
||||||
|
|
||||||
values["dusk_time"] = timestamp;
|
|
||||||
}
|
|
||||||
|
|
||||||
//čas úsvitu
|
|
||||||
if (register == 7) {
|
|
||||||
//Byte3 - hodiny, Byte 2 - minúty, Byte 1 -sek.
|
|
||||||
//values["dawn_time"] = h + ":" + m + ":" + s;
|
|
||||||
|
|
||||||
values["dawn_time"] = timestamp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//FW verzia nodu
|
//FW verzia nodu
|
||||||
if (register == 89) {
|
else if (register == 89) {
|
||||||
//formát: "Byte3: Byte2.Byte1 (Byte0)"
|
//formát: "Byte3: Byte2.Byte1 (Byte0)"
|
||||||
values["fw_version"] = byte3 + ":" + byte2 + "." + byte1 + "(" + byte0 + ")";
|
values["fw_version"] = byte3 + ":" + byte2 + "." + byte1 + "(" + byte0 + ")";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (register == 87 || register == 6 || register == 7) {
|
||||||
|
var d = new Date();
|
||||||
|
d.setHours(byte3, byte2, 0, 0);
|
||||||
|
let timestamp = d.getTime();
|
||||||
|
|
||||||
|
//aktuálny čas
|
||||||
|
if (register == 87) values["actual_time"] = timestamp;
|
||||||
|
//čas súmraku
|
||||||
|
else if (register == 6) values["dusk_time"] = timestamp;
|
||||||
|
//čas úsvitu
|
||||||
|
else if (register == 7) values["dawn_time"] = timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -2850,9 +2792,13 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
if (temperatureInSenica === null) return;
|
if (temperatureInSenica === null) return;
|
||||||
|
|
||||||
for (const key in relaysData) {
|
//clone nodesData and relaysData objects
|
||||||
|
let nodesData_clone = JSON.parse(JSON.stringify(nodesData));
|
||||||
|
let relaysData_clone = JSON.parse(JSON.stringify(relaysData));
|
||||||
|
|
||||||
const lineData = relaysData[key];
|
for (const key in relaysData_clone) {
|
||||||
|
|
||||||
|
const lineData = relaysData_clone[key];
|
||||||
const lineNumber = lineData.line;
|
const lineNumber = lineData.line;
|
||||||
const contactor = lineData.contactor;
|
const contactor = lineData.contactor;
|
||||||
|
|
||||||
|
|
@ -2862,17 +2808,21 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let date = Date.now();
|
let date = Date.now();
|
||||||
|
|
||||||
Object.keys(nodesData).forEach((node, index) => {
|
Object.keys(nodesData_clone).forEach((node, index) => {
|
||||||
|
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
|
|
||||||
if (nodesData[node].line === lineNumber) {
|
if (nodesData_clone[node].line === lineNumber) {
|
||||||
|
|
||||||
|
// NOTE: if status of luminaire is NOK or OFFLINE, we do not send data;
|
||||||
|
let status = nodesData_clone[node].status;
|
||||||
|
if (status === "OFFLINE" || !status) return;
|
||||||
|
|
||||||
let x = null;
|
let x = null;
|
||||||
if (naklony.hasOwnProperty(node)) x = naklony[node].naklon;
|
if (naklony.hasOwnProperty(node)) x = naklony[node].naklon;
|
||||||
if (x === null) x = 0;
|
if (x === null) x = 0;
|
||||||
|
|
||||||
sendTelemetry({ temperature: Math.round(temperatureInSenica + 10 + Math.floor(Math.random() * 3)), inclination_x: x, inclination_y: 0, inclination_z: 0 }, nodesData[node].tbname, date);
|
sendTelemetry({ temperature: Math.round(temperatureInSenica + 10 + Math.floor(Math.random() * 3)), inclination_x: x, inclination_y: 0, inclination_z: 0 }, nodesData_clone[node].tbname, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
}, (index + 1) * 500);
|
}, (index + 1) * 500);
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,7 @@ exports.group = 'Worksys';
|
||||||
exports.color = '#888600';
|
exports.color = '#888600';
|
||||||
exports.version = '1.0.2';
|
exports.version = '1.0.2';
|
||||||
exports.icon = 'sign-out';
|
exports.icon = 'sign-out';
|
||||||
exports.input = 1;
|
exports.output = 2;
|
||||||
exports.output = ["blue"];
|
|
||||||
|
|
||||||
exports.html = `<div class="padding">
|
exports.html = `<div class="padding">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -33,6 +32,12 @@ exports.readme = `
|
||||||
|
|
||||||
const { promisifyBuilder, makeMapFromDbResult } = require('./helper/db_helper.js');
|
const { promisifyBuilder, makeMapFromDbResult } = require('./helper/db_helper.js');
|
||||||
const { initNotification } = require('./helper/notification_reporter');
|
const { initNotification } = require('./helper/notification_reporter');
|
||||||
|
const errorHandler = require('./helper/ErrorToServiceHandler');
|
||||||
|
|
||||||
|
const SEND_TO = {
|
||||||
|
db_init: 0,
|
||||||
|
infoSender: 1
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
exports.install = async function(instance) {
|
exports.install = async function(instance) {
|
||||||
|
|
@ -94,15 +99,26 @@ exports.install = async function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
FLOW.dbLoaded = true;
|
FLOW.dbLoaded = true;
|
||||||
|
errorHandler.setProjectId(dbs.settings.project_id);
|
||||||
initNotification();
|
initNotification();
|
||||||
|
|
||||||
|
//APP START - send to data services
|
||||||
|
const toService = {
|
||||||
|
id: dbs.settings.project_id,
|
||||||
|
name: dbs.settings.rvo_name,
|
||||||
|
fw_version: dbs.settings.edge_fw_version,
|
||||||
|
startdate: new Date().toISOString().slice(0, 19).replace('T', ' '),
|
||||||
|
js_error: "",
|
||||||
|
error_message: ""
|
||||||
|
};
|
||||||
|
|
||||||
|
instance.send(SEND_TO.infoSender, toService);
|
||||||
|
console.log("----------------> START - message send to service", toService);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log("DB_INIT - data loaded");
|
console.log("DB_INIT - data loaded");
|
||||||
instance.send(0, "_")
|
instance.send(SEND_TO.db_init, "_")
|
||||||
}, 5000)
|
}, 5000)
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,8 +49,8 @@
|
||||||
"component": "wsmqttpublish",
|
"component": "wsmqttpublish",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "WS MQTT publish",
|
"name": "WS MQTT publish",
|
||||||
"x": 304.75,
|
"x": 281.75,
|
||||||
"y": 237,
|
"y": 174,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -69,10 +69,6 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"2": [
|
"2": [
|
||||||
{
|
|
||||||
"index": "0",
|
|
||||||
"id": "1618300863816"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"index": "0",
|
"index": "0",
|
||||||
"id": "1634303685503"
|
"id": "1634303685503"
|
||||||
|
|
@ -107,8 +103,8 @@
|
||||||
"component": "virtualwirein",
|
"component": "virtualwirein",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "tb-push",
|
"name": "tb-push",
|
||||||
"x": 86.75,
|
"x": 72.75,
|
||||||
"y": 375,
|
"y": 328,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -144,8 +140,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "to TB",
|
"name": "to TB",
|
||||||
"x": 306.75,
|
"x": 283.75,
|
||||||
"y": 371,
|
"y": 324,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [
|
"input": [
|
||||||
|
|
@ -170,8 +166,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "errors from MQTT Broker",
|
"name": "errors from MQTT Broker",
|
||||||
"x": 650,
|
"x": 594,
|
||||||
"y": 76,
|
"y": 57,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [
|
"input": [
|
||||||
|
|
@ -270,8 +266,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "Debug",
|
"name": "Debug",
|
||||||
"x": 595.8833312988281,
|
"x": 596.8833312988281,
|
||||||
"y": 557.3500061035156,
|
"y": 566.3500061035156,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -294,8 +290,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "tempToTb",
|
"name": "tempToTb",
|
||||||
"x": 598.8833312988281,
|
"x": 595.8833312988281,
|
||||||
"y": 654.3500061035156,
|
"y": 658.3500061035156,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -318,8 +314,8 @@
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "tb-push",
|
"name": "tb-push",
|
||||||
"x": 594.8833312988281,
|
"x": 597.8833312988281,
|
||||||
"y": 350.25,
|
"y": 377.25,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -453,8 +449,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"data": "{line: 3, command: \"turnOff\", force: true}",
|
"datatype": "object",
|
||||||
"datatype": "object"
|
"data": "{line: 3, command: \"turnOff\", force: true}"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -505,8 +501,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"datatype": "string",
|
"data": "profile_nodes",
|
||||||
"data": "profile_nodes"
|
"datatype": "string"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -545,8 +541,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "wsmqtt-exit1",
|
"name": "wsmqtt-exit1",
|
||||||
"x": 650.8833312988281,
|
"x": 597.8833312988281,
|
||||||
"y": 160,
|
"y": 149,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -564,32 +560,6 @@
|
||||||
"color": "#967ADC",
|
"color": "#967ADC",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"id": "1618300863816",
|
|
||||||
"component": "debug",
|
|
||||||
"tab": "1612772287426",
|
|
||||||
"name": "wsmqtt-exit2",
|
|
||||||
"x": 845.8833312988281,
|
|
||||||
"y": 320,
|
|
||||||
"connections": {},
|
|
||||||
"disabledio": {
|
|
||||||
"input": [
|
|
||||||
0
|
|
||||||
],
|
|
||||||
"output": []
|
|
||||||
},
|
|
||||||
"state": {
|
|
||||||
"text": "Enabled",
|
|
||||||
"color": "gray"
|
|
||||||
},
|
|
||||||
"options": {
|
|
||||||
"type": "data",
|
|
||||||
"repository": false,
|
|
||||||
"enabled": true
|
|
||||||
},
|
|
||||||
"color": "#967ADC",
|
|
||||||
"notes": ""
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"id": "1618393583970",
|
"id": "1618393583970",
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
|
|
@ -701,8 +671,8 @@
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "platform-rpc-call",
|
"name": "platform-rpc-call",
|
||||||
"x": 649.8833312988281,
|
"x": 597.8833312988281,
|
||||||
"y": 246,
|
"y": 247,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -742,8 +712,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"datatype": "object",
|
"data": "{line: 1, command: \"turnOn\", force: true}",
|
||||||
"data": "{line: 1, command: \"turnOn\", force: true}"
|
"datatype": "object"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -872,8 +842,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"data": "{command: \"turnOnAlarm\"}",
|
"datatype": "object",
|
||||||
"datatype": "object"
|
"data": "{command: \"turnOnAlarm\"}"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -902,8 +872,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"data": "{command: \"turnOffAlarm\"}",
|
"datatype": "object",
|
||||||
"datatype": "object"
|
"data": "{command: \"turnOffAlarm\"}"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -913,8 +883,8 @@
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "modbus_to_dido",
|
"name": "modbus_to_dido",
|
||||||
"x": 596,
|
"x": 599,
|
||||||
"y": 462,
|
"y": 471,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -1039,7 +1009,7 @@
|
||||||
"output": []
|
"output": []
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "795.21 MB / 987.80 MB",
|
"text": "843.78 MB / 985.68 MB",
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
|
@ -1069,7 +1039,7 @@
|
||||||
"output": []
|
"output": []
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "5.50 GB / 7.26 GB",
|
"text": "5.68 GB / 7.26 GB",
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
|
@ -1140,8 +1110,8 @@
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "send-to-services",
|
"name": "send-to-services",
|
||||||
"x": 650.8833312988281,
|
"x": 600.8833312988281,
|
||||||
"y": 355.5,
|
"y": 341.5,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -1163,8 +1133,8 @@
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "192.168.252.2:8004/sentmessage",
|
"name": "192.168.252.2:8004/sentmessage",
|
||||||
"reference": "",
|
"reference": "",
|
||||||
"x": 480.8833312988281,
|
"x": 506.8833312988281,
|
||||||
"y": 1334.7333374023438,
|
"y": 1331.7333374023438,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -1182,9 +1152,9 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"stringify": "json",
|
"url": "http://192.168.252.2:8004/sentmessage",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "http://192.168.252.2:8004/sentmessage"
|
"stringify": "json"
|
||||||
},
|
},
|
||||||
"color": "#5D9CEC",
|
"color": "#5D9CEC",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -1194,8 +1164,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "Debug",
|
"name": "Debug",
|
||||||
"x": 280.75,
|
"x": 305.75,
|
||||||
"y": 1446,
|
"y": 1442,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [
|
"input": [
|
||||||
|
|
@ -1403,7 +1373,7 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "Send info",
|
"name": "Send info",
|
||||||
"x": 480,
|
"x": 513,
|
||||||
"y": 1441,
|
"y": 1441,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
|
|
@ -1429,8 +1399,8 @@
|
||||||
"component": "infosender",
|
"component": "infosender",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "Info sender",
|
"name": "Info sender",
|
||||||
"x": 285,
|
"x": 301,
|
||||||
"y": 1338,
|
"y": 1336,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -1462,8 +1432,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "Debug",
|
"name": "Debug",
|
||||||
"x": 795.8833312988281,
|
"x": 837.8833312988281,
|
||||||
"y": 1329.5,
|
"y": 1325.5,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [
|
"input": [
|
||||||
|
|
@ -1525,7 +1495,7 @@
|
||||||
"output": []
|
"output": []
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "1.2% / 70.53 MB",
|
"text": "2% / 86.44 MB",
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
|
@ -1885,8 +1855,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "MDBToTb",
|
"name": "MDBToTb",
|
||||||
"x": 759,
|
"x": 766,
|
||||||
"y": 313,
|
"y": 324,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -1909,8 +1879,8 @@
|
||||||
"component": "code",
|
"component": "code",
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "device-status",
|
"name": "device-status",
|
||||||
"x": 755.0833282470703,
|
"x": 764.0833282470703,
|
||||||
"y": 209,
|
"y": 222,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -1932,9 +1902,9 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"outputs": 1,
|
"keepmessage": true,
|
||||||
"code": "if(value.hasOwnProperty(\"status\"))\n{\n\tif(value.status.includes(\"-em\"))\n\t{\n\t\tsend(0, {\"em_status\": \"NOK\"});\n\t}\n\telse if(value.status.includes(\"twilight\"))\n\t{\n\t\tsend(0, {\"lux_sensor\": \"NOK\"});\n\t}\n\telse if(value.status === \"NOK-thermometer\")\n\t{\n\t\tsend(0, {\"thermometer\": \"NOK\"});\n\t}\n}\n\nif(value.hasOwnProperty(\"values\"))\n{\n\tif(value.values.hasOwnProperty(\"twilight_sensor\"))\n\t{\n\t\tsend(0, {\"lux_sensor\": \"OK\"});\n\t}\n\telse if(value.values.hasOwnProperty(\"Phase_1_power\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Phase_1_voltage\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Total_power\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Phase_1_current\"))\n\t{\n\t\tsend(0, {\"em_status\": \"OK\"});\n\t}\n\telse if(value.values.hasOwnProperty(\"temperature\"))\n\t{\n\t\tsend(0, {\"thermometer\": \"OK\"});\n\t}\n}",
|
"code": "if(value.hasOwnProperty(\"status\"))\n{\n\tif(value.status.includes(\"-em\"))\n\t{\n\t\tsend(0, {\"em_status\": \"NOK\"});\n\t}\n\telse if(value.status.includes(\"twilight\"))\n\t{\n\t\tsend(0, {\"lux_sensor\": \"NOK\"});\n\t}\n\telse if(value.status === \"NOK-thermometer\")\n\t{\n\t\tsend(0, {\"thermometer\": \"NOK\"});\n\t}\n}\n\nif(value.hasOwnProperty(\"values\"))\n{\n\tif(value.values.hasOwnProperty(\"twilight_sensor\"))\n\t{\n\t\tsend(0, {\"lux_sensor\": \"OK\"});\n\t}\n\telse if(value.values.hasOwnProperty(\"Phase_1_power\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Phase_1_voltage\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Total_power\") ||\n\t\t\tvalue.values.hasOwnProperty(\"Phase_1_current\"))\n\t{\n\t\tsend(0, {\"em_status\": \"OK\"});\n\t}\n\telse if(value.values.hasOwnProperty(\"temperature\"))\n\t{\n\t\tsend(0, {\"thermometer\": \"OK\"});\n\t}\n}",
|
||||||
"keepmessage": true
|
"outputs": 1
|
||||||
},
|
},
|
||||||
"color": "#656D78",
|
"color": "#656D78",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -1945,7 +1915,7 @@
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "modbus service",
|
"name": "modbus service",
|
||||||
"x": 966.0833282470703,
|
"x": 966.0833282470703,
|
||||||
"y": 152,
|
"y": 165,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [
|
"input": [
|
||||||
|
|
@ -2048,7 +2018,7 @@
|
||||||
"tag_on_include": "[{\"user_id\":\"U072JE5JUQG\", \"includes\":[\"Electrometer\", \"Twilight sensor\"]}]",
|
"tag_on_include": "[{\"user_id\":\"U072JE5JUQG\", \"includes\":[\"Electrometer\", \"Twilight sensor\"]}]",
|
||||||
"message_includes": "[\"is responding again\", \"Flow has been restarted\", \"Node db has changed\"]",
|
"message_includes": "[\"is responding again\", \"Flow has been restarted\", \"Node db has changed\"]",
|
||||||
"types": "[\"emergency\", \"critical\", \"error\", \"alert\"]",
|
"types": "[\"emergency\", \"critical\", \"error\", \"alert\"]",
|
||||||
"name": "rvo_senica_20_10.0.0.113"
|
"name": ""
|
||||||
},
|
},
|
||||||
"color": "#30E193",
|
"color": "#30E193",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -2077,9 +2047,9 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"stringify": "json",
|
"url": "http://192.168.252.2:8004/slack",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"url": "http://192.168.252.2:8004/slack"
|
"stringify": "json"
|
||||||
},
|
},
|
||||||
"color": "#5D9CEC",
|
"color": "#5D9CEC",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -2134,8 +2104,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"datatype": "object",
|
"data": "{ \"g9OxBZ5KRwNznlY6pAppqEAWXvjdEL4eGQobMDy2\": [ { \"ts\": 1716289039281, \"values\": { \"_event\": { \"type\": \"alert\", \"status\": \"new\", \"source\": { \"func\": \"CMD Manager: process cmd\", \"component\": \"1619515097737\", \"component_name\": \"CMD Manager\", \"edge\": \"g9OxBZ5KRwNznlY6pAppqEAWXvjdEL4eGQobMDy2\" }, \"message\": \"NOW CONNECTED TO SLACK !\", \"message_data\": \"\" } } } ] }",
|
||||||
"data": "{ \"g9OxBZ5KRwNznlY6pAppqEAWXvjdEL4eGQobMDy2\": [ { \"ts\": 1716289039281, \"values\": { \"_event\": { \"type\": \"alert\", \"status\": \"new\", \"source\": { \"func\": \"CMD Manager: process cmd\", \"component\": \"1619515097737\", \"component_name\": \"CMD Manager\", \"edge\": \"g9OxBZ5KRwNznlY6pAppqEAWXvjdEL4eGQobMDy2\" }, \"message\": \"NOW CONNECTED TO SLACK !\", \"message_data\": \"\" } } } ] }"
|
"datatype": "object"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -2145,7 +2115,7 @@
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "platform-rpc-call",
|
"name": "platform-rpc-call",
|
||||||
"x": 649.9333343505859,
|
"x": 599.9333343505859,
|
||||||
"y": 541.3500061035156,
|
"y": 541.3500061035156,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
|
|
@ -2167,8 +2137,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "rpc cloud",
|
"name": "rpc cloud",
|
||||||
"x": 650.9333343505859,
|
"x": 601.9333343505859,
|
||||||
"y": 451.3500061035156,
|
"y": 440.3500061035156,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -2191,8 +2161,8 @@
|
||||||
"component": "virtualwirein",
|
"component": "virtualwirein",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "db-init",
|
"name": "db-init",
|
||||||
"x": 90.75,
|
"x": 75.75,
|
||||||
"y": 250,
|
"y": 184,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2219,9 +2189,9 @@
|
||||||
"id": "1731068754606",
|
"id": "1731068754606",
|
||||||
"component": "cloudmqttconnect",
|
"component": "cloudmqttconnect",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "MQTT client - to senica-prod01",
|
"name": "MQTT to senica-prod01",
|
||||||
"x": 304.75,
|
"x": 284.75,
|
||||||
"y": 474,
|
"y": 452,
|
||||||
"connections": {
|
"connections": {
|
||||||
"1": [
|
"1": [
|
||||||
{
|
{
|
||||||
|
|
@ -2257,14 +2227,20 @@
|
||||||
"component": "db_init",
|
"component": "db_init",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "DB Initialization",
|
"name": "DB Initialization",
|
||||||
"x": 91.75,
|
"x": 1003.75,
|
||||||
"y": 55.25,
|
"y": 240.25,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
"index": "0",
|
"index": "0",
|
||||||
"id": "1731069033416"
|
"id": "1731069033416"
|
||||||
}
|
}
|
||||||
|
],
|
||||||
|
"1": [
|
||||||
|
{
|
||||||
|
"index": "0",
|
||||||
|
"id": "1747561603739"
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
|
|
@ -2284,8 +2260,8 @@
|
||||||
"component": "virtualwireout",
|
"component": "virtualwireout",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "db-init",
|
"name": "db-init",
|
||||||
"x": 343.75,
|
"x": 1244.75,
|
||||||
"y": 50.25,
|
"y": 233.25,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -2798,7 +2774,7 @@
|
||||||
"tab": "1611921777196",
|
"tab": "1611921777196",
|
||||||
"name": "tempToDido",
|
"name": "tempToDido",
|
||||||
"x": 594.8833312988281,
|
"x": 594.8833312988281,
|
||||||
"y": 745,
|
"y": 753,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -2821,8 +2797,8 @@
|
||||||
"component": "virtualwirein",
|
"component": "virtualwirein",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "db-init",
|
"name": "db-init",
|
||||||
"x": 86.75,
|
"x": 72.75,
|
||||||
"y": 495,
|
"y": 474,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2844,6 +2820,48 @@
|
||||||
},
|
},
|
||||||
"color": "#303E4D",
|
"color": "#303E4D",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1747561603739",
|
||||||
|
"component": "virtualwireout",
|
||||||
|
"tab": "1612772287426",
|
||||||
|
"name": "send-to-services",
|
||||||
|
"x": 1243.8833312988281,
|
||||||
|
"y": 334.5,
|
||||||
|
"connections": {},
|
||||||
|
"disabledio": {
|
||||||
|
"input": [],
|
||||||
|
"output": []
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"text": "send-to-services",
|
||||||
|
"color": "gray"
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"wirename": "send-to-services"
|
||||||
|
},
|
||||||
|
"color": "#303E4D",
|
||||||
|
"notes": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1747562867845",
|
||||||
|
"component": "comment",
|
||||||
|
"tab": "1612772287426",
|
||||||
|
"name": "FLOW STARTING POINT",
|
||||||
|
"x": 1003.5666656494141,
|
||||||
|
"y": 178,
|
||||||
|
"connections": {},
|
||||||
|
"disabledio": {
|
||||||
|
"input": [],
|
||||||
|
"output": []
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"text": "",
|
||||||
|
"color": "gray"
|
||||||
|
},
|
||||||
|
"options": {},
|
||||||
|
"color": "#704cff",
|
||||||
|
"notes": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": 615
|
"version": 615
|
||||||
|
|
|
||||||
|
|
@ -58,8 +58,7 @@ const bitwise = require('bitwise');
|
||||||
const DataToTbHandler = require('./helper/DataToTbHandler');
|
const DataToTbHandler = require('./helper/DataToTbHandler');
|
||||||
let tbHandler;
|
let tbHandler;
|
||||||
|
|
||||||
const ErrorToServiceHandler = require('./helper/ErrorToServiceHandler');
|
const errorHandler = require('./helper/ErrorToServiceHandler');
|
||||||
const errorHandler = new ErrorToServiceHandler();
|
|
||||||
|
|
||||||
let ws = null;
|
let ws = null;
|
||||||
let rsPort = null;
|
let rsPort = null;
|
||||||
|
|
@ -741,7 +740,7 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function getPins(controllerType, hasMainSwitch) {
|
function pinsForRvoStatus(controllerType, hasMainSwitch) {
|
||||||
|
|
||||||
let pins = [];
|
let pins = [];
|
||||||
|
|
||||||
|
|
@ -774,7 +773,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
if (status === "OK") {
|
if (status === "OK") {
|
||||||
|
|
||||||
let pinIndexes = getPins(controller_type, hasMainSwitch);
|
let pinIndexes = pinsForRvoStatus(controller_type, hasMainSwitch);
|
||||||
|
|
||||||
for (const pinIndex of pinIndexes) {
|
for (const pinIndex of pinIndexes) {
|
||||||
if (previousValues[pinIndex] === 0) {
|
if (previousValues[pinIndex] === 0) {
|
||||||
|
|
@ -914,21 +913,25 @@ exports.install = function(instance) {
|
||||||
else if (type == "door_condition" || type === "state_of_main_switch") {
|
else if (type == "door_condition" || type === "state_of_main_switch") {
|
||||||
newPinValue === 0 ? value = "open" : value = "closed";
|
newPinValue === 0 ? value = "open" : value = "closed";
|
||||||
|
|
||||||
if (value === "open" && SETTINGS.maintenance_mode) {
|
let door = "door_main";
|
||||||
sendNotification("switchLogic", rvoTbName, "door_opened", {}, "", SEND_TO.tb, instance, "rvo_door");
|
if (type === "state_of_main_switch") door = "door_em";
|
||||||
|
|
||||||
|
if (value === "open") {
|
||||||
|
if (SETTINGS.maintenance_mode) {
|
||||||
|
sendNotification("switchLogic", rvoTbName, door + "_open", {}, "", SEND_TO.tb, instance, door);
|
||||||
|
} else {
|
||||||
|
sendNotification("switchLogic", rvoTbName, door + "_open_without_permission", {}, "", SEND_TO.tb, instance, door);
|
||||||
|
|
||||||
|
// zapneme sirenu
|
||||||
|
// ak sa otvoria dvere len na elektromeri (type === "state_of_main_switch") alarm sa nema spustit. alarm sa spusti len ked sa otvoria hlavne dvere (type === "door_condition")
|
||||||
|
if (type === "door_condition") turnAlarm("on");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (value === "open" && !SETTINGS.maintenance_mode) {
|
|
||||||
sendNotification("switchLogic", rvoTbName, "door_opened_without_permission", {}, "", SEND_TO.tb, instance, "rvo_door");
|
|
||||||
|
|
||||||
// zapneme sirenu
|
|
||||||
// ak sa otvoria dvere len na elektromeri (type === "state_of_main_switch") alarm sa nema spustit. alarm sa spusti len ked sa otvoria hlavne dvere (type === "door_condition")
|
|
||||||
if (type === "door_condition") turnAlarm("on");
|
|
||||||
}
|
|
||||||
|
|
||||||
if (value === "closed") {
|
if (value === "closed") {
|
||||||
if (alarmStatus == "ON") turnAlarm("off");
|
if (alarmStatus == "ON") turnAlarm("off");
|
||||||
sendNotification("switchLogic", rvoTbName, "door_closed", {}, "", SEND_TO.tb, instance, "rvo_door");
|
sendNotification("switchLogic", rvoTbName, door + "_close", {}, "", SEND_TO.tb, instance, door);
|
||||||
}
|
}
|
||||||
|
|
||||||
deviceStatus[type] = value;
|
deviceStatus[type] = value;
|
||||||
|
|
@ -1011,34 +1014,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "reload_relays", line: line, value: value, dataChanged: dataChanged });
|
instance.send(SEND_TO.cmd_manager, { sender: "dido_controller", cmd: "reload_relays", line: line, value: value, dataChanged: dataChanged });
|
||||||
reportLineStatus(line);
|
reportLineStatus(line);
|
||||||
|
|
||||||
//modify table relays
|
|
||||||
// dbRelays.modify({ contactor: newPinValue }).where("line", line).make(function(builder) {
|
|
||||||
// builder.callback(function(err, response) {
|
|
||||||
// if(!err)
|
|
||||||
// {
|
|
||||||
// let time = 0;
|
|
||||||
// if(value) time = 1000 * 10;//10 sekund
|
|
||||||
|
|
||||||
// let dataChanged = false;
|
|
||||||
// if(relaysData[line].contactor != newPinValue) dataChanged = true;
|
|
||||||
// relaysData[line].contactor = newPinValue; // 0,1
|
|
||||||
|
|
||||||
// //ak bola predchadzajuci stav off a novy stav je on, budu sa nastavovat nespracovane node profiles
|
|
||||||
// //a budu sa odosielat commandy, tie vsak mozu zlyhat, a preto potrebujeme ich spusti trochu neskor
|
|
||||||
// setTimeout(function(){
|
|
||||||
// instance.send(SEND_TO.cmd_manager, {sender: "dido_controller", cmd: "reload_relays", line: line, time: time, value: value, dataChanged: dataChanged});
|
|
||||||
// }, time);
|
|
||||||
|
|
||||||
// reportLineStatus(line);
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// errLogger.error("modify table relays failed", err);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// });
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (type === "state_of_breaker") {
|
else if (type === "state_of_breaker") {
|
||||||
|
|
|
||||||
|
|
@ -1,126 +1,91 @@
|
||||||
const { MD5 } = require('./md5.js');
|
const { MD5 } = require('./md5.js');
|
||||||
const { networkInterfaces } = require('os');
|
const { networkInterfaces } = require('os');
|
||||||
|
|
||||||
class ErrorToServiceHandler
|
class ErrorToServiceHandler {
|
||||||
{
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.previousValues = {};
|
this.previousValues = {};
|
||||||
|
|
||||||
this.projects_id = undefined;
|
this.project_id = undefined;
|
||||||
|
|
||||||
const nets = networkInterfaces();
|
const nets = networkInterfaces();
|
||||||
this.ipAddresses = Object.create(null); // Or just '{}', an empty object
|
this.ipAddresses = {};
|
||||||
|
|
||||||
for (const name of Object.keys(nets)) {
|
for (const name of Object.keys(nets)) {
|
||||||
for (const net of nets[name]) {
|
for (const net of nets[name]) {
|
||||||
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
||||||
if (net.family === 'IPv4' && !net.internal) {
|
if (net.family === 'IPv4' && !net.internal) {
|
||||||
if (!this.ipAddresses[name]) {
|
if (!this.ipAddresses[name]) {
|
||||||
this.ipAddresses[name] = [];
|
this.ipAddresses[name] = [];
|
||||||
}
|
}
|
||||||
this.ipAddresses[name].push(net.address);
|
this.ipAddresses[name].push(net.address);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//console.log(this.ipAddresses);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setProjectsId(projects_id)
|
setProjectId(project_id) {
|
||||||
{
|
this.project_id = project_id;
|
||||||
this.projects_id = projects_id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
processMessage(message, seconds, message_type)
|
processMessage(message, seconds) {
|
||||||
{
|
if (Array.isArray(message)) message = message.join(', ');
|
||||||
if(message_type == undefined) message_type = "error_message";
|
|
||||||
if(Array.isArray(message)) message = message.join(', ');
|
|
||||||
|
|
||||||
let key = MD5(message);
|
|
||||||
let timestamp = new Date().getTime();
|
|
||||||
|
|
||||||
//keep in memory - default value is 1h
|
|
||||||
if (seconds === undefined) seconds = 60*60;
|
|
||||||
|
|
||||||
if(!this.previousValues.hasOwnProperty(key))
|
|
||||||
{
|
|
||||||
this.previousValues[key] = {ts: timestamp, duration: seconds};
|
|
||||||
}
|
|
||||||
|
|
||||||
let diff = (timestamp - this.previousValues[key].ts);
|
|
||||||
if(diff < this.previousValues[key].duration*1000) return false;
|
|
||||||
|
|
||||||
this.previousValues[key].ts = timestamp;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
sendMessageToService(message, seconds, message_type)
|
|
||||||
{
|
|
||||||
|
|
||||||
let f = this.processMessage(message, seconds, message_type);
|
|
||||||
if(!f) return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
//-------------
|
|
||||||
if(message_type == undefined) message_type = "error_message";
|
|
||||||
if(Array.isArray(message)) message = message.join(', ');
|
|
||||||
|
|
||||||
let key = MD5(message);
|
let key = MD5(message);
|
||||||
let timestamp = new Date().getTime();
|
let ts = Date.now();
|
||||||
|
|
||||||
//keep in memory
|
//keep in memory - default value is 1h
|
||||||
if (seconds === undefined) seconds = 60*60;
|
if (seconds === undefined) seconds = 60 * 60;
|
||||||
|
|
||||||
if(!this.previousValues.hasOwnProperty(key))
|
if (!this.previousValues.hasOwnProperty(key)) {
|
||||||
{
|
this.previousValues[key] = { ts: ts, duration: seconds };
|
||||||
this.previousValues[key] = {ts: timestamp, duration: seconds};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let diff = (timestamp - this.previousValues[key].ts);
|
let diff = (ts - this.previousValues[key].ts);
|
||||||
if(diff < this.previousValues[key].duration*1000) return;
|
if (diff < this.previousValues[key].duration * 1000) return false;
|
||||||
|
|
||||||
this.previousValues[key].ts = timestamp;
|
this.previousValues[key].ts = ts;
|
||||||
*/
|
|
||||||
|
|
||||||
//-------------------------
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
//send to service
|
sendMessageToService(message, seconds, message_type) {
|
||||||
|
|
||||||
let dataToInfoSender = {id: this.projects_id};
|
// if error occures too early FLOW.GLOBALS.settings.project_id is still undefined
|
||||||
|
if (this.project_id === undefined) {
|
||||||
|
console.log("ErrorToServiceHandler.js: no project_id");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
let f = this.processMessage(message, seconds);
|
||||||
|
if (f === false) return;
|
||||||
|
|
||||||
|
if (message_type === undefined) message_type = "error_message";
|
||||||
|
|
||||||
|
let toService = {
|
||||||
|
id: this.project_id,
|
||||||
|
ipAddresses: this.ipAddresses
|
||||||
|
};
|
||||||
|
|
||||||
//js_error || error_message
|
//js_error || error_message
|
||||||
dataToInfoSender[message_type] = message;
|
toService[message_type] = message;
|
||||||
dataToInfoSender.ipAddresses = this.ipAddresses;
|
|
||||||
|
|
||||||
console.log("ErrorToServiceHandler------------------------>send to service", dataToInfoSender);
|
console.log("ErrorToServiceHandler------------------------>send to service", toService);
|
||||||
|
|
||||||
//TODO UGLY!!!
|
|
||||||
// if error occures too early FLOW.GLOBALs.settings.project_id is still undefined
|
|
||||||
// if(this.projects_id === undefined) this.projects_id = FLOW.GLOBALS.settings.project_id;
|
|
||||||
if(this.projects_id === undefined) return;
|
|
||||||
|
|
||||||
/*
|
|
||||||
if(this.projects_id === undefined)
|
|
||||||
{
|
|
||||||
console.log("this.projects_id is undefined");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
RESTBuilder.make(function(builder) {
|
RESTBuilder.make(function(builder) {
|
||||||
builder.method('POST');
|
builder.method('POST');
|
||||||
builder.post(dataToInfoSender);
|
builder.post(toService);
|
||||||
builder.url('http://192.168.252.2:8004/sentmessage');
|
builder.url('http://192.168.252.2:8004/sentmessage');
|
||||||
|
|
||||||
builder.callback(function(err, response, output) {
|
builder.callback(function(err, response, output) {
|
||||||
console.log("process.on error send", err, response, output, dataToInfoSender);
|
console.log("process.on error send", err, response, output, toService);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ErrorToServiceHandler;
|
const errorHandler = new ErrorToServiceHandler();
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = errorHandler;
|
||||||
|
//module.exports = ErrorToServiceHandler;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
//key is device, value = str
|
//key is device, value = message {}
|
||||||
let sentValues= {};
|
let sentValues = {};
|
||||||
let notificationsData = null;
|
let notificationsData = null;
|
||||||
|
let rvoName;
|
||||||
|
|
||||||
|
//sendNotification("CMD Manager: process cmd", SETTINGS.rvoTbName, "dimming_profile_was_successfully_received_by_node", { node: node }, "", SEND_TO.tb, instance);
|
||||||
|
|
||||||
let ERRWEIGHT = {
|
let ERRWEIGHT = {
|
||||||
EMERGENCY: "emergency", // System unusable
|
EMERGENCY: "emergency", // System unusable
|
||||||
|
|
@ -23,82 +26,67 @@ var template = (tpl, args) => tpl.replace(/\${(\w+)}/g, (_, v) => args[v]);
|
||||||
|
|
||||||
function initNotification() {
|
function initNotification() {
|
||||||
notificationsData = FLOW.GLOBALS.notificationsData;
|
notificationsData = FLOW.GLOBALS.notificationsData;
|
||||||
|
rvoName = FLOW.GLOBALS.settings.rvo_name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendNotification(func, device, key, params, extra, tb_output, instance, saveKey) {
|
function sendNotification(func, device, key, params, extra, tb_output, instance, saveKey) {
|
||||||
|
|
||||||
// return;
|
|
||||||
|
|
||||||
let storeToSendValues = true;
|
let storeToSendValues = true;
|
||||||
if(saveKey == undefined) storeToSendValues = false;
|
if (saveKey == undefined) storeToSendValues = false;
|
||||||
|
|
||||||
let lang = FLOW.GLOBALS.settings.language;
|
|
||||||
if(lang != "en" || lang != "sk") lang = "en";
|
|
||||||
|
|
||||||
let tpl = key;
|
|
||||||
let weight = "";
|
let weight = "";
|
||||||
|
let message = {};
|
||||||
|
|
||||||
if(notificationsData[key])
|
let notification = notificationsData[key];
|
||||||
{
|
|
||||||
weight = notificationsData[key].weight;
|
|
||||||
weight = weight.toLowerCase();
|
|
||||||
|
|
||||||
tpl = notificationsData[key][lang];
|
if (notification) {
|
||||||
tpl = template(tpl, params);
|
weight = notification.weight.toLowerCase();
|
||||||
|
|
||||||
|
Object.keys(notification).forEach(item => {
|
||||||
|
if (["en", "sk", "de", "cz", "it", "es"].includes(item)) {
|
||||||
|
message[item] = rvoName + ": " + template(notification[item], params);
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
//console.error("sendNotification: Notifications: undefined key", key, func, notificationsData);
|
//console.error("sendNotification: Notifications: undefined key", key, func, notificationsData);
|
||||||
console.error("sendNotification: Notifications: undefined key", key, func );
|
console.error("sendNotification: Notifications: undefined key", key, func);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//detect invalid err weight
|
//detect invalid err weight
|
||||||
if(getKey(ERRWEIGHT, weight) == undefined)
|
if (getKey(ERRWEIGHT, weight) == undefined) {
|
||||||
{
|
|
||||||
console.error("sendNotification: Notifications: undefined weight", weight, key, func);
|
console.error("sendNotification: Notifications: undefined weight", weight, key, func);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sentValues.hasOwnProperty(saveKey))
|
if (sentValues.hasOwnProperty(saveKey)) {
|
||||||
{
|
if (JSON.stringify(sentValues[saveKey]) == JSON.stringify(message)) {
|
||||||
if(sentValues[saveKey] == tpl)
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sentValues[saveKey] == undefined)
|
if (sentValues[saveKey] == undefined) {
|
||||||
{
|
if (storeToSendValues) {
|
||||||
if(storeToSendValues)
|
|
||||||
{
|
|
||||||
//do not send - flow is was started
|
//do not send - flow is was started
|
||||||
sentValues[saveKey] = tpl;
|
sentValues[saveKey] = message;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(saveKey == "rvo_door")
|
if (storeToSendValues) sentValues[saveKey] = message;
|
||||||
{
|
|
||||||
//console.log("******", saveKey, sentValues[saveKey], tpl);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(storeToSendValues) sentValues[saveKey] = tpl;
|
|
||||||
|
|
||||||
let str = FLOW.GLOBALS.settings.rvo_name;
|
|
||||||
if(str != "") str = str + ": ";
|
|
||||||
str = str + tpl;
|
|
||||||
|
|
||||||
let content = {
|
let content = {
|
||||||
"type": weight,
|
"type": weight,
|
||||||
"status": "new",
|
"status": "new",
|
||||||
"source": {
|
"source": {
|
||||||
"func":func,
|
"func": func,
|
||||||
"component":instance.id,
|
"component": instance.id,
|
||||||
"component_name":instance.name,
|
"component_name": instance.name,
|
||||||
"edge":device
|
"edge": device
|
||||||
},
|
},
|
||||||
"message":str,
|
"message": message,
|
||||||
"message_data": extra
|
"message_data": extra
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -107,7 +95,7 @@ function sendNotification(func, device, key, params, extra, tb_output, instance,
|
||||||
{
|
{
|
||||||
"ts": Date.now(),
|
"ts": Date.now(),
|
||||||
"values": {
|
"values": {
|
||||||
"_event":content
|
"_event": content
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
@ -118,6 +106,7 @@ function sendNotification(func, device, key, params, extra, tb_output, instance,
|
||||||
} else {
|
} else {
|
||||||
bufferError(msg);
|
bufferError(msg);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
instance.send(tb_output, msg); // Even if error server is unavailable, send this message to output, for other possible component connections
|
instance.send(tb_output, msg); // Even if error server is unavailable, send this message to output, for other possible component connections
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -129,3 +118,4 @@ module.exports = {
|
||||||
ERRWEIGHT,
|
ERRWEIGHT,
|
||||||
initNotification
|
initNotification
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|
||||||
function openPort(port){
|
function openPort(port) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
var callbackError = function(err) {
|
var callbackError = function(err) {
|
||||||
|
|
@ -25,24 +25,24 @@ function openPort(port){
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function runSyncExec(command){
|
function runSyncExec(command) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
exec(command, (error, stdout, stderr) => {
|
exec(command, (error, stdout, stderr) => {
|
||||||
if(error == null) resolve(stdout);
|
if (error == null) resolve(stdout);
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function writeData(port, data, readbytes, timeout){
|
async function writeData(port, data, readbytes, timeout) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
|
||||||
// If first item in data array is 255, we just write broadcast command to rsPort
|
// If first item in data array is 255, we just write broadcast command to rsPort
|
||||||
// We wait 3 seconds and resolve(["broadcast"])
|
// We wait 3 seconds and resolve(["broadcast"])
|
||||||
// It is important to resolve with array
|
// It is important to resolve with array
|
||||||
if(data[0] == 255) {
|
if (data[0] == 255) {
|
||||||
|
|
||||||
port.write(Buffer.from(data), function(err) {
|
port.write(Buffer.from(data), function(err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
|
|
@ -60,8 +60,7 @@ async function writeData(port, data, readbytes, timeout){
|
||||||
rsPortReceivedData.push(...data);
|
rsPortReceivedData.push(...data);
|
||||||
let l = rsPortReceivedData.length;
|
let l = rsPortReceivedData.length;
|
||||||
|
|
||||||
if(l >= readbytes)
|
if (l >= readbytes) {
|
||||||
{
|
|
||||||
port.removeListener('data', callback);
|
port.removeListener('data', callback);
|
||||||
|
|
||||||
clearTimeout(t);
|
clearTimeout(t);
|
||||||
|
|
|
||||||
|
|
@ -33,39 +33,28 @@ exports.install = function(instance) {
|
||||||
let ipAddresses = Object.create(null); // Or just '{}', an empty object
|
let ipAddresses = Object.create(null); // Or just '{}', an empty object
|
||||||
|
|
||||||
for (const name of Object.keys(nets)) {
|
for (const name of Object.keys(nets)) {
|
||||||
for (const net of nets[name]) {
|
for (const net of nets[name]) {
|
||||||
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
// Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
|
||||||
if (net.family === 'IPv4' && !net.internal) {
|
if (net.family === 'IPv4' && !net.internal) {
|
||||||
if (!ipAddresses[name]) {
|
if (!ipAddresses[name]) {
|
||||||
ipAddresses[name] = [];
|
ipAddresses[name] = [];
|
||||||
}
|
}
|
||||||
ipAddresses[name].push(net.address);
|
ipAddresses[name].push(net.address);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendValues()
|
function sendValues() {
|
||||||
{
|
if (!configured) return;
|
||||||
if(!configured) return;
|
|
||||||
|
|
||||||
if(Object.keys(allValues).length > 0)
|
if (Object.keys(allValues).length > 0) {
|
||||||
{
|
let dataToSend = { ...allValues };
|
||||||
if(id)
|
dataToSend.id = id;
|
||||||
{
|
dataToSend.ipAddresses = ipAddresses;
|
||||||
delete allValues.__force__;
|
|
||||||
let dataToSend = {...allValues};
|
|
||||||
dataToSend.id = id;
|
|
||||||
dataToSend.ipAddresses = ipAddresses;
|
|
||||||
|
|
||||||
instance.send(0, dataToSend);
|
instance.send(0, dataToSend);
|
||||||
|
|
||||||
allValues = {};
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
console.log(exports.title, "unable to send data, no id");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
allValues = {};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -75,27 +64,18 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
instance.on("0", _ => {
|
instance.on("0", _ => {
|
||||||
id = FLOW.GLOBALS.settings.project_id;
|
id = FLOW.GLOBALS.settings.project_id;
|
||||||
configured = true;
|
if (id) configured = true;
|
||||||
|
else console.log(exports.title, "InfoSender: Unable to send data, no id");
|
||||||
})
|
})
|
||||||
|
|
||||||
instance.on("1", flowdata => {
|
instance.on("1", flowdata => {
|
||||||
|
allValues = { ...allValues, ...flowdata.data };
|
||||||
allValues = { ...allValues, ...flowdata.data};
|
|
||||||
//console.log("DATA RECEIVED", flowdata.data);
|
//console.log("DATA RECEIVED", flowdata.data);
|
||||||
|
|
||||||
//__force__
|
|
||||||
if(flowdata.data.hasOwnProperty("__force__"))
|
|
||||||
{
|
|
||||||
if(flowdata.data.__force__)
|
|
||||||
{
|
|
||||||
sendValues();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
sendAllValuesInterval = setInterval(() => {
|
sendAllValuesInterval = setInterval(() => {
|
||||||
sendValues();
|
sendValues();
|
||||||
}, 60000*3);
|
}, 60000 * 3);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -332,8 +332,6 @@ exports.install = function(instance) {
|
||||||
noVoltage = FLOW.GLOBALS.settings.no_voltage;
|
noVoltage = FLOW.GLOBALS.settings.no_voltage;
|
||||||
mainSocket = new SocketWithClients();
|
mainSocket = new SocketWithClients();
|
||||||
|
|
||||||
console.log("novoltage: ", noVoltage, typeof noVoltage);
|
|
||||||
|
|
||||||
// this notification is to show, that flow (unipi) has been restarted
|
// this notification is to show, that flow (unipi) has been restarted
|
||||||
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
|
sendNotification("modbus_reader", tbName, "flow_restart", {}, "", SEND_TO.slack, instance);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ exports.output = 1;
|
||||||
exports.author = 'Jakub Klena';
|
exports.author = 'Jakub Klena';
|
||||||
exports.icon = 'plug';
|
exports.icon = 'plug';
|
||||||
exports.version = '1.0.8';
|
exports.version = '1.0.8';
|
||||||
exports.options = { 'name':'', 'types': '["emergency", "critical", "error", "alert"]', 'message_includes':'["is responding again"]', 'tag_on_include':'[{"user_id":"U072JE5JUQG", "includes":["Electrometer", "Twilight sensor"]}]', 'slack_channel':'' };
|
exports.options = { 'name': '', 'types': '["emergency", "critical", "error", "alert"]', 'message_includes': '["is responding again"]', 'tag_on_include': '[{"user_id":"U072JE5JUQG", "includes":["Electrometer", "Twilight sensor"]}]', 'slack_channel': '' };
|
||||||
|
|
||||||
exports.html = `<div class="padding">
|
exports.html = `<div class="padding">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
|
|
@ -57,11 +57,11 @@ exports.install = function(instance) {
|
||||||
let icon = ':totaljs:';
|
let icon = ':totaljs:';
|
||||||
let type = value[k[0]][0]['values']['_event']['type'];
|
let type = value[k[0]][0]['values']['_event']['type'];
|
||||||
let source = value[k[0]][0]['values']['_event']['source']['func'];
|
let source = value[k[0]][0]['values']['_event']['source']['func'];
|
||||||
let message = value[k[0]][0]['values']['_event']['message'];
|
let message = value[k[0]][0]['values']['_event']['message']['en'];
|
||||||
let message_data = value[k[0]][0]['values']['_event']['message_data'];
|
let message_data = value[k[0]][0]['values']['_event']['message_data'];
|
||||||
let tag = '';
|
let tag = '';
|
||||||
|
|
||||||
switch(type){
|
switch (type) {
|
||||||
case 'debug':
|
case 'debug':
|
||||||
icon = ':beetle:';
|
icon = ':beetle:';
|
||||||
break;
|
break;
|
||||||
|
|
@ -89,15 +89,15 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if this message includes one of the strings we are watching for
|
// Check if this message includes one of the strings we are watching for
|
||||||
for (const msg of msg_incl){
|
for (const msg of msg_incl) {
|
||||||
if (message.includes(msg)){
|
if (message.includes(msg)) {
|
||||||
if (msg == 'is responding again') icon = ':large_green_circle:';
|
if (msg == 'is responding again') icon = ':large_green_circle:';
|
||||||
can = true;
|
can = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Check if message is one of the types we are watching for
|
// Check if message is one of the types we are watching for
|
||||||
if (interested.includes(type)){
|
if (interested.includes(type)) {
|
||||||
can = true;
|
can = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -105,10 +105,10 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
|
|
||||||
// Check for each person tags based on what the message includes
|
// Check for each person tags based on what the message includes
|
||||||
for (const person of tags){
|
for (const person of tags) {
|
||||||
for (const msg of person.includes){
|
for (const msg of person.includes) {
|
||||||
if (message.includes(msg)){
|
if (message.includes(msg)) {
|
||||||
tag += '<@'+person.user_id+'> ';
|
tag += '<@' + person.user_id + '> ';
|
||||||
break; // Break out from this person checks as they are already tagged now
|
break; // Break out from this person checks as they are already tagged now
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -116,46 +116,46 @@ exports.install = function(instance) {
|
||||||
// Now that all people are tagged add new line symbol
|
// Now that all people are tagged add new line symbol
|
||||||
if (tag != '') tag += '\n';
|
if (tag != '') tag += '\n';
|
||||||
|
|
||||||
let send_data = tag+instance.options.name+' '+type.toUpperCase()+'\n*Source*: '+source+'\n*Message*: '+message;
|
let send_data = tag + instance.options.name + ' ' + type.toUpperCase() + '\n*Source*: ' + source + '\n*Message*: ' + message;
|
||||||
if (message_data) {
|
if (message_data) {
|
||||||
send_data += '\nData: '+message_data;
|
send_data += '\nData: ' + message_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ignore_msg = false
|
let ignore_msg = false
|
||||||
if (message.includes('Configuration of dimming profile to node no')){
|
if (message.includes('Configuration of dimming profile to node no')) {
|
||||||
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++){
|
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++) {
|
||||||
if (FLOW["savedSlackMessages"][i].message == message){
|
if (FLOW["savedSlackMessages"][i].message == message) {
|
||||||
ignore_msg = true;
|
ignore_msg = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!ignore_msg){
|
if (!ignore_msg) {
|
||||||
FLOW["savedSlackMessages"].push({message, 'dateandtime': Date.now()});
|
FLOW["savedSlackMessages"].push({ message, 'dateandtime': Date.now() });
|
||||||
if (timer === null){
|
if (timer === null) {
|
||||||
timer = setTimeout(checkSavedMessages, 60*60000);
|
timer = setTimeout(checkSavedMessages, 60 * 60000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ignore_msg){
|
if (!ignore_msg) {
|
||||||
instance.send2({'msg':send_data,'bot_name':instance.options.name+' '+type.toUpperCase(),'bot_icon':icon,'channel':instance.options.slack_channel});
|
instance.send2({ 'msg': send_data, 'bot_name': instance.options.name + ' ' + type.toUpperCase(), 'bot_icon': icon, 'channel': instance.options.slack_channel });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function checkSavedMessages(){
|
function checkSavedMessages() {
|
||||||
var d = Date.now();
|
var d = Date.now();
|
||||||
d = d - 86400000; // older then 24hr
|
d = d - 86400000; // older then 24hr
|
||||||
var a = [];
|
var a = [];
|
||||||
//Remove msgs older then 24hr
|
//Remove msgs older then 24hr
|
||||||
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++){
|
for (let i = 0; i < FLOW["savedSlackMessages"].length; i++) {
|
||||||
if (FLOW["savedSlackMessages"][i].dateandtime > d){
|
if (FLOW["savedSlackMessages"][i].dateandtime > d) {
|
||||||
a.push(FLOW["savedSlackMessages"][i]);
|
a.push(FLOW["savedSlackMessages"][i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FLOW["savedSlackMessages"] = a;
|
FLOW["savedSlackMessages"] = a;
|
||||||
|
|
||||||
if (FLOW["savedSlackMessages"].length > 0) {
|
if (FLOW["savedSlackMessages"].length > 0) {
|
||||||
timer = setTimeout(checkSavedMessages, 60*60000);
|
timer = setTimeout(checkSavedMessages, 60 * 60000);
|
||||||
} else {
|
} else {
|
||||||
timer = null;
|
timer = null;
|
||||||
}
|
}
|
||||||
|
|
@ -163,7 +163,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
instance.reconfigure = function() {
|
instance.reconfigure = function() {
|
||||||
try {
|
try {
|
||||||
if (!FLOW["savedSlackMessages"]){
|
if (!FLOW["savedSlackMessages"]) {
|
||||||
FLOW["savedSlackMessages"] = [];
|
FLOW["savedSlackMessages"] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -183,5 +183,4 @@ exports.install = function(instance) {
|
||||||
instance.on('options', instance.reconfigure);
|
instance.on('options', instance.reconfigure);
|
||||||
setTimeout(instance.reconfigure, 10000);
|
setTimeout(instance.reconfigure, 10000);
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ let saveTelemetryOnError = true;//backup_on_failure overrides this value
|
||||||
//------------------------
|
//------------------------
|
||||||
|
|
||||||
let rollers;
|
let rollers;
|
||||||
if(createTelemetryBackup) rollers = require('streamroller');
|
if (createTelemetryBackup) rollers = require('streamroller');
|
||||||
|
|
||||||
const noSqlFileSizeLimit = 4194304;//use 5MB - 4194304
|
const noSqlFileSizeLimit = 4194304;//use 5MB - 4194304
|
||||||
let insertNoSqlCounter = 0;
|
let insertNoSqlCounter = 0;
|
||||||
|
|
@ -70,7 +70,7 @@ let lastRestoreTime = 0;
|
||||||
// if there is an error in client connection, flow logs to monitor.txt. Not to log messages every second, we use sendClientError variable
|
// if there is an error in client connection, flow logs to monitor.txt. Not to log messages every second, we use sendClientError variable
|
||||||
let sendClientError = true;
|
let sendClientError = true;
|
||||||
|
|
||||||
process.on('uncaughtException', function (err) {
|
process.on('uncaughtException', function(err) {
|
||||||
|
|
||||||
errLogger.error('uncaughtException:', err.message)
|
errLogger.error('uncaughtException:', err.message)
|
||||||
errLogger.error(err.stack);
|
errLogger.error(err.stack);
|
||||||
|
|
@ -96,22 +96,19 @@ exports.install = function(instance) {
|
||||||
let sendWsStatusVar = null;
|
let sendWsStatusVar = null;
|
||||||
let wsmqtt_status = 'disconnected';
|
let wsmqtt_status = 'disconnected';
|
||||||
|
|
||||||
function getWsmqttName(host)
|
function getWsmqttName(host) {
|
||||||
{
|
if (host == "tb-demo.worksys.io" || host == '192.168.252.4') return 'wsmqtt_demo';
|
||||||
if(host == "tb-demo.worksys.io" || host == '192.168.252.4') return 'wsmqtt_demo';
|
else if (host == "tb-qas01.worksys.io" || host == '192.168.252.5') return 'wsmqtt_qas01';
|
||||||
else if(host == "tb-qas01.worksys.io" || host == '192.168.252.5') return 'wsmqtt_qas01';
|
else if (host == "tb-prod01.worksys.io" || host == '192.168.252.1') return 'wsmqtt_prod01';
|
||||||
else if(host == "tb-prod01.worksys.io" || host == '192.168.252.1') return 'wsmqtt_prod01';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendWsStatus()
|
function sendWsStatus() {
|
||||||
{
|
instance.send(SEND_TO.services, { [wsmqttName]: wsmqtt_status });
|
||||||
instance.send(SEND_TO.services, {[wsmqttName]: wsmqtt_status});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function main()
|
function main() {
|
||||||
{
|
if (!FLOW.dbLoaded) return;
|
||||||
if(!FLOW.dbLoaded) return;
|
|
||||||
|
|
||||||
loadSettings();
|
loadSettings();
|
||||||
clearInterval(sendWsStatus);
|
clearInterval(sendWsStatus);
|
||||||
|
|
@ -119,11 +116,9 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//set opts according to db settings
|
//set opts according to db settings
|
||||||
function loadSettings()
|
function loadSettings() {
|
||||||
{
|
|
||||||
|
|
||||||
if(instance.options.host !== "")
|
if (instance.options.host !== "") {
|
||||||
{
|
|
||||||
//override settings from database
|
//override settings from database
|
||||||
var o = instance.options;
|
var o = instance.options;
|
||||||
opts = {
|
opts = {
|
||||||
|
|
@ -139,8 +134,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
console.log("wsmqttpublich -> loadSettings from instance.options", instance.options);
|
console.log("wsmqttpublich -> loadSettings from instance.options", instance.options);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
|
|
||||||
const SETTINGS = FLOW.GLOBALS.settings;
|
const SETTINGS = FLOW.GLOBALS.settings;
|
||||||
backup_on_failure = SETTINGS.backup_on_failure;
|
backup_on_failure = SETTINGS.backup_on_failure;
|
||||||
|
|
@ -170,8 +164,7 @@ exports.install = function(instance) {
|
||||||
connectToTbServer();
|
connectToTbServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
function connectToTbServer()
|
function connectToTbServer() {
|
||||||
{
|
|
||||||
var url = "mqtt://" + opts.host + ":" + opts.port;
|
var url = "mqtt://" + opts.host + ":" + opts.port;
|
||||||
console.log("MQTT URL: ", url);
|
console.log("MQTT URL: ", url);
|
||||||
|
|
||||||
|
|
@ -179,7 +172,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
client.on('connect', function() {
|
client.on('connect', function() {
|
||||||
instance.status("Connected", "green");
|
instance.status("Connected", "green");
|
||||||
monitor.info("MQTT client connected");
|
//monitor.info("MQTT client connected");
|
||||||
|
|
||||||
sendClientError = true;
|
sendClientError = true;
|
||||||
clientReady = true;
|
clientReady = true;
|
||||||
|
|
@ -198,15 +191,15 @@ exports.install = function(instance) {
|
||||||
TRY(function() {
|
TRY(function() {
|
||||||
|
|
||||||
message = JSON.parse(message);
|
message = JSON.parse(message);
|
||||||
if (message.hasOwnProperty("device") && message.hasOwnProperty("data") && message.data.hasOwnProperty("id")) {
|
if (message.hasOwnProperty("device") && message.hasOwnProperty("data") && message.data.hasOwnProperty("id")) {
|
||||||
client.publish(topic, `{"device": ${message.device}, "id": ${message.data.id}, "data": {"success": true}}`, {qos:1});
|
client.publish(topic, `{"device": ${message.device}, "id": ${message.data.id}, "data": {"success": true}}`, { qos: 1 });
|
||||||
instance.send(SEND_TO.rpcCall, {"device": message.device, "id": message.data.id, "RPC response": {"success": true}});
|
instance.send(SEND_TO.rpcCall, { "device": message.device, "id": message.data.id, "RPC response": { "success": true } });
|
||||||
}
|
}
|
||||||
|
|
||||||
}, () => instance.debug('MQTT: Error parsing data', message));
|
}, () => instance.debug('MQTT: Error parsing data', message));
|
||||||
}
|
}
|
||||||
|
|
||||||
instance.send(SEND_TO.rpcCall, {"topic":topic, "content":message });
|
instance.send(SEND_TO.rpcCall, { "topic": topic, "content": message });
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('close', function() {
|
client.on('close', function() {
|
||||||
|
|
@ -214,15 +207,15 @@ exports.install = function(instance) {
|
||||||
wsmqtt_status = 'disconnected';
|
wsmqtt_status = 'disconnected';
|
||||||
|
|
||||||
instance.status("Disconnected", "red");
|
instance.status("Disconnected", "red");
|
||||||
instance.send(SEND_TO.debug, {"message":"Client CLOSE signal received !"});
|
instance.send(SEND_TO.debug, { "message": "Client CLOSE signal received !" });
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('error', function(err) {
|
client.on('error', function(err) {
|
||||||
instance.status("Err: "+ err.code, "red");
|
instance.status("Err: " + err.code, "red");
|
||||||
instance.send(SEND_TO.debug, {"message":"Client ERROR signal received !", "error":err, "opt":opts });
|
instance.send(SEND_TO.debug, { "message": "Client ERROR signal received !", "error": err, "opt": opts });
|
||||||
if(sendClientError) {
|
if (sendClientError) {
|
||||||
monitor.info('MQTT client error', err);
|
monitor.info('MQTT client error', err);
|
||||||
sendClientError = false;
|
sendClientError = false;
|
||||||
}
|
}
|
||||||
clientReady = false;
|
clientReady = false;
|
||||||
wsmqtt_status = 'disconnected';
|
wsmqtt_status = 'disconnected';
|
||||||
|
|
@ -238,28 +231,24 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
instance.on('1', function(data) {
|
instance.on('1', function(data) {
|
||||||
|
|
||||||
if(clientReady)
|
if (clientReady) {
|
||||||
{
|
//do we have some data in backup file? if any, process data from database
|
||||||
//do we have some data in backup file? if any, process data from database
|
if (saveTelemetryOnError) {
|
||||||
if(saveTelemetryOnError)
|
|
||||||
{
|
|
||||||
//read telemetry data and send back to server
|
//read telemetry data and send back to server
|
||||||
if(!processingData) processDataFromDatabase();
|
if (!processingData) processDataFromDatabase();
|
||||||
}
|
}
|
||||||
|
|
||||||
let stringifiedJson = JSON.stringify(data.data);
|
let stringifiedJson = JSON.stringify(data.data);
|
||||||
client.publish("v1/gateway/telemetry", stringifiedJson, {qos: 1});
|
client.publish("v1/gateway/telemetry", stringifiedJson, { qos: 1 });
|
||||||
|
|
||||||
//backup telemetry
|
//backup telemetry
|
||||||
if(createTelemetryBackup)
|
if (createTelemetryBackup) {
|
||||||
{
|
|
||||||
data.data.id = UID();
|
data.data.id = UID();
|
||||||
nosqlBackup.insert(data.data);
|
nosqlBackup.insert(data.data);
|
||||||
|
|
||||||
insertBackupNoSqlCounter++;
|
insertBackupNoSqlCounter++;
|
||||||
if(insertBackupNoSqlCounter > 150)
|
if (insertBackupNoSqlCounter > 150) {
|
||||||
{
|
let options = { compress: true };
|
||||||
let options = {compress: true};
|
|
||||||
let path = __dirname + "/../databases/backup/tbdata.nosql";
|
let path = __dirname + "/../databases/backup/tbdata.nosql";
|
||||||
var stream = new rollers.RollingFileStream(path, noSqlFileSizeLimit, 150, options);
|
var stream = new rollers.RollingFileStream(path, noSqlFileSizeLimit, 150, options);
|
||||||
stream.write("");
|
stream.write("");
|
||||||
|
|
@ -270,13 +259,11 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
//logger.debug("Client unavailable. Data not sent !", JSON.stringify(data.data));
|
//logger.debug("Client unavailable. Data not sent !", JSON.stringify(data.data));
|
||||||
instance.send(SEND_TO.debug, {"message":"Client unavailable. Data not sent !", "data": data.data });
|
instance.send(SEND_TO.debug, { "message": "Client unavailable. Data not sent !", "data": data.data });
|
||||||
|
|
||||||
if(saveTelemetryOnError)
|
if (saveTelemetryOnError) {
|
||||||
{
|
|
||||||
//create new file from tbdata.nosql, if file size exceeds given limit, and clear tbdata.nosql
|
//create new file from tbdata.nosql, if file size exceeds given limit, and clear tbdata.nosql
|
||||||
makeBackupFromDbFile();
|
makeBackupFromDbFile();
|
||||||
|
|
||||||
|
|
@ -289,50 +276,42 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
|
|
||||||
instance.close = function(done) {
|
instance.close = function(done) {
|
||||||
if(clientReady){
|
if (clientReady) {
|
||||||
client.end();
|
client.end();
|
||||||
clearInterval(sendWsStatusVar);
|
clearInterval(sendWsStatusVar);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
function getDbBackupFileCounter(type)
|
function getDbBackupFileCounter(type) {
|
||||||
{
|
|
||||||
var files = fs.readdirSync(__dirname + "/../databases");
|
var files = fs.readdirSync(__dirname + "/../databases");
|
||||||
|
|
||||||
let counter = 0;
|
let counter = 0;
|
||||||
for(var i = 0; i < files.length; i++)
|
for (var i = 0; i < files.length; i++) {
|
||||||
{
|
|
||||||
|
|
||||||
if(files[i] == "tbdata.nosql") continue;
|
if (files[i] == "tbdata.nosql") continue;
|
||||||
|
|
||||||
if(files[i].endsWith(".nosql"))
|
if (files[i].endsWith(".nosql")) {
|
||||||
{
|
|
||||||
|
|
||||||
let pos = files[i].indexOf(".");
|
let pos = files[i].indexOf(".");
|
||||||
if(pos > -1)
|
if (pos > -1) {
|
||||||
{
|
|
||||||
|
|
||||||
let fileCounter = counter;
|
let fileCounter = counter;
|
||||||
let firstDigit = files[i].slice(0, pos);
|
let firstDigit = files[i].slice(0, pos);
|
||||||
|
|
||||||
fileCounter = parseInt(firstDigit);
|
fileCounter = parseInt(firstDigit);
|
||||||
if(isNaN(fileCounter)) fileCounter = 0;
|
if (isNaN(fileCounter)) fileCounter = 0;
|
||||||
//console.log("getDbBackupFileCounter digit:", files[i], firstDigit, fileCounter, isNaN(fileCounter), type);
|
//console.log("getDbBackupFileCounter digit:", files[i], firstDigit, fileCounter, isNaN(fileCounter), type);
|
||||||
|
|
||||||
if(type == "max")
|
if (type == "max") {
|
||||||
{
|
if (fileCounter > counter) {
|
||||||
if(fileCounter > counter)
|
|
||||||
{
|
|
||||||
counter = fileCounter;
|
counter = fileCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(type == "min")
|
else if (type == "min") {
|
||||||
{
|
if (counter == 0) counter = fileCounter;
|
||||||
if(counter == 0) counter = fileCounter;
|
|
||||||
|
|
||||||
if(fileCounter < counter)
|
if (fileCounter < counter) {
|
||||||
{
|
|
||||||
counter = fileCounter;
|
counter = fileCounter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -341,20 +320,19 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(type == "max") counter++;
|
if (type == "max") counter++;
|
||||||
|
|
||||||
return counter;
|
return counter;
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeBackupFromDbFile = async () => {
|
const makeBackupFromDbFile = async () => {
|
||||||
|
|
||||||
if(!saveTelemetryOnError) return;
|
if (!saveTelemetryOnError) return;
|
||||||
|
|
||||||
//to avoid large file: tbdata.nosql
|
//to avoid large file: tbdata.nosql
|
||||||
|
|
||||||
//init value is 0!
|
//init value is 0!
|
||||||
if(insertNoSqlCounter > 0)
|
if (insertNoSqlCounter > 0) {
|
||||||
{
|
|
||||||
--insertNoSqlCounter;
|
--insertNoSqlCounter;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -366,8 +344,7 @@ exports.install = function(instance) {
|
||||||
var stats = fs.statSync(source);
|
var stats = fs.statSync(source);
|
||||||
var fileSizeInBytes = stats.size;
|
var fileSizeInBytes = stats.size;
|
||||||
|
|
||||||
if(fileSizeInBytes > noSqlFileSizeLimit)
|
if (fileSizeInBytes > noSqlFileSizeLimit) {
|
||||||
{
|
|
||||||
|
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
counter = getDbBackupFileCounter("max");
|
counter = getDbBackupFileCounter("max");
|
||||||
|
|
@ -387,15 +364,14 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
const processDataFromDatabase = async () => {
|
const processDataFromDatabase = async () => {
|
||||||
|
|
||||||
if(restore_from_backup <= 0) return;
|
if (restore_from_backup <= 0) return;
|
||||||
|
|
||||||
//calculate diff
|
//calculate diff
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
let currentTime = now.getTime();
|
let currentTime = now.getTime();
|
||||||
let diff = currentTime - lastRestoreTime;
|
let diff = currentTime - lastRestoreTime;
|
||||||
|
|
||||||
if( (diff / 1000) < restore_backup_wait)
|
if ((diff / 1000) < restore_backup_wait) {
|
||||||
{
|
|
||||||
//console.log("*********restore_backup_wait", diff, restore_backup_wait);
|
//console.log("*********restore_backup_wait", diff, restore_backup_wait);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -409,7 +385,7 @@ exports.install = function(instance) {
|
||||||
let dataBase = 'tbdata';
|
let dataBase = 'tbdata';
|
||||||
|
|
||||||
var nosql;
|
var nosql;
|
||||||
if(counter == 0) dataBase = 'tbdata';
|
if (counter == 0) dataBase = 'tbdata';
|
||||||
else dataBase = counter + "." + 'tbdata';
|
else dataBase = counter + "." + 'tbdata';
|
||||||
|
|
||||||
nosql = NOSQL(dataBase);
|
nosql = NOSQL(dataBase);
|
||||||
|
|
@ -417,15 +393,13 @@ exports.install = function(instance) {
|
||||||
//select all data - use limit restore_from_backup
|
//select all data - use limit restore_from_backup
|
||||||
let records = await promisifyBuilder(nosql.find().take(restore_from_backup));
|
let records = await promisifyBuilder(nosql.find().take(restore_from_backup));
|
||||||
|
|
||||||
for(let i = 0; i < records.length; i++)
|
for (let i = 0; i < records.length; i++) {
|
||||||
{
|
if (clientReady) {
|
||||||
if(clientReady) {
|
|
||||||
|
|
||||||
let item = records[i];
|
let item = records[i];
|
||||||
let id = item.id;
|
let id = item.id;
|
||||||
|
|
||||||
if(id !== undefined)
|
if (id !== undefined) {
|
||||||
{
|
|
||||||
//console.log("------------processDataFromDatabase - remove", id, dataBase, i);
|
//console.log("------------processDataFromDatabase - remove", id, dataBase, i);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
@ -433,12 +407,12 @@ exports.install = function(instance) {
|
||||||
let message = JSON.parse(JSON.stringify(item));
|
let message = JSON.parse(JSON.stringify(item));
|
||||||
delete message.id;
|
delete message.id;
|
||||||
|
|
||||||
client.publish("v1/gateway/telemetry", JSON.stringify(message), {qos:1});
|
client.publish("v1/gateway/telemetry", JSON.stringify(message), { qos: 1 });
|
||||||
|
|
||||||
//remove from database
|
//remove from database
|
||||||
await promisifyBuilder(nosql.remove().where("id", id));
|
await promisifyBuilder(nosql.remove().where("id", id));
|
||||||
|
|
||||||
} catch(error) {
|
} catch (error) {
|
||||||
//process error
|
//process error
|
||||||
console.log("processDataFromDatabase", error);
|
console.log("processDataFromDatabase", error);
|
||||||
}
|
}
|
||||||
|
|
@ -446,23 +420,20 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
processingData = false;
|
processingData = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(records.length > 0)
|
if (records.length > 0) {
|
||||||
{
|
|
||||||
//clean backup file
|
//clean backup file
|
||||||
if(counter > 0) nosql.clean();
|
if (counter > 0) nosql.clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
//no data in db, remove
|
//no data in db, remove
|
||||||
if(records.length == 0)
|
if (records.length == 0) {
|
||||||
{
|
if (counter > 0) nosql.drop();
|
||||||
if(counter > 0) nosql.drop();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const d = new Date();
|
const d = new Date();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue