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
|
|
@ -1,2 +1,2 @@
|
||||||
node:number|tbname:string|line:number|profile:string|processed:boolean|status:boolean|time_of_last_communication:number
|
node:number|tbname:string|line:number|profile:string|processed:boolean|status:boolean|time_of_last_communication:number
|
||||||
+|638|rDbQ84xzwgdqEoPm3kbJQWk9anOZY1RXyBv2LVM6|3|{"intervals":[{"cct":3000,"value":20,"end_time":"20:00","start_time":"13:00"},{"cct":3000,"value":10,"end_time":"05:30","start_time":"20:00"},{"cct":3000,"value":20,"end_time":"13:00","start_time":"05:30"}],"astro_clock":true,"dawn_lux_sensor":false,"dusk_lux_sensor":false,"dawn_lux_sensor_value":5,"dusk_lux_sensor_value":5,"dawn_astro_clock_offset":-20,"dusk_astro_clock_offset":20,"dawn_lux_sensor_time_window":30,"dusk_lux_sensor_time_window":30,"dawn_astro_clock_time_window":60,"dusk_astro_clock_time_window":60}|1|0|1725885127396|............................................................................................................................................................................................................................................................|.................
|
+|638|rDbQ84xzwgdqEoPm3kbJQWk9anOZY1RXyBv2LVM6|3|{"intervals":[{"cct":3000,"value":20,"end_time":"20:00","start_time":"13:00"},{"cct":3000,"value":10,"end_time":"05:30","start_time":"20:00"},{"cct":3000,"value":20,"end_time":"13:00","start_time":"05:30"}],"astro_clock":true,"dawn_lux_sensor":false,"dusk_lux_sensor":false,"dawn_lux_sensor_value":5,"dusk_lux_sensor_value":5,"dawn_astro_clock_offset":-20,"dusk_astro_clock_offset":20,"dawn_lux_sensor_time_window":30,"dusk_lux_sensor_time_window":30,"dawn_astro_clock_time_window":60,"dusk_astro_clock_time_window":60}|1|0|1725885127396|............................................................................................................................................................................................................................................................
|
||||||
|
|
|
||||||
|
|
@ -225,7 +225,9 @@ exports.install = function(instance) {
|
||||||
params.priority = priority;
|
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.timePointName = "luxOff" // "luxOn", "dusk", "dawn", "profileTimepoint"
|
||||||
//params.info = "";
|
//params.info = "";
|
||||||
//params.debug = true; // will console.log params in writeData response
|
//params.debug = true; // will console.log params in writeData response
|
||||||
|
|
@ -642,7 +644,7 @@ exports.install = function(instance) {
|
||||||
function reportOnlineNodeStatus(line) {
|
function reportOnlineNodeStatus(line) {
|
||||||
//Po zapnutí línie broadcastovo aktualizovať predtým čas a o 3 sek neskor - status, brightness
|
//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();
|
const d = new Date();
|
||||||
|
|
||||||
|
|
@ -746,7 +748,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
|
|
||||||
function reportOfflineNodeStatus(line) {
|
function reportOfflineNodeStatus(line) {
|
||||||
logger.debug("--->reportOfflineNodeStatus for line", line);
|
logger.debug("Cmd-mngr: ----->reportOfflineNodeStatus for line", line);
|
||||||
|
|
||||||
values = {};
|
values = {};
|
||||||
values["dimming"] = 0;//brightness
|
values["dimming"] = 0;//brightness
|
||||||
|
|
@ -766,11 +768,10 @@ exports.install = function(instance) {
|
||||||
let tbname = nodesData[node].tbname;
|
let tbname = nodesData[node].tbname;
|
||||||
let nodeStatus = nodesData[node].status;
|
let nodeStatus = nodesData[node].status;
|
||||||
|
|
||||||
|
|
||||||
//in case we have reported offline node status, we return (continue with next node)
|
//in case we have reported offline node status, we return (continue with next node)
|
||||||
if (nodeStatus === "OFFLINE") return;
|
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].status = "OFFLINE";
|
||||||
nodesData[node].readout = {};
|
nodesData[node].readout = {};
|
||||||
|
|
||||||
|
|
@ -795,7 +796,6 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function detectIfResponseIsValid(bytes) {
|
function detectIfResponseIsValid(bytes) {
|
||||||
//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 type = "RESPONSE";
|
let type = "RESPONSE";
|
||||||
|
|
@ -1492,7 +1492,7 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let stop = true;
|
let stop = true;
|
||||||
|
|
||||||
if (type == "cmd-terminal" || type == "cmd-master") stop = false;
|
if (type === "cmd-terminal" || type === "cmd-master") stop = false;
|
||||||
if (stop) {
|
if (stop) {
|
||||||
interval = setInterval(runTasks, LONG_INTERVAL);
|
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||||
return;
|
return;
|
||||||
|
|
@ -1502,7 +1502,7 @@ exports.install = function(instance) {
|
||||||
let contactorStatus = 1;
|
let contactorStatus = 1;
|
||||||
if (relaysData[line] != undefined) contactorStatus = relaysData[line].contactor;
|
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);
|
interval = setInterval(runTasks, LONG_INTERVAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -1653,7 +1653,6 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
terminalCommandResponse(params, "ERROR", data);
|
terminalCommandResponse(params, "ERROR", data);
|
||||||
handleNokResponseOnRsPort("handleNOK else block", params, itIsNodeCommand, saveToTb);
|
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) {
|
function handleNokResponseOnRsPort(message, params, itIsNodeCommand, saveToTb) {
|
||||||
|
|
||||||
let node = params.address;
|
let node = params.address;
|
||||||
|
|
@ -1712,6 +1721,7 @@ exports.install = function(instance) {
|
||||||
if (itIsNodeCommand) {
|
if (itIsNodeCommand) {
|
||||||
values.comm_status = "NOK";
|
values.comm_status = "NOK";
|
||||||
nodesData[node].readout.comm_status = "NOK";
|
nodesData[node].readout.comm_status = "NOK";
|
||||||
|
repeatCommand(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (updateStatus) {
|
if (updateStatus) {
|
||||||
|
|
@ -1747,10 +1757,12 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function sendNodesData() {
|
function sendNodesData() {
|
||||||
Object.keys(nodesData).forEach(node => {
|
Object.keys(nodesData).forEach(node => {
|
||||||
if (nodesData[node]["status"] !== "OFFLINE") {
|
if (nodesData[node]["status"] !== "OFFLINE") {
|
||||||
sendTelemetry(nodesData[node].readout, nodesData[node].tbname);
|
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
|
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);
|
//console.log("params.refFlowdataKey is undefined", params);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
console.log("params.refFlowdataKey: ", params);
|
|
||||||
}
|
|
||||||
|
|
||||||
let message = null;
|
let message = null;
|
||||||
let type = null;
|
let type = null;
|
||||||
|
|
@ -1792,7 +1801,6 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.debug(message);
|
logger.debug(message);
|
||||||
logger.debug(params);
|
|
||||||
|
|
||||||
//make http response
|
//make http response
|
||||||
let responseObj = {}
|
let responseObj = {}
|
||||||
|
|
@ -1851,6 +1859,11 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
function handleRsPort() {
|
function handleRsPort() {
|
||||||
|
|
||||||
|
if (rsPort) {
|
||||||
|
rsPort.removeAllListeners();
|
||||||
|
rsPort = null;
|
||||||
|
}
|
||||||
|
|
||||||
//! rsPort LM = "/dev/ttymxc4", rsPort UNIPI = "/dev/ttyUSB0"
|
//! rsPort LM = "/dev/ttymxc4", rsPort UNIPI = "/dev/ttyUSB0"
|
||||||
// const rsPort = new SerialPort("/dev/ttymxc4", { autoOpen: false }); //LM
|
// const rsPort = new SerialPort("/dev/ttymxc4", { autoOpen: false }); //LM
|
||||||
// const rsPort = new SerialPort("/dev/ttyUSB0", { autoOpen: false }); // UNIPI
|
// const rsPort = new SerialPort("/dev/ttyUSB0", { autoOpen: false }); // UNIPI
|
||||||
|
|
@ -1875,16 +1888,13 @@ exports.install = function(instance) {
|
||||||
});
|
});
|
||||||
|
|
||||||
rsPort.on('error', function(err) {
|
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);
|
errorHandler.sendMessageToService([exports.title, "unable to open port", SETTINGS.serial_port, err.message], 0);
|
||||||
|
monitor.info("Cmd_manager: Error on rsPort", err.message);
|
||||||
instance.send(SEND_TO.debug, err.message);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rsPort.on("close", () => {
|
rsPort.on("close", () => {
|
||||||
setTimeout(() => rsPort.open(), 1000);
|
monitor.info("Cmd_manager: rsPort closed, reconnecting...");
|
||||||
|
setTimeout(handleRsPort, 1000);
|
||||||
});
|
});
|
||||||
|
|
||||||
rsPort.open();
|
rsPort.open();
|
||||||
|
|
|
||||||
|
|
@ -449,8 +449,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"datatype": "object",
|
"data": "{line: 3, command: \"turnOff\", force: true}",
|
||||||
"data": "{line: 3, command: \"turnOff\", force: true}"
|
"datatype": "object"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -501,8 +501,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"data": "profile_nodes",
|
"datatype": "string",
|
||||||
"datatype": "string"
|
"data": "profile_nodes"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -712,8 +712,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"data": "{line: 1, command: \"turnOn\", force: true}",
|
"datatype": "object",
|
||||||
"datatype": "object"
|
"data": "{line: 1, command: \"turnOn\", force: true}"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -842,8 +842,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"datatype": "object",
|
"data": "{command: \"turnOnAlarm\"}",
|
||||||
"data": "{command: \"turnOnAlarm\"}"
|
"datatype": "object"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -872,8 +872,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"datatype": "object",
|
"data": "{command: \"turnOffAlarm\"}",
|
||||||
"data": "{command: \"turnOffAlarm\"}"
|
"datatype": "object"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -1009,7 +1009,7 @@
|
||||||
"output": []
|
"output": []
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "843.78 MB / 985.68 MB",
|
"text": "840.05 MB / 985.68 MB",
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
|
@ -1039,7 +1039,7 @@
|
||||||
"output": []
|
"output": []
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "5.68 GB / 7.26 GB",
|
"text": "5.78 GB / 7.26 GB",
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
|
@ -1152,9 +1152,9 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"url": "http://192.168.252.2:8004/sentmessage",
|
"stringify": "json",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"stringify": "json"
|
"url": "http://192.168.252.2:8004/sentmessage"
|
||||||
},
|
},
|
||||||
"color": "#5D9CEC",
|
"color": "#5D9CEC",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -1495,7 +1495,7 @@
|
||||||
"output": []
|
"output": []
|
||||||
},
|
},
|
||||||
"state": {
|
"state": {
|
||||||
"text": "2% / 86.44 MB",
|
"text": "2.4% / 74.33 MB",
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
|
|
@ -2018,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": ""
|
"name": "rvo_senica_33_10.0.0.127"
|
||||||
},
|
},
|
||||||
"color": "#30E193",
|
"color": "#30E193",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -2047,9 +2047,9 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"url": "http://192.168.252.2:8004/slack",
|
"stringify": "json",
|
||||||
"method": "POST",
|
"method": "POST",
|
||||||
"stringify": "json"
|
"url": "http://192.168.252.2:8004/slack"
|
||||||
},
|
},
|
||||||
"color": "#5D9CEC",
|
"color": "#5D9CEC",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -2104,8 +2104,8 @@
|
||||||
"color": "gray"
|
"color": "gray"
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"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",
|
||||||
"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\": \"\" } } } ] }"
|
||||||
},
|
},
|
||||||
"color": "#F6BB42",
|
"color": "#F6BB42",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
|
@ -2282,8 +2282,8 @@
|
||||||
"component": "showdb",
|
"component": "showdb",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "Show db data",
|
"name": "Show db data",
|
||||||
"x": 1121.75,
|
"x": 1186.75,
|
||||||
"y": 814.25,
|
"y": 821.25,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2309,8 +2309,8 @@
|
||||||
"component": "debug",
|
"component": "debug",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "dbData",
|
"name": "dbData",
|
||||||
"x": 1315.75,
|
"x": 1390.75,
|
||||||
"y": 853.25,
|
"y": 870.25,
|
||||||
"connections": {},
|
"connections": {},
|
||||||
"disabledio": {
|
"disabledio": {
|
||||||
"input": [],
|
"input": [],
|
||||||
|
|
@ -2333,8 +2333,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "settings",
|
"name": "settings",
|
||||||
"x": 911.75,
|
"x": 934.75,
|
||||||
"y": 710.75,
|
"y": 669.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2360,8 +2360,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "relaysData",
|
"name": "relaysData",
|
||||||
"x": 832.75,
|
"x": 876.75,
|
||||||
"y": 775.75,
|
"y": 733.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2387,8 +2387,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "nodesData",
|
"name": "nodesData",
|
||||||
"x": 747.75,
|
"x": 852.75,
|
||||||
"y": 840.75,
|
"y": 794.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2414,8 +2414,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "pinsData",
|
"name": "pinsData",
|
||||||
"x": 803.75,
|
"x": 850.75,
|
||||||
"y": 899.75,
|
"y": 861.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2441,8 +2441,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "sample data",
|
"name": "sample data",
|
||||||
"x": 858.75,
|
"x": 857.75,
|
||||||
"y": 959.75,
|
"y": 928.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2613,8 +2613,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "monitor.txt",
|
"name": "monitor.txt",
|
||||||
"x": 915.75,
|
"x": 882.75,
|
||||||
"y": 1017.75,
|
"y": 991.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2640,8 +2640,8 @@
|
||||||
"component": "trigger",
|
"component": "trigger",
|
||||||
"tab": "1612772287426",
|
"tab": "1612772287426",
|
||||||
"name": "err.txt",
|
"name": "err.txt",
|
||||||
"x": 966.75,
|
"x": 904.75,
|
||||||
"y": 1080.75,
|
"y": 1053.75,
|
||||||
"connections": {
|
"connections": {
|
||||||
"0": [
|
"0": [
|
||||||
{
|
{
|
||||||
|
|
@ -2862,6 +2862,33 @@
|
||||||
"options": {},
|
"options": {},
|
||||||
"color": "#704cff",
|
"color": "#704cff",
|
||||||
"notes": ""
|
"notes": ""
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "1749211698385",
|
||||||
|
"component": "trigger",
|
||||||
|
"tab": "1612772287426",
|
||||||
|
"name": "deviceStatus",
|
||||||
|
"x": 911.75,
|
||||||
|
"y": 1116.75,
|
||||||
|
"connections": {
|
||||||
|
"0": [
|
||||||
|
{
|
||||||
|
"index": "7",
|
||||||
|
"id": "1731069059135"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"disabledio": {
|
||||||
|
"input": [],
|
||||||
|
"output": []
|
||||||
|
},
|
||||||
|
"state": {
|
||||||
|
"text": "",
|
||||||
|
"color": "gray"
|
||||||
|
},
|
||||||
|
"options": {},
|
||||||
|
"color": "#F6BB42",
|
||||||
|
"notes": ""
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"version": 615
|
"version": 615
|
||||||
|
|
|
||||||
|
|
@ -124,8 +124,8 @@ exports.install = function(instance) {
|
||||||
};
|
};
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//status for calculating Statecodes
|
//status for calculating Statecodes-we make it global to see it from outside
|
||||||
let deviceStatus = { //key is device name: temperature,....
|
FLOW.deviceStatus = { //key is device name: temperature,....
|
||||||
"state_of_main_switch": "Off", //Hlavny istic (alebo druhy dverovy kontakt)
|
"state_of_main_switch": "Off", //Hlavny istic (alebo druhy dverovy kontakt)
|
||||||
"rotary_switch_state": "Off", //Prevadzkovy
|
"rotary_switch_state": "Off", //Prevadzkovy
|
||||||
"door_condition": "closed", //Dverový kontakt
|
"door_condition": "closed", //Dverový kontakt
|
||||||
|
|
@ -139,6 +139,7 @@ exports.install = function(instance) {
|
||||||
"state_of_contactor": {}, //"Off",//Stykac
|
"state_of_contactor": {}, //"Off",//Stykac
|
||||||
"twilight_sensor": "OK" //lux sensor
|
"twilight_sensor": "OK" //lux sensor
|
||||||
};
|
};
|
||||||
|
let deviceStatus = FLOW.deviceStatus;
|
||||||
|
|
||||||
|
|
||||||
function main() {
|
function main() {
|
||||||
|
|
@ -211,18 +212,17 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
|
|
||||||
function handleRsPort() {
|
function handleRsPort() {
|
||||||
|
|
||||||
|
if (rsPort) {
|
||||||
|
rsPort.removeAllListeners();
|
||||||
|
rsPort = null;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO build according to pins!!!
|
//TODO build according to pins!!!
|
||||||
//! rsPort to open are the same for lm and unipi and electromer ("/dev/ttymxc0")
|
//! rsPort to open are the same for lm and unipi and electromer ("/dev/ttymxc0")
|
||||||
const setRSPortData = [0xAA, 6, 6, 6, 6, 6, 6, 0, 6, 6, 6, 1, 1, 1, 1, 0, 0, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 15, 15, 15, 15, 15, 15, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0];
|
const setRSPortData = [0xAA, 6, 6, 6, 6, 6, 6, 0, 6, 6, 6, 1, 1, 1, 1, 0, 0, 10, 10, 10, 10, 10, 10, 0, 10, 10, 10, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 15, 15, 15, 15, 15, 15, 0, 15, 15, 15, 0, 0, 0, 0, 0, 0, 30, 0, 0, 0];
|
||||||
rsPort = new SerialPort("/dev/ttymxc0", { autoOpen: false });
|
rsPort = new SerialPort("/dev/ttymxc0", { autoOpen: false });
|
||||||
|
|
||||||
rsPort.on('error', function(err) {
|
|
||||||
logger.debug("rsPort opened error - failed", err.message);
|
|
||||||
instance.send(SEND_TO.debug, err.message);
|
|
||||||
|
|
||||||
errorHandler.sendMessageToService(exports.title + " rsPort opened error - failed: " + err.message);
|
|
||||||
})
|
|
||||||
|
|
||||||
rsPort.on('open', async function() {
|
rsPort.on('open', async function() {
|
||||||
|
|
||||||
await runSyncExec("stty -F /dev/ttymxc0 115200 min 1 time 5 ignbrk -brkint -icrnl -imaxbel -opost -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke").then(function(status) {
|
await runSyncExec("stty -F /dev/ttymxc0 115200 min 1 time 5 ignbrk -brkint -icrnl -imaxbel -opost -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke").then(function(status) {
|
||||||
|
|
@ -283,8 +283,18 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
rsPort.on('error', err => {
|
||||||
|
let message = "Dido: rsPort error: " + err.message;
|
||||||
|
logger.debug(message);
|
||||||
|
monitor.info(message);
|
||||||
|
errorHandler.sendMessageToService(message);
|
||||||
|
})
|
||||||
|
|
||||||
rsPort.on("close", () => {
|
rsPort.on("close", () => {
|
||||||
rsPort.close();
|
let message = "Dido: rsPort closed - reconnecting ...";
|
||||||
|
logger.debug(message);
|
||||||
|
monitor.info(message);
|
||||||
|
setTimeout(handleRsPort, 1000);
|
||||||
})
|
})
|
||||||
|
|
||||||
rsPort.open();
|
rsPort.open();
|
||||||
|
|
@ -293,6 +303,11 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
function handleWebSocket() {
|
function handleWebSocket() {
|
||||||
|
|
||||||
|
if (ws) {
|
||||||
|
ws.removeAllListeners();
|
||||||
|
ws = null;
|
||||||
|
}
|
||||||
|
|
||||||
//to keep websocket opened, we send request every 150 seconds
|
//to keep websocket opened, we send request every 150 seconds
|
||||||
let startRequests = null;
|
let startRequests = null;
|
||||||
|
|
||||||
|
|
@ -356,23 +371,13 @@ exports.install = function(instance) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ws.on('error', err => {
|
||||||
ws.on('error', (err) => {
|
logger.debug('Dido: websocket error', err);
|
||||||
monitor.info('websocket error, reconnect')
|
|
||||||
instance.send(SEND_TO.debug, err.message);
|
|
||||||
clearInterval(startRequests);
|
|
||||||
ws = null;
|
|
||||||
setTimeout(handleWebSocket, 1000);
|
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
ws.onclose = function() {
|
ws.onclose = function() {
|
||||||
// connection closed, discard old websocket and create a new one in 5s
|
logger.debug('Dido: websocket onclose, reconnecting...')
|
||||||
// stopRequests();
|
|
||||||
monitor.info('websocket onclose, reconnect')
|
|
||||||
clearInterval(startRequests);
|
clearInterval(startRequests);
|
||||||
ws = null;
|
|
||||||
console.log("ws is null now, reconnecting...");
|
|
||||||
setTimeout(handleWebSocket, 1000);
|
setTimeout(handleWebSocket, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -382,7 +387,6 @@ exports.install = function(instance) {
|
||||||
if (ws) ws.close();
|
if (ws) ws.close();
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
function getPin(line) {
|
function getPin(line) {
|
||||||
//conversionTable
|
//conversionTable
|
||||||
let keys = Object.keys(pinsData);
|
let keys = Object.keys(pinsData);
|
||||||
|
|
@ -483,14 +487,14 @@ exports.install = function(instance) {
|
||||||
if (!force) {
|
if (!force) {
|
||||||
if (relaysData[line].contactor == value) {
|
if (relaysData[line].contactor == value) {
|
||||||
instance.send(SEND_TO.debug, `line is already ${onOrOff} ` + line);
|
instance.send(SEND_TO.debug, `line is already ${onOrOff} ` + line);
|
||||||
logger.debug(`turnLine: line is already ${onOrOff} `, line);
|
logger.debug(`Dido: turnLine: line is already ${onOrOff} `, line);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if(!rsPort.isOpen && !ws)
|
// if(!rsPort.isOpen && !ws)
|
||||||
if (!rsPort && !ws) {
|
if (!rsPort && !ws) {
|
||||||
errLogger.error("dido controller - port or websocket is not opened");
|
errLogger.error("Dido - port or websocket is not opened");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -502,18 +506,18 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
rsPort.write(Buffer.from(arr), function(err) {
|
rsPort.write(Buffer.from(arr), function(err) {
|
||||||
if (err === undefined) {
|
if (err === undefined) {
|
||||||
monitor.info(`turnLine ${onOrOff} zapisal do rsPort-u`, line, pin, arr, info);
|
monitor.info(`Dido: turnLine ${onOrOff} zapisal do rsPort-u`, line, pin, arr, info);
|
||||||
switchLogic(arr);
|
switchLogic(arr);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
monitor.info(`turnLine ${onOrOff} WRITE error`, err);
|
monitor.info(`Dido: turnLine ${onOrOff} WRITE error`, err);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (ws) {
|
else if (ws) {
|
||||||
//pin = "relay1_03" or "input1_01" ... we must make just "1_01" with slice method
|
//pin = "relay1_03" or "input1_01" ... we must make just "1_01" with slice method
|
||||||
monitor.info(`turnLine ${onOrOff} - (line, pin, force)`, line, pin, force, info);
|
monitor.info(`Dido: turnLine ${onOrOff} - (line, pin, force)`, line, pin, force, info);
|
||||||
let cmd = { "cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": value };
|
let cmd = { "cmd": "set", "dev": "relay", "circuit": pin.slice(5), "value": value };
|
||||||
ws.send(JSON.stringify(cmd));
|
ws.send(JSON.stringify(cmd));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -76,6 +76,11 @@ exports.install = function(instance) {
|
||||||
|
|
||||||
let obj = this;
|
let obj = this;
|
||||||
|
|
||||||
|
if (this.socket) {
|
||||||
|
this.socket.removeAllListeners();
|
||||||
|
this.socket = null;
|
||||||
|
}
|
||||||
|
|
||||||
this.socket = new SerialPort("/dev/ttymxc0", {
|
this.socket = new SerialPort("/dev/ttymxc0", {
|
||||||
baudRate: 9600,
|
baudRate: 9600,
|
||||||
})
|
})
|
||||||
|
|
@ -86,15 +91,11 @@ exports.install = function(instance) {
|
||||||
}
|
}
|
||||||
|
|
||||||
this.socket.on('error', function(e) {
|
this.socket.on('error', function(e) {
|
||||||
console.log('socket connection error', e);
|
console.log('Modbus_reader: Socket connection error', e); //'ECONNREFUSED' or 'ECONNRESET' ??
|
||||||
if (e.code == 'ECONNREFUSED' || e.code == 'ECONNRESET') {
|
|
||||||
console.log(exports.title + ' Waiting 10 seconds before trying to connect again');
|
|
||||||
setTimeout(obj.startSocket, 10000);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.socket.on('close', function() {
|
this.socket.on('close', function() {
|
||||||
console.log('Socket connection closed ' + exports.title + ' Waiting 10 seconds before trying to connect again');
|
console.log('Modbus_reader: Socket connection closed - Waiting 10 seconds before connecting again');
|
||||||
setTimeout(obj.startSocket, 10000);
|
setTimeout(obj.startSocket, 10000);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -115,7 +116,8 @@ exports.install = function(instance) {
|
||||||
this.deviceAddress = dev.deviceAddress; // 1 or 2 or any number
|
this.deviceAddress = dev.deviceAddress; // 1 or 2 or any number
|
||||||
this.device = dev.device; //em340, twilight_sensor
|
this.device = dev.device; //em340, twilight_sensor
|
||||||
|
|
||||||
if (this.indexInDeviceConfig == 0) setTimeout(this.readRegisters, this.timeoutInterval);
|
//if we just start to loop devices from the beginning, or there is just 1 device in config, we wait whole timeoutInterval
|
||||||
|
if (this.indexInDeviceConfig == 0 || deviceConfig.length === 1) setTimeout(this.readRegisters, this.timeoutInterval);
|
||||||
else setTimeout(this.readRegisters, DELAY_BETWEEN_DEVICES);
|
else setTimeout(this.readRegisters, DELAY_BETWEEN_DEVICES);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,7 +332,8 @@ exports.install = function(instance) {
|
||||||
phases = FLOW.GLOBALS.settings.phases;
|
phases = FLOW.GLOBALS.settings.phases;
|
||||||
tbName = FLOW.GLOBALS.settings.rvoTbName;
|
tbName = FLOW.GLOBALS.settings.rvoTbName;
|
||||||
noVoltage = FLOW.GLOBALS.settings.no_voltage;
|
noVoltage = FLOW.GLOBALS.settings.no_voltage;
|
||||||
mainSocket = new SocketWithClients();
|
if (deviceConfig.length) mainSocket = new SocketWithClients();
|
||||||
|
else console.log("Modbus_reader: no modbus device in configuration");
|
||||||
|
|
||||||
// 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);
|
||||||
|
|
|
||||||
|
|
@ -4,7 +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 = 7;
|
exports.input = 8;
|
||||||
exports.output = 1;
|
exports.output = 1;
|
||||||
|
|
||||||
const { exec } = require('child_process');
|
const { exec } = require('child_process');
|
||||||
|
|
@ -38,10 +38,12 @@ exports.install = function(instance) {
|
||||||
else instance.send(0, stdout);
|
else instance.send(0, stdout);
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
instance.on("7", _ => {
|
||||||
|
instance.send(0, FLOW.deviceStatus);
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const rpcSwitchOffLine =
|
const rpcSwitchOffLine =
|
||||||
{
|
{
|
||||||
"topic": "v1/gateway/rpc",
|
"topic": "v1/gateway/rpc",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue