Table des matières

Idées pour compteurs avec node red

un compteur avec remise à zéro, A adapter ….

Nota : cette variable est seulement connue dans le flux , ce n'est pas une variable globale ni persistante …mais je pense que c'est possible de le faire

la fonction :

fonction.js
var compteur1 = flow.get("compteur1") || 0
compteur1++
if (compteur1 === 6)// remise à zero à 6
{
compteur1 = 0;
}
flow.set("compteur1",compteur1)
msg.payload = compteur1
return msg;

les nœuds à importer pour essais:

compteur1_essai_flows.json.zip

compteur.js
[ { "id": "745389f46bba8f47", "type": "inject", "z": "968dc7d3a4ac9207", "name": "+1", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 190, "y": 500, "wires": [ [ "79a0decfbb064151" ] ] }, { "id": "79a0decfbb064151", "type": "function", "z": "968dc7d3a4ac9207", "name": "function 6", "func": "var compteur1 = flow.get(\"compteur1\") || 0\ncompteur1++\nif (compteur1 === 6)\n{\n compteur1 = 0;\n}\nflow.set(\"compteur1\",compteur1)\nmsg.payload = compteur1\nreturn msg;", "outputs": 1, "timeout": 0, "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 440, "y": 500, "wires": [ [ "b8e4eebc720c258b", "4910c8c53a1e402a" ] ] }, { "id": "b8e4eebc720c258b", "type": "debug", "z": "968dc7d3a4ac9207", "name": "debug 56", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 700, "y": 500, "wires": [] }, { "id": "3cb31948362869ec", "type": "inject", "z": "968dc7d3a4ac9207", "name": "Remise à Zero", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "date", "x": 200, "y": 580, "wires": [ [ "71bb8df28449e565" ] ] }, { "id": "71bb8df28449e565", "type": "change", "z": "968dc7d3a4ac9207", "name": "", "rules": [ { "t": "set", "p": "compteur1", "pt": "flow", "to": "0", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 460, "y": 580, "wires": [ [ "79a0decfbb064151" ] ] }, { "id": "4910c8c53a1e402a", "type": "ui_text", "z": "968dc7d3a4ac9207", "group": "7d39b6925b5fda69", "order": 4, "width": 0, "height": 0, "name": "", "label": "Compteur1", "format": "{{msg.payload}}", "layout": "row-spread", "className": "", "style": false, "font": "", "fontSize": 16, "color": "#000000", "x": 710, "y": 440, "wires": [] }, { "id": "83e4d61a37937888", "type": "ui_button", "z": "968dc7d3a4ac9207", "name": "", "group": "7d39b6925b5fda69", "order": 5, "width": 0, "height": 0, "passthru": false, "label": "bouton +1", "tooltip": "", "color": "", "bgcolor": "", "className": "", "icon": "", "payload": "1", "payloadType": "str", "topic": "topic", "topicType": "msg", "x": 180, "y": 540, "wires": [ [ "79a0decfbb064151" ] ] }, { "id": "7d39b6925b5fda69", "type": "ui_group", "name": "Default", "tab": "8b1ceed22ac65836", "order": 1, "disp": true, "width": "6", "collapse": false, "className": "" }, { "id": "8b1ceed22ac65836", "type": "ui_tab", "name": "compteurs", "icon": "dashboard", "order": 1, "disabled": false, "hidden": false } ]