Actual and history event-alarm

Hello everyone,
I'm new to using node-red. I come from the plc-hmi world.
I explain my problem.
At home I installed a plc that manages part of home automation, I use node-red on a raspberry that reads variables and also creates graphics, sends telegram messages, emails.
All this is already done and operational.

I stopped in wanting to create, as in the operator panels, the list of current alarms and alarm history.
I set up a csv with the various alarms, I send a word with the active alarms but I don't know how to manage it to display the string associated with the incoming alarm.

Thanks to everyone who help me

HI and welcome to the magic world of Node-Red.

Though I don't use CSV files, this is what I use:

Press the GENERATE button and get a result.
If there is a list shown, it wipes and refreshes the list.
To clear you have to double press the WIPE button. (Not shown)

This is the flow (picture first)

Basically it generates a list from reading the file and spits it into an array on the screen.

Extra nodes needed:

node-red-contrib-ring-buffer
node-red-contrib-fan (though you can just get rid of this node.) I use it to help make flows neater.

Code:

[{"id":"f75b2cbd.eae688","type":"ui_button","z":"a3bd09a.b852978","name":"Generate command history list","group":"7ef9a31d.7430bc","order":1,"width":"4","height":"1","passthru":false,"label":"Generate","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"date","topic":"","x":240,"y":520,"wires":[["ecea66d4.7d5ca","f4f65650.d8d868"]]},{"id":"ecea66d4.7d5ca","type":"delay","z":"a3bd09a.b852978","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":490,"y":520,"wires":[["1c62a613.05e212"]]},{"id":"f4f65650.d8d868","type":"change","z":"a3bd09a.b852978","name":"Clear","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":620,"wires":[["9ef5f475.ef8b"]]},{"id":"1c62a613.05e212","type":"exec","z":"a3bd09a.b852978","command":"tail -n11 /media/pi/9020-9C27/events/commands_received.txt | cat","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Cat","x":470,"y":570,"wires":[["3f29b235.b18f7e","e5e5fd93.8f284"],[],[]]},{"id":"9ef5f475.ef8b","type":"ring-buffer","z":"a3bd09a.b852978","name":"","capacity":"11","order":"new-to-old","sendOnlyIfFull":false,"pushAfterClear":false,"extra":false,"perTopic":false,"x":700,"y":740,"wires":[["726be7f.ec9c398"]]},{"id":"3f29b235.b18f7e","type":"split","z":"a3bd09a.b852978","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":680,"y":560,"wires":[["8932ae4.4f5dfd"]]},{"id":"e5e5fd93.8f284","type":"debug","z":"a3bd09a.b852978","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":700,"y":510,"wires":[]},{"id":"56d150c1.6417f8","type":"inject","z":"a3bd09a.b852978","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":310,"y":570,"wires":[["1c62a613.05e212"]]},{"id":"726be7f.ec9c398","type":"ui_template","z":"a3bd09a.b852978","group":"7ef9a31d.7430bc","name":"Command history","order":0,"width":"7","height":"6","format":"<table id=\"table\" border=\"1\">\n <tr>\n <th>Commands received</th> \n </tr>\n <tbody>\n <tr ng-repeat=\"row in msg.payload track by $index\">\n <td class=\"text\" >{{row}}</td>\n </tr>\n </tbody>\n</table>\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":900,"y":740,"wires":[[]]},{"id":"8932ae4.4f5dfd","type":"switch","z":"a3bd09a.b852978","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":680,"y":610,"wires":[["9ef5f475.ef8b"]]},{"id":"f40fd09e.dffd3","type":"change","z":"a3bd09a.b852978","name":"clear","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":470,"y":740,"wires":[["9ef5f475.ef8b"]]},{"id":"ae1576e6.e1627","type":"inject","z":"a3bd09a.b852978","name":"Clear","topic":"","payload":"true","payloadType":"bool","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":300,"y":740,"wires":[["f40fd09e.dffd3"]]},{"id":"7a53a2e8.f53d7c","type":"fan","z":"a3bd09a.b852978","x":470,"y":700,"wires":[["f40fd09e.dffd3"]]},{"id":"1f58a05c.0b4d9","type":"switch","z":"a3bd09a.b852978","name":"","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"CONTROL","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":470,"y":660,"wires":[["7a53a2e8.f53d7c"]]},{"id":"e34409ef.7eed18","type":"function","z":"a3bd09a.b852978","name":"Push Button","func":"var state = context.get(\"STATE\")||0;\nvar enabled = context.get(\"ENABLED\")||0;\n\n//  Look for a message with topic set to SETUP to set values.\nif (msg.topic == \"SETUP\")     //Do this if the message is NOT \"X\"\n{\n    //\n    //  Background colours first.\n    //\n    context.set(\"ABGC\", msg.colourA);\n    context.set(\"BBGC\", msg.colourB);\n    //\n    //  Disabled button background colour.\n    //\n    context.set(\"DISABLEDCLR\",msg.disabledColour);\n    //\n    //  Now do text.\n    //\n    context.set(\"Atxt\", msg.txtA);\n    context.set(\"Btxt\", msg.txtB);\n    //\n    //  Font colours.\n    //\n    context.set(\"AFC\",msg.txtclrA);\n    context.set(\"BFC\",msg.txtclrB);\n    //\n    //  Payloads.\n    //\n    context.set(\"PayloadA\", msg.payloadA);\n    context.set(\"PayloadB\", msg.payloadB);\n    //\n    //  Topic.\n    //\n    if (msg.topicSET !== null)\n    {\n        context.set(\"Topic\",msg.topicSET);\n    } else\n    {\n        context.set(\"Topic\",\"~\");\n    }\n    msg.txt = msg.txtA;\n    msg.colour = msg.disabledColour;\n    msg.fontclr = msg.txtclrA;\n    return msg;\n}\n\n//      Now on to the real stuff.\nif (msg.payload == \"X\")\n{\n    //node.warn(\"X detected\");\n    //  Insert here code to enable other stuff.\n//    if (context.get(\"ENABLED\") === 0)\n    if (enabled === 0)\n    {\n        //node.warn(\"State = \" + state);\n\n        context.set(\"ENABLED\",1);\n        if (state === 0)\n        {\n            //\n            //  Set things for state 0\n            //\n            //node.warn(\"State 0 detected\");\n            msg.payload = context.get(\"PayloadA\");\n            msg.colour = context.get(\"ABGC\");\n            msg.txt = context.get(\"Atxt\");\n            msg.fontclr = context.get(\"AFC\");\n        }\n        else if (state === 1)\n        {\n            //\n            //  Set things for state 1\n            //\n            //node.warn(\"State 1 detected\");\n            msg.payload = context.get(\"PayloadB\");\n            msg.colour = context.get(\"BBGC\");\n            msg.txt = context.get(\"Btxt\");\n            msg.fontclr = context.get(\"BFC\");\n        }\n        return msg;\n    }\n    \n    //\n    //\n    //  Block deleted here\n    //\n    //\n\n    state = (state + 1)% 2;\n    //node.warn(state);\n//    context.set(\"STATE\",state);\n    if (enabled === 1)\n    {\n        if (state === 0)\n        {\n            //  Condition A\n            msg.payload = context.get(\"PayloadA\");\n            msg.colour = context.get(\"ABGC\");\n            msg.txt = context.get(\"Atxt\");\n            msg.fontclr = context.get(\"AFC\");\n        } else\n        if (state === 1)\n        {\n            //  Condition B\n            msg.payload = context.get(\"PayloadB\");\n            msg.colour = context.get(\"BBGC\");\n            msg.txt = context.get(\"Btxt\");\n            msg.fontclr = context.get(\"BFC\");\n        }\n    }\n\n    \n    if (context.get(\"Topic\") == \"~\")\n    {\n        msg.topic = \"\";\n    } else\n    {\n        msg.topic = context.get(\"Topic\");\n    }\n    return msg;\n}\nif (msg.payload == \"Z\")\n{\n    //\n    ////node.warn(\"Timed out\");\n    //\n    context.set(\"ENABLED\",0);\n    if (state === 0)\n    {\n        //\n        //  Set things for state 1\n        //\n        msg.payload = context.get(\"PayloadA\");\n        msg.colour = context.get(\"DISABLEDCLR\");\n        msg.txt = context.get(\"Atxt\");\n        msg.fontclr = context.get(\"AFC\");\n    }\n    else if (state === 1)\n    {\n        //\n        //  Set things for state 2\n        //\n        msg.payload = context.get(\"PayloadB\");\n        msg.colour = context.get(\"DISABLEDCLR\");\n        msg.txt = context.get(\"Btxt\");\n        msg.fontclr = context.get(\"BFC\");\n    }\n    return msg;\n}\n","outputs":1,"noerr":0,"x":320,"y":660,"wires":[["ad2b43b2.2231e8","1f58a05c.0b4d9"]]},{"id":"64884b34.210cec","type":"function","z":"a3bd09a.b852978","name":"Setup","func":"msg = {\n    \"topic\":\"SETUP\",\n    \"disabledColour\":\"brown\",\n    \"colourA\": \"yellow\",\n    \"colourB\": \"green\",\n    \"txtA\": \"Wipe\",\n    \"txtB\": '<font color = \"white\"><i class=\"material-icons\"> check_circle_outline</i></font>',\n    \"txtclrA\": \"black\",\n    \"txtclrB\": \"black\",\n    \"payloadA\": 0,\n    \"payloadB\": 1,\n    \"topicSET\": \"CONTROL\"\n}\nreturn msg;","outputs":1,"noerr":0,"x":140,"y":660,"wires":[["e34409ef.7eed18"]]},{"id":"ad2b43b2.2231e8","type":"ui_button","z":"a3bd09a.b852978","name":"Wipe","group":"7ef9a31d.7430bc","order":3,"width":"2","height":"1","passthru":false,"label":"{{msg.txt}}","tooltip":"","color":"{{msg.fontclr}}","bgcolor":"{{msg.colour}}","icon":"","payload":"X","payloadType":"str","topic":"","x":300,"y":620,"wires":[["e34409ef.7eed18","48f240af.2173a8"]]},{"id":"48f240af.2173a8","type":"trigger","z":"a3bd09a.b852978","op1":"","op2":"Z","op1type":"nul","op2type":"str","duration":"3","extend":false,"units":"s","reset":"","bytopic":"all","name":"","x":310,"y":700,"wires":[["e34409ef.7eed18"]]},{"id":"b7e4afff.b114a8","type":"inject","z":"a3bd09a.b852978","name":"Inject","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":"3","x":140,"y":620,"wires":[["64884b34.210cec"]]},{"id":"7ef9a31d.7430bc","type":"ui_group","z":"","name":"Commands received","tab":"22b3809f.04cca","order":2,"disp":true,"width":"7","collapse":false},{"id":"22b3809f.04cca","type":"ui_tab","z":"","name":"History","icon":"dashboard","order":6,"disabled":false,"hidden":false}]

You will have to edit some parts of the flow (and maybe some global values.)
But I think mostly the exec node.

Sorry for the brief reply, but I hope you can see your way to getting it working.

Thank you i'll try. and i hope

depending on your web knowledge you may also want to take a look at 'uibuilder' to display active alarms and alarm history in separate tables.

I had a sample of code that i use...........right but not practical to use. Do you know a better way?

[{"id":"93bf5ef6.a059","type":"delay","z":"9bbffea9.f46ad","name":"","pauseType":"delay","timeout":"100","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":590,"y":280,"wires":[["8f918f1d.c225d"]]},{"id":"92860ae4.b57278","type":"change","z":"9bbffea9.f46ad","name":"Clear","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":790,"y":380,"wires":[["9a0f490e.977568"]]},{"id":"8f918f1d.c225d","type":"exec","z":"9bbffea9.f46ad","command":"tail -n20 /home/pi/logging_history.csv | cat","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Cat","x":790,"y":280,"wires":[["5c9b4292.ae818c"],[],[]]},{"id":"9a0f490e.977568","type":"ring-buffer","z":"9bbffea9.f46ad","name":"","capacity":"20","order":"new-to-old","sendOnlyIfFull":false,"pushAfterClear":false,"extra":false,"perTopic":false,"x":1400,"y":320,"wires":[["8b4c07f0.3e6a38"]]},{"id":"5c9b4292.ae818c","type":"split","z":"9bbffea9.f46ad","name":"","splt":"\\n","spltType":"str","arraySplt":1,"arraySpltType":"len","stream":false,"addname":"","x":990,"y":280,"wires":[["42f3140a.a9e9ec"]]},{"id":"b1e1bcef.39c69","type":"debug","z":"9bbffea9.f46ad","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1010,"y":320,"wires":[]},{"id":"8b4c07f0.3e6a38","type":"ui_template","z":"9bbffea9.f46ad","group":"4698ecb8.dd1894","name":"Command history","order":6,"width":25,"height":20,"format":"<table id=\"table\" border=\"1\">\n\n<style>\ntable {\n  font-family: arial, sans-serif;\n  border-collapse: collapse;\n  width: 100%;\n}\n\ntd, th {\n  border: 1px solid #dddddd;\n  text-align: center;\n  padding: 8px;\n}\n\ntr:nth-child(even) {\n  background-color: teal;\n}\n</style>\n <tr>\n    <th width=80 >Date</th>\n    <th width=20 >Nr</th> \n    <th width=300 >Message</th>\n    <th width=10 >Status</th>\n  </tr>\n <tbody>\n <tr ng-repeat=\"row in msg.payload track by $index\">\n    <td class=\"text\" width=80 ><div align=\"left\">{{row.split(\";\")[0]}}</div></td>\n    <td class=\"text\" width=20><div align=\"center\">{{row.split(\";\")[1]}}</div></td>\n    <td class=\"text\" width=300><div align=\"left\">{{row.split(\";\")[2]}}</div></td>\n    <td class=\"text\" width=10><div align=\"center\">{{row.split(\";\")[3]}}</div></td>\n </tr>\n\n </tbody>\n</table>\n\n","storeOutMessages":true,"fwdInMessages":true,"templateScope":"local","x":1630,"y":320,"wires":[[]]},{"id":"42f3140a.a9e9ec","type":"switch","z":"9bbffea9.f46ad","name":"","property":"payload","propertyType":"msg","rules":[{"t":"nempty"}],"checkall":"true","repair":false,"outputs":1,"x":1170,"y":280,"wires":[["9a0f490e.977568"]]},{"id":"7a6e648c.d6d92c","type":"comment","z":"9bbffea9.f46ad","name":"Creo storico allarmi","info":"","x":150,"y":40,"wires":[]},{"id":"52e6b76c.b367d8","type":"inject","z":"9bbffea9.f46ad","name":"","topic":"","payload":"true","payloadType":"bool","repeat":"60","crontab":"","once":false,"onceDelay":0.1,"x":210,"y":100,"wires":[["b1a33a61.0eaf38"]]},{"id":"b1a33a61.0eaf38","type":"file in","z":"9bbffea9.f46ad","name":"","filename":"/home/pi/alarm.csv","format":"lines","chunk":false,"sendError":false,"encoding":"none","x":430,"y":100,"wires":[["50abce5e.f788b"]]},{"id":"31a84350.80b17c","type":"function","z":"9bbffea9.f46ad","name":"Creo array di object da elenco allarmi","func":"var alarm = new Array(300);\nalarm=msg.payload;\nglobal.set('alarms',alarm);\nreturn msg;","outputs":1,"noerr":0,"x":910,"y":100,"wires":[[]]},{"id":"50abce5e.f788b","type":"csv","z":"9bbffea9.f46ad","name":"","sep":";","hdrin":"","hdrout":"","multi":"mult","ret":"\\n","temp":"","skip":"0","strings":true,"x":610,"y":100,"wires":[["31a84350.80b17c"]]},{"id":"6e1676a9.792368","type":"function","z":"9bbffea9.f46ad","name":"Select from array","func":"var date;\ndate = new Date();\ndate = (date.getFullYear() + '-' + ('00' + (date.getMonth()+1)).slice(-2) + '-' + ('00' + date.getDate()).slice(-2) + ' ' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2));\n\n//Copio valori da array creato\nvar Topics=new Array(300);\nTopics=global.get('alarms');\n\n//Creo input array\nvar IntIn=new Array(32);\nIntIn[0] = msg.payload.Allarmi_1;\nIntIn[1] = msg.payload.Allarmi_2;\n\n\n//array di appoggio\nvar OutputBit = new Array(32);\nvar old_OutputBit = context.get('old_OutputBit')||0;\nvar index = new Array(32);\nvar old_index = context.get('old_index')||0;\n\n//contatori indipendenti\nvar c = 0;\nvar a = 0;\n// A loop that will run 16 times checking the value of each bit.i will increment 1, 2, 4, 8, 16 and so on. \n//& is a bitwiseand bit\nfor (h = 0; h <= 1; h++){ \nc=0;    \n    for (i = 1; i <= 32768; i = i * 2){ \n        \n        if ((IntIn[a] & i) > 0) {\n            index[c+(a*16)]=1;\n        } else {\n            index[c+(a*16)]=0;\n        }\n    \n        if (index[c+(a*16)]!=old_index[c+(a*16)]) {\n            OutputBit[c+(a*16)] = {payload:(date+';'+(Topics[c+(a*16)].col1)+';'+(Topics[c+(a*16)].col2)+';'+index[c+(a*16)])};\n        } else {\n            OutputBit[c+(a*16)] = old_OutputBit[c+(a*16)];\n        }\n        \n    c ++ // increment by 1\n    }\n\na ++ //Increment c by 1\n}\n//Return the entire message array. The function must have 32 outputs.\ncontext.set('old_OutputBit',OutputBit)\ncontext.set('old_index',index)\nreturn OutputBit;","outputs":32,"noerr":0,"x":430,"y":1080,"wires":[["a7418c7.bc4627"],["4c6ea1d2.5e291"],["6515a81.912fb58"],["16a867ae.df98a8"],["d108386.831c3c8"],["459872bc.fb9e1c"],["dba50d26.800b8"],["d8d63e8d.fd463"],["2a9d976b.72fb88"],["69024d7.0acfbb4"],["71776cbb.841a94"],["64145828.8242e8"],["6e141af7.803564"],["a626f958.a75628"],["7768657f.3e5d5c"],["7a8b8358.10640c"],["357f1756.30ec98"],["f664db15.40abe8"],["57d2f72a.3ae2b8"],["b58744f.425b1b8"],["7eea8c1c.4693a4"],["fdc0d110.e6663"],["a7e58249.f7585"],["bdb0dbcf.6d9a78"],["2bb5d464.954bec"],["b014f24c.7358e"],["3887b747.153168"],["dd2f4eab.9b707"],["f6b8f226.2a396"],["b76f1f3a.39fd6"],["d64c172f.6169c8"],["49807a51.fd0544"]]},{"id":"eaacd90c.0171e8","type":"file","z":"9bbffea9.f46ad","name":"History","filename":"/home/pi/logging_history.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","x":1590,"y":1020,"wires":[[]]},{"id":"63cbdaeb.b29ee4","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"single","variable":"Allarmi_1","diff":true,"name":"","x":120,"y":280,"wires":[["7d9233b3.c596cc"]]},{"id":"16a867ae.df98a8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":640,"wires":[["eaacd90c.0171e8"]]},{"id":"d108386.831c3c8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":680,"wires":[["eaacd90c.0171e8"]]},{"id":"459872bc.fb9e1c","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":720,"wires":[["eaacd90c.0171e8"]]},{"id":"dba50d26.800b8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":760,"wires":[["eaacd90c.0171e8"]]},{"id":"d8d63e8d.fd463","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":800,"wires":[["eaacd90c.0171e8"]]},{"id":"2a9d976b.72fb88","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":840,"wires":[["eaacd90c.0171e8"]]},{"id":"69024d7.0acfbb4","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":880,"wires":[["eaacd90c.0171e8"]]},{"id":"71776cbb.841a94","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":920,"wires":[["eaacd90c.0171e8"]]},{"id":"64145828.8242e8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":960,"wires":[["eaacd90c.0171e8"]]},{"id":"6e141af7.803564","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1000,"wires":[["eaacd90c.0171e8"]]},{"id":"a626f958.a75628","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1040,"wires":[["eaacd90c.0171e8"]]},{"id":"7768657f.3e5d5c","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1080,"wires":[["eaacd90c.0171e8"]]},{"id":"7a8b8358.10640c","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1120,"wires":[["eaacd90c.0171e8"]]},{"id":"a7418c7.bc4627","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":520,"wires":[["eaacd90c.0171e8"]]},{"id":"4c6ea1d2.5e291","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":560,"wires":[["eaacd90c.0171e8"]]},{"id":"6515a81.912fb58","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":600,"wires":[["eaacd90c.0171e8"]]},{"id":"b58744f.425b1b8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1300,"wires":[["eaacd90c.0171e8"]]},{"id":"7eea8c1c.4693a4","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1340,"wires":[["eaacd90c.0171e8"]]},{"id":"fdc0d110.e6663","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1380,"wires":[["eaacd90c.0171e8"]]},{"id":"a7e58249.f7585","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1420,"wires":[["eaacd90c.0171e8"]]},{"id":"bdb0dbcf.6d9a78","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1460,"wires":[["eaacd90c.0171e8"]]},{"id":"2bb5d464.954bec","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1500,"wires":[["eaacd90c.0171e8"]]},{"id":"b014f24c.7358e","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1540,"wires":[["eaacd90c.0171e8"]]},{"id":"3887b747.153168","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1580,"wires":[["eaacd90c.0171e8"]]},{"id":"dd2f4eab.9b707","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1620,"wires":[["eaacd90c.0171e8"]]},{"id":"f6b8f226.2a396","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1660,"wires":[["eaacd90c.0171e8"]]},{"id":"b76f1f3a.39fd6","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1700,"wires":[["eaacd90c.0171e8"]]},{"id":"d64c172f.6169c8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1740,"wires":[["eaacd90c.0171e8"]]},{"id":"49807a51.fd0544","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1780,"wires":[["eaacd90c.0171e8"]]},{"id":"357f1756.30ec98","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1180,"wires":[["eaacd90c.0171e8"]]},{"id":"f664db15.40abe8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":870,"y":1220,"wires":[["eaacd90c.0171e8"]]},{"id":"57d2f72a.3ae2b8","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":850,"y":1260,"wires":[["eaacd90c.0171e8"]]},{"id":"2c82e29a.6cbbae","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"single","variable":"Allarmi_2","diff":true,"name":"","x":120,"y":340,"wires":[["c8581f4.4b426e"]]},{"id":"7d9233b3.c596cc","type":"link out","z":"9bbffea9.f46ad","name":"Word_1","links":["abae3fb5.c7bcb","4b5d4a2b.e2e564"],"x":235,"y":280,"wires":[]},{"id":"c8581f4.4b426e","type":"link out","z":"9bbffea9.f46ad","name":"","links":["abae3fb5.c7bcb","4b5d4a2b.e2e564"],"x":235,"y":340,"wires":[]},{"id":"abae3fb5.c7bcb","type":"link in","z":"9bbffea9.f46ad","name":"Canged_alarm_value","links":["7d9233b3.c596cc","c8581f4.4b426e"],"x":355,"y":280,"wires":[["93bf5ef6.a059","92860ae4.b57278"]]},{"id":"ccd062b1.8c964","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"all","variable":"","diff":true,"name":"","x":180,"y":1080,"wires":[["6e1676a9.792368"]]},{"id":"bf97f077.348a1","type":"comment","z":"9bbffea9.f46ad","name":"Leggo i valori che cambiano e li scrivo in un file di archivio","info":"","x":270,"y":520,"wires":[]},{"id":"318b312.30a17ce","type":"comment","z":"9bbffea9.f46ad","name":"Aggiorno la visualizzazione","info":"","x":170,"y":200,"wires":[]},{"id":"4698ecb8.dd1894","type":"ui_group","z":"","name":"History_Alarm","tab":"a114e290.f4417","disp":true,"width":25,"collapse":false},{"id":"73e529c2.107728","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.160","port":"102","rack":"0","slot":"0","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"","vartable":[{"addr":"QB0","name":"Speed"},{"addr":"DB2,i0","name":"Power"},{"addr":"DB2,i2","name":"Temperature"},{"addr":"I0.0","name":"TriggerMessage"},{"addr":"Q1.0","name":"uscita"},{"addr":"DB2,I24","name":"Allarmi_1"},{"addr":"DB2,I26","name":"Allarmi_2"},{"addr":"DB2,I28","name":"Allarmi_3"},{"addr":"DB2,I30","name":"Allarmi_4"},{"addr":"DB2,I32","name":"Allarmi_5"},{"addr":"DB2,I34","name":"Allarmi_6"},{"addr":"DB2,I36","name":"Allarmi_7"},{"addr":"DB2,I38","name":"Allarmi_8"},{"addr":"DB2,I40","name":"Allarmi_9"},{"addr":"DB2,I42","name":"Allarmi_10"},{"addr":"DB2,I44","name":"Allarmi_11"},{"addr":"DB2,I46","name":"Allarmi_12"},{"addr":"DB2,I48","name":"Allarmi_13"},{"addr":"DB2,I50","name":"Allarmi_14"},{"addr":"DB2,I52","name":"Allarmi_15"},{"addr":"DB2,I54","name":"Allarmi_16"},{"addr":"DB2,I56","name":"Allarmi_17"},{"addr":"DB2,I58","name":"Allarmi_18"},{"addr":"DB2,I60","name":"Allarmi_19"},{"addr":"DB2,I62","name":"Allarmi_20"},{"addr":"DB2,I64","name":"Allarmi_21"}]},{"id":"a114e290.f4417","type":"ui_tab","z":"","name":"History","icon":"dashboard","disabled":false,"hidden":false}]

I get only change of state (from 0 to 1, and from 1 to 0) but 32 output and 32 rbe for me isn't good.

[{"id":"97263d0a.d9c74","type":"s7 in","z":"9bbffea9.f46ad","endpoint":"73e529c2.107728","mode":"all","variable":"Allarmi_1","diff":false,"name":"","x":160,"y":760,"wires":[["51a8f764.b76658"]]},{"id":"9eebd216.fb607","type":"rbe","z":"9bbffea9.f46ad","name":"","func":"rbei","gap":"","start":"","inout":"out","property":"payload","x":690,"y":760,"wires":[["9c1b9790.fe69d8"]]},{"id":"51a8f764.b76658","type":"function","z":"9bbffea9.f46ad","name":"Select from array","func":"var date;\ndate = new Date();\ndate = (date.getFullYear() + '-' + ('00' + (date.getMonth()+1)).slice(-2) + '-' + ('00' + date.getDate()).slice(-2) + ' ' + ('00' + date.getHours()).slice(-2) + ':' + ('00' + date.getMinutes()).slice(-2) + ':' + ('00' + date.getSeconds()).slice(-2));\n\n//Copio valori da array creato\nvar Topics=new Array(300);\nTopics=global.get('alarms');\n\n//Creo input array\nvar IntIn=new Array(32);\nIntIn[0] = msg.payload.Allarmi_1;\nIntIn[1] = msg.payload.Allarmi_2;\n\n\n//array di appoggio\nvar OutputBit = new Array(32);\n\nvar index = new Array(32);\nvar old_index = context.get('old_index')||0;\n\n//contatori indipendenti\nvar c = 0;\nvar n = 0;\n// A loop that will run 16 times checking the value of each bit.i will increment 1, 2, 4, 8, 16 and so on. \n//& is a bitwiseand bit\nfor (h = 0; h <= 1; h++){ \n    c=0;    \n    for (i = 1; i <= 32768; i = i * 2){ \n        \n        if ((IntIn[h] & i) > 0) {\n            index[c+(h*16)]=1;\n        } else {\n            index[c+(h*16)]=0;\n        }\n        c++;\n    }\n}\n\nfor (l = 0; l <= 1; l++){\n    for (d=0;d<=15;d++){\n        if (index[n]!=old_index[n]) {\n            OutputBit[n] = {payload:(date+';'+(Topics[n].col1)+';'+(Topics[n].col2)+';'+index[n])};\n            node.send(OutputBit[n]);\n        }\n        n++;\n        \n    }\n}\n\n//Return the entire message array. The function must have 32 outputs.\n\ncontext.set('old_index',index);\n","outputs":1,"noerr":0,"x":450,"y":760,"wires":[["9eebd216.fb607"]]},{"id":"9c1b9790.fe69d8","type":"file","z":"9bbffea9.f46ad","name":"History","filename":"/home/pi/data/alarm/today.csv","appendNewline":true,"createDir":true,"overwriteFile":"false","x":870,"y":760,"wires":[[]]},{"id":"73e529c2.107728","type":"s7 endpoint","z":"","transport":"iso-on-tcp","address":"192.168.0.160","port":"102","rack":"0","slot":"0","localtsaphi":"01","localtsaplo":"00","remotetsaphi":"01","remotetsaplo":"00","connmode":"rack-slot","adapterauto":true,"adapterport":"","busaddr":"","adapteraddr":"0","cycletime":"500","timeout":"1500","verbose":"default","name":"","vartable":[{"addr":"QB0","name":"Speed"},{"addr":"DB2,i0","name":"Power"},{"addr":"DB2,i2","name":"Temperature"},{"addr":"m0.7","name":"TriggerMessage"},{"addr":"Q1.0","name":"uscita"},{"addr":"DB2,I24","name":"Allarmi_1"},{"addr":"DB2,I26","name":"Allarmi_2"},{"addr":"DB2,I28","name":"Allarmi_3"},{"addr":"DB2,I30","name":"Allarmi_4"},{"addr":"DB2,I32","name":"Allarmi_5"},{"addr":"DB2,I34","name":"Allarmi_6"},{"addr":"DB2,I36","name":"Allarmi_7"},{"addr":"DB2,I38","name":"Allarmi_8"},{"addr":"DB2,I40","name":"Allarmi_9"},{"addr":"DB2,I42","name":"Allarmi_10"},{"addr":"DB2,I44","name":"Allarmi_11"},{"addr":"DB2,I46","name":"Allarmi_12"},{"addr":"DB2,I48","name":"Allarmi_13"},{"addr":"DB2,I50","name":"Allarmi_14"},{"addr":"DB2,I52","name":"Allarmi_15"},{"addr":"DB2,I54","name":"Allarmi_16"},{"addr":"DB2,I56","name":"Allarmi_17"},{"addr":"DB2,I58","name":"Allarmi_18"},{"addr":"DB2,I60","name":"Allarmi_19"},{"addr":"DB2,I62","name":"Allarmi_20"},{"addr":"DB2,I64","name":"Allarmi_21"}]}]

This is my solution whit infinity word of alarm. it works fine for me

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.