From 75bb2794d2414962cdde7791026bbb54816a37da Mon Sep 17 00:00:00 2001 From: rasta5man Date: Mon, 13 Jan 2025 15:39:53 +0100 Subject: [PATCH] actual version before - turnOff on startup change --- flow/cmd_manager.js | 58 +++--------------------------- flow/count.js | 60 ++++++++++++++++++++++++++++++++ flow/db_init.js | 2 +- flow/dido_controller.js | 11 ++---- flow/helper/serialport_helper.js | 2 +- 5 files changed, 69 insertions(+), 64 deletions(-) create mode 100644 flow/count.js diff --git a/flow/cmd_manager.js b/flow/cmd_manager.js index a960aaa..280a5a6 100644 --- a/flow/cmd_manager.js +++ b/flow/cmd_manager.js @@ -118,11 +118,10 @@ exports.install = function(instance) { priorities["7"] = minutes; priorities["80"] = minutes; priorities["8"] = minutes; - priorities["3"] = minutes; priorities["89"] = minutes; //prikazy kt sa budu spustat na dany node - see config.js in terminal-oms.app. (1 - dimming) - let listOfCommands = [0, 1, 3, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 84, 87, 89]; + let listOfCommands = [0, 1, 6, 7, 8, 74, 75, 76, 77, 78, 79, 80, 84, 87, 89]; const errorHandler = new ErrorToServiceHandler(); @@ -133,7 +132,6 @@ exports.install = function(instance) { let relaysData; let nodesData; - let rvoTbName; let sunCalcResult; let reportDuskDawn; @@ -159,11 +157,7 @@ exports.install = function(instance) { tbHandler = new DataToTbHandler(SEND_TO.tb); tbHandler.setSender(exports.title); - //SETTINGS.project_id, name: SETTINGS.rvo_name; - //const errorHandler = new ErrorToServiceHandler(instance, SEND_TO.infoSender); errorHandler.setProjectsId(SETTINGS.project_id); - //const errorHandler = new ErrorToServiceHandler(instance); - //errorHandler.sendMessageToService("ahoj", 0); let now = new Date(); console.log("CMD Manager installed", now.toLocaleString("sk-SK")); @@ -225,7 +219,6 @@ exports.install = function(instance) { } params.addMinutesToTimestamp = 0;//repeat task if value is > 0, - //params.timePointName = "luxOff" // "luxOn", "dusk", "dawn", "profileTimepoint" //params.info = ""; //params.debug = true; // will console.log params in writeData response @@ -340,13 +333,6 @@ exports.install = function(instance) { Register úrovne má rovnaký formát ako dimming register (Reg 1). */ - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - //params.byte1 = 0;//msb, podla dokumentacie data3 - //params.byte2 = 0;//podla dokumentacie data2 - //params.byte3 = 0;//podla dokumentacie data1 - //params.byte4 = 0;//lsb, podla dokumentacie data0 - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - let start_time = obj.start_time; let t = start_time.split(":"); //if(timePoint != undefined) t = timePoint.split(":"); @@ -394,16 +380,6 @@ exports.install = function(instance) { } //Threshold lux level for DUSK/DAWN - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - //params.byte1 = 0;//msb, podla dokumentacie data3 - //params.byte2 = 0;//podla dokumentacie data2 - //params.byte3 = 0;//podla dokumentacie data1 - //params.byte4 = 0;//lsb, podla dokumentacie data0 - //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - - //Time schedule settings na koniec - //if(nodeProfile.dusk_lux_sensor || nodeProfile.dawn_lux_sensor) { logger.debug("processNodeProfile: Threshold lux level for DUSK/DAWN", node); @@ -673,16 +649,11 @@ exports.install = function(instance) { function reportOnlineNodeStatus(line) { - //broadcast cas, o 3 sek neskor - status, brightness - //Po zapnutí línie broadcastovo aktualizovať predtým čas. + //Po zapnutí línie broadcastovo aktualizovať predtým čas a o 3 sek neskor - status, brightness logger.debug("--->reportOnlineNodeStatus for line", line); - //return; - //run broadcast //Actual time - addMinutesToTimestamp = 0; - let params = {}; var d = new Date(); @@ -704,7 +675,7 @@ exports.install = function(instance) { //other values params.type = "cmd"; params.timestamp = Date.now() + 60000; - params.addMinutesToTimestamp = addMinutesToTimestamp; + params.addMinutesToTimestamp = 0; params.info = "run broadcast: Actual time"; tasks.push(params); @@ -729,9 +700,7 @@ exports.install = function(instance) { sendTelemetry({ status: status }, tbname, time); - //prud, vykon - current, input power pre liniu pre vsetky nody - - //a pridame aj vyreportovanie dimmingu + //vyreportovanie dimmingu, prud, vykon - current, input power pre liniu pre vsetky nody { let params = getParams(PRIORITY_TYPES.high_priority); @@ -1655,7 +1624,7 @@ exports.install = function(instance) { if (register == 7 && params.recipient === 2) { if (type != "cmd-terminal") { let sunCalcResult = calculateDuskDawn(); - params.byte1 = sunCalcResult["dawn_hours"];//h + params.byte1 = sunCalcResult["dawn_hours"];//h params.byte2 = sunCalcResult["dawn_minutes"];//m params.byte3 = 0;//s params.byte4 = 0; @@ -1969,8 +1938,6 @@ exports.install = function(instance) { logger.debug("CMD manager - rsPort opened success"); - //loadRelaysData(); - await runSyncExec(`stty -F /dev/${SETTINGS.serial_port} 115200 min 1 time 5 ignbrk -brkint -icrnl -imaxbel -opost -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke`).then(function(status) { instance.send(SEND_TO.debug, "RPC runSyncExec - Promise Resolved:" + status); @@ -2801,21 +2768,6 @@ exports.install = function(instance) { values["time_schedule_settings"] = time_schedule_settings; } - //skupinová adresa 1 - if (register == 3) { - let gr_add_1 = bytesToInt(byte0); - values["gr_add_1"] = gr_add_1; - - let gr_add_2 = bytesToInt(byte1); - values["gr_add_2"] = gr_add_2; - - let gr_add_3 = bytesToInt(byte2); - values["gr_add_3"] = gr_add_3; - - let gr_add_4 = bytesToInt(byte3); - values["gr_add_4"] = gr_add_4; - } - //naklon if (register == 84) { let temp; diff --git a/flow/count.js b/flow/count.js new file mode 100644 index 0000000..fa92ee9 --- /dev/null +++ b/flow/count.js @@ -0,0 +1,60 @@ +exports.id = 'count'; +exports.title = 'Count'; +exports.version = '1.0.1'; +exports.author = 'John Graves'; +exports.color = '#656D78'; +exports.icon = 'plus-square'; +exports.input = 2; +exports.output = 1; +exports.options = { increment: 1, initialvalue: 1 }; +exports.readme = `# Counter + +Counter Number of times called.`; + +exports.html = `
+
@(Initial Value)
+
@(Increment)
+

Example Video

+
`; + +exports.readme = `# Count + +This component counts the number of messages received. + +__Response:__ + +Integer value based on the initial value and increment settings. + +__Arguments:__ +- Initial Value: What number should be output on the receipt of the first message. +- Increment: What should the increment be for each following message received.`; + +exports.install = function(instance) { + + var count = 0; + var initialCall = true; + + instance.on('data', function(flowdata) { + var index = flowdata.index; + if (index) { + instance.debug('Reset Count.'); + count = instance.options.initialvalue; + initialCall = true; + } else { + // If this is the first time, set the value to 'initial value' + if(initialCall) { + initialCall = false; + count = instance.options.initialvalue; + } else + count = count+instance.options.increment; + instance.status('Count:' + count); + instance.send2(count); + } + }); + + instance.on('options', function() { + count = instance.options.initialvalue; + initialCall = true; + }); + +}; diff --git a/flow/db_init.js b/flow/db_init.js index c43e4a2..ddd0aa0 100644 --- a/flow/db_init.js +++ b/flow/db_init.js @@ -64,7 +64,7 @@ exports.install = async function(instance) { if(dbs.nodesData.hasOwnProperty("0")) delete dbs.nodesData["0"]; dbs.settings = { - edge_fw_version : "2025-01-02", //rok-mesiac-den + edge_fw_version : "2025-01-09", //rok-mesiac-den language : responseSettings[0]["lang"], rvo_name : responseSettings[0]["rvo_name"], project_id : responseSettings[0]["project_id"], diff --git a/flow/dido_controller.js b/flow/dido_controller.js index 8415921..a6861b4 100644 --- a/flow/dido_controller.js +++ b/flow/dido_controller.js @@ -39,21 +39,18 @@ After that, we set this value to "previousValues[allPins[whichpin]]" variable /* RVO objekt: -state_of_main_switch - sem sa bude reportovať stav hlavného ističa : 0-> off 1-> on (toto nie je na platforme, ale Rado to už do entity type doplnil) +state_of_main_switch - reportovať stav hlavného ističa : 0-> off 1-> on rotary_switch_state - sem by sa mal reportovať stav vstupov manual a auto podľa nasledovnej logiky: Manual = 1 a Auto = 0 -> vyreportuje Manual Manual = 0 a Auto = 0 -> vyreportuje Off Manual = 0 a Auto = 1 -> vyreportuje Automatic -door_condition - tuto ide pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Open +door_condition - pin 6, dverový kontakt -> 1 -> vyreportuje Closed, 0 -> vyreportuje Open twilight_sensor - hodnotu, ktorú vracia ten analógový vstup (17) treba poslať sem ako float number. Zrejme tu potom pridáme nejaký koeficient prevodu na luxy -zjavne nám v jsone chýba stav hlavného ističa. Musíme to potom doplniť - Na každú líniu: state_of_breaker - podľa indexu ističa sa reportuje jeho stav, teda istič 1 na líniu 1: 0-> off 1-> on state_of_contactor - podľa indexu stykača sa reportuje jeho stav, teda stykač 1 na líniu 1: 0-> off 1-> on - momentálne sa stav zmení len keď vo flow klikneš aby sa zmenil, ale tá zmena by sa mala ukázať aj na platforme */ const { errLogger, logger, monitor } = require('./helper/logger'); @@ -319,16 +316,12 @@ exports.install = function(instance) { instance.send(0, exports.title + " running"); turnAlarm("off"); - // useTurnOffCounter = true; - // turnOffCounter = relaysData.length - 1; initialSetting(); ws.send(JSON.stringify({ "cmd": "all" })); // we request dev info about neuron device from evok to keep websocket connection alive // for some reason this request returns no data, but connection keeps alive - // https://evok.api-docs.io/1.0/mpqzDwPwirsoq7i5A/websocket startRequests = setInterval(() => { - // console.log(" *** data from evok requested"); ws.send(JSON.stringify({ "cmd": "filter", "dev": ["neuron"] })); }, 150000) }; diff --git a/flow/helper/serialport_helper.js b/flow/helper/serialport_helper.js index 4a0edd5..8efa6af 100644 --- a/flow/helper/serialport_helper.js +++ b/flow/helper/serialport_helper.js @@ -74,7 +74,7 @@ async function writeData(port, data, readbytes, timeout){ let t = setTimeout(() => { port.removeListener('data', callback); - console.log("serialport helper: writeData TIMEOUT READING", rsPortReceivedData); + //console.log("serialport helper: writeData TIMEOUT READING", rsPortReceivedData); reject("TIMEOUT READING"); }, timeout);