Repeat node request 3x; fix rsPort and ws connection after close
This commit is contained in:
parent
0876e73c68
commit
0c993f50b1
6 changed files with 144 additions and 98 deletions
|
|
@ -225,7 +225,9 @@ exports.install = function(instance) {
|
|||
params.priority = priority;
|
||||
}
|
||||
|
||||
params.addMinutesToTimestamp = 0;//repeat task if value is > 0,
|
||||
params.addMinutesToTimestamp = 0;//repeat task if value is > 0
|
||||
// if node regular readout does not respond, we repeat request
|
||||
params.repeatCounter = 0;
|
||||
//params.timePointName = "luxOff" // "luxOn", "dusk", "dawn", "profileTimepoint"
|
||||
//params.info = "";
|
||||
//params.debug = true; // will console.log params in writeData response
|
||||
|
|
@ -642,7 +644,7 @@ exports.install = function(instance) {
|
|||
function reportOnlineNodeStatus(line) {
|
||||
//Po zapnutí línie broadcastovo aktualizovať predtým čas a o 3 sek neskor - status, brightness
|
||||
|
||||
logger.debug("--->reportOnlineNodeStatus for line", line);
|
||||
logger.debug("Cmd-mngr: ----->reportOnlineNodeStatus for line", line);
|
||||
|
||||
const d = new Date();
|
||||
|
||||
|
|
@ -746,7 +748,7 @@ exports.install = function(instance) {
|
|||
|
||||
|
||||
function reportOfflineNodeStatus(line) {
|
||||
logger.debug("--->reportOfflineNodeStatus for line", line);
|
||||
logger.debug("Cmd-mngr: ----->reportOfflineNodeStatus for line", line);
|
||||
|
||||
values = {};
|
||||
values["dimming"] = 0;//brightness
|
||||
|
|
@ -766,11 +768,10 @@ exports.install = function(instance) {
|
|||
let tbname = nodesData[node].tbname;
|
||||
let nodeStatus = nodesData[node].status;
|
||||
|
||||
|
||||
//in case we have reported offline node status, we return (continue with next node)
|
||||
if (nodeStatus === "OFFLINE") return;
|
||||
|
||||
nodesData[node].node_status_before_offline = nodeStatus === true ? true : false;
|
||||
nodesData[node].node_status_before_offline = nodeStatus;
|
||||
nodesData[node].status = "OFFLINE";
|
||||
nodesData[node].readout = {};
|
||||
|
||||
|
|
@ -795,7 +796,6 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
|
||||
|
||||
function detectIfResponseIsValid(bytes) {
|
||||
//ak sa odpoved zacina 0 - je to v poriadku, inak je NOK
|
||||
let type = "RESPONSE";
|
||||
|
|
@ -1492,7 +1492,7 @@ exports.install = function(instance) {
|
|||
|
||||
let stop = true;
|
||||
|
||||
if (type == "cmd-terminal" || type == "cmd-master") stop = false;
|
||||
if (type === "cmd-terminal" || type === "cmd-master") stop = false;
|
||||
if (stop) {
|
||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||
return;
|
||||
|
|
@ -1502,7 +1502,7 @@ exports.install = function(instance) {
|
|||
let contactorStatus = 1;
|
||||
if (relaysData[line] != undefined) contactorStatus = relaysData[line].contactor;
|
||||
|
||||
if (line == 0 || contactorStatus == 0) {
|
||||
if (line === 0 || contactorStatus === 0 || FLOW.deviceStatus.state_of_breaker[line] === "Off") {
|
||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||
return;
|
||||
}
|
||||
|
|
@ -1653,7 +1653,6 @@ exports.install = function(instance) {
|
|||
|
||||
}
|
||||
else {
|
||||
|
||||
terminalCommandResponse(params, "ERROR", data);
|
||||
handleNokResponseOnRsPort("handleNOK else block", params, itIsNodeCommand, saveToTb);
|
||||
|
||||
|
|
@ -1697,6 +1696,16 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
|
||||
function repeatCommand(params) {
|
||||
params.repeatCounter++;
|
||||
if (params.repeatCounter > 0) console.log("repeated-------", params.address, params.register, params.repeatCounter);
|
||||
if (params.repeatCounter < 4) {
|
||||
params.timestamp = 0;
|
||||
params.addMinutesToTimestamp = 0;
|
||||
tasks.push(params);
|
||||
}
|
||||
}
|
||||
|
||||
function handleNokResponseOnRsPort(message, params, itIsNodeCommand, saveToTb) {
|
||||
|
||||
let node = params.address;
|
||||
|
|
@ -1712,6 +1721,7 @@ exports.install = function(instance) {
|
|||
if (itIsNodeCommand) {
|
||||
values.comm_status = "NOK";
|
||||
nodesData[node].readout.comm_status = "NOK";
|
||||
repeatCommand(params);
|
||||
}
|
||||
|
||||
if (updateStatus) {
|
||||
|
|
@ -1747,10 +1757,12 @@ exports.install = function(instance) {
|
|||
|
||||
}
|
||||
|
||||
|
||||
function sendNodesData() {
|
||||
Object.keys(nodesData).forEach(node => {
|
||||
if (nodesData[node]["status"] !== "OFFLINE") {
|
||||
sendTelemetry(nodesData[node].readout, nodesData[node].tbname);
|
||||
nodesData[node].readout = {};
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1763,13 +1775,10 @@ exports.install = function(instance) {
|
|||
*/
|
||||
function terminalCommandResponse(params, responseType, data = null, reason = "") { //success, error, failure
|
||||
|
||||
if (params.refFlowdataKey == undefined) {
|
||||
if (params.refFlowdataKey === undefined) {
|
||||
//console.log("params.refFlowdataKey is undefined", params);
|
||||
return;
|
||||
}
|
||||
else {
|
||||
console.log("params.refFlowdataKey: ", params);
|
||||
}
|
||||
|
||||
let message = null;
|
||||
let type = null;
|
||||
|
|
@ -1792,7 +1801,6 @@ exports.install = function(instance) {
|
|||
}
|
||||
|
||||
logger.debug(message);
|
||||
logger.debug(params);
|
||||
|
||||
//make http response
|
||||
let responseObj = {}
|
||||
|
|
@ -1851,6 +1859,11 @@ exports.install = function(instance) {
|
|||
|
||||
function handleRsPort() {
|
||||
|
||||
if (rsPort) {
|
||||
rsPort.removeAllListeners();
|
||||
rsPort = null;
|
||||
}
|
||||
|
||||
//! rsPort LM = "/dev/ttymxc4", rsPort UNIPI = "/dev/ttyUSB0"
|
||||
// const rsPort = new SerialPort("/dev/ttymxc4", { autoOpen: false }); //LM
|
||||
// const rsPort = new SerialPort("/dev/ttyUSB0", { autoOpen: false }); // UNIPI
|
||||
|
|
@ -1875,16 +1888,13 @@ exports.install = function(instance) {
|
|||
});
|
||||
|
||||
rsPort.on('error', function(err) {
|
||||
|
||||
//TODO report to service!!!
|
||||
//errLogger.error(exports.title, "unable to open port", SETTINGS.serial_port, err.message);
|
||||
errorHandler.sendMessageToService([exports.title, "unable to open port", SETTINGS.serial_port, err.message], 0);
|
||||
|
||||
instance.send(SEND_TO.debug, err.message);
|
||||
monitor.info("Cmd_manager: Error on rsPort", err.message);
|
||||
});
|
||||
|
||||
rsPort.on("close", () => {
|
||||
setTimeout(() => rsPort.open(), 1000);
|
||||
monitor.info("Cmd_manager: rsPort closed, reconnecting...");
|
||||
setTimeout(handleRsPort, 1000);
|
||||
});
|
||||
|
||||
rsPort.open();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue