- Home
- Deutsch
- Skripten / Logik
- Node-Red
- Konvertierung Byte nach Dezimal und umgekehrt
Konvertierung Byte nach Dezimal und umgekehrt
-
Aufgrund einer aktuellen Anforderung habe ich mal einen Subflow gebastelt, der Bytes als String in eine Zahl bzw. einen String mit einer durch kommagetrennten Zahlenfolge als String ausgibt.
Hier die Node zum Importieren:
[ { "id": "d9c9c1e0.5e69d", "type": "subflow", "name": "Byte to Decimal", "info": "# Byte to Decimal\nFor a single Byte a number will be the result, for several Bytes a comma seperated string is the result.\n\nThe `msg.payload` needs to be a string, each Byte represented by 2 characters. If there is an odd number is in the string, the first one and not the last one is ignored. \n\nThe string can be prefixed or not - this will be ignored by the subflow\n\n# Bytes nach Dezimal\nDie `msg.payload` muss eine Zeichenkette/String sein, wobei jedes Byte durch 2 Zeichen festgelegt wird. Falls eine ungerade Zahl Zeichen eingegeben, so wird das erste und nicht das letzte Zeichen ignoriert.\n\nBei Eingabe eines Bytes (2 Zeichen) wird eine Zahl zurückgegeben. Anderenfalls eine Zeichenkette/String deren Werte der Bytes durch Kommas getrennt ausgegeben werden. \n\nPräfixes werden ignoriert!", "category": "", "in": [ { "x": 40, "y": 120, "wires": [ { "id": "5dfc7ea9.dacc7" } ] } ], "out": [ { "x": 1680, "y": 80, "wires": [ { "id": "5789b533.ab3f1c", "port": 0 }, { "id": "52580831.7bf218", "port": 0 } ] } ], "env": [], "color": "#E2D96E", "icon": "node-red/parser-csv.svg" }, { "id": "5dfc7ea9.dacc7", "type": "change", "z": "d9c9c1e0.5e69d", "name": "Match Array", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$match(payload, /([\\da-f]{2})+$/i)\t", "tot": "jsonata" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload.match", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "$match(payload,/[\\da-f]{2}/i)\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 190, "y": 120, "wires": [ [ "2e1e4681.070eba" ] ] }, { "id": "3d07c465.1b3f6c", "type": "split", "z": "d9c9c1e0.5e69d", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 640, "y": 160, "wires": [ [ "c2faaf77.92add" ] ] }, { "id": "c2faaf77.92add", "type": "change", "z": "d9c9c1e0.5e69d", "name": "payload = match", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.match", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 820, "y": 160, "wires": [ [ "1aa74150.a187cf" ] ] }, { "id": "1aa74150.a187cf", "type": "function", "z": "d9c9c1e0.5e69d", "name": "to HEX", "func": "msg.payload = parseInt(msg.payload, 16);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 1000, "y": 160, "wires": [ [ "cc5c9f9d.6d62d" ] ] }, { "id": "50984962.df4c28", "type": "join", "z": "d9c9c1e0.5e69d", "name": "sammeln", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 1300, "y": 160, "wires": [ [ "52580831.7bf218" ] ] }, { "id": "52580831.7bf218", "type": "change", "z": "d9c9c1e0.5e69d", "name": "Setze Array zusammen", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$join(payload, ',')\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1490, "y": 160, "wires": [ [] ] }, { "id": "cc5c9f9d.6d62d", "type": "change", "z": "d9c9c1e0.5e69d", "name": "toString", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$string(payload, prettify)\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1150, "y": 160, "wires": [ [ "50984962.df4c28" ] ] }, { "id": "2e1e4681.070eba", "type": "switch", "z": "d9c9c1e0.5e69d", "name": "Output = Array or Number ? ", "property": "payload.match", "propertyType": "msg", "rules": [ { "t": "istype", "v": "string", "vt": "string" }, { "t": "else" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 420, "y": 120, "wires": [ [ "3616e58a.0770ea" ], [ "3d07c465.1b3f6c" ] ] }, { "id": "3616e58a.0770ea", "type": "change", "z": "d9c9c1e0.5e69d", "name": "payload = match", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.match", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 660, "y": 80, "wires": [ [ "5789b533.ab3f1c" ] ] }, { "id": "5789b533.ab3f1c", "type": "function", "z": "d9c9c1e0.5e69d", "name": "to HEX", "func": "msg.payload = parseInt(msg.payload, 16);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 840, "y": 80, "wires": [ [] ] }, { "id": "7bfad8cf.bc95d8", "type": "subflow:d9c9c1e0.5e69d", "z": "6e170384.60c96c", "name": "", "env": [], "x": 2500, "y": 3900, "wires": [ [ "78863adb.5af204", "14c09538.f63b2b" ] ] } ]
Die Node ist in der Standardhilfe beschrieben:
Die Beispiele was die Node ausgibt anhand der Eingaben hier nochmals dargestellt:
Zum Schluss nochmal ein Beispiel wie man so einen String mit den Bytewerten wieder in ein Objekt umwandelt. Beispiel RGB.
Zum Schluß nochmal der gesamte Beispiel Flow zum Import:
[ { "id": "d9c9c1e0.5e69d", "type": "subflow", "name": "Byte to Decimal", "info": "# Byte to Decimal\nFor a single Byte a number will be the result, for several Bytes a comma seperated string is the result.\n\nThe `msg.payload` needs to be a string, each Byte represented by 2 characters. If there is an odd number is in the string, the first one and not the last one is ignored. \n\nThe string can be prefixed or not - this will be ignored by the subflow\n\n# Bytes nach Dezimal\nDie `msg.payload` muss eine Zeichenkette/String sein, wobei jedes Byte durch 2 Zeichen festgelegt wird. Falls eine ungerade Zahl Zeichen eingegeben, so wird das erste und nicht das letzte Zeichen ignoriert.\n\nBei Eingabe eines Bytes (2 Zeichen) wird eine Zahl zurückgegeben. Anderenfalls eine Zeichenkette/String deren Werte der Bytes durch Kommas getrennt ausgegeben werden. \n\nPräfixes werden ignoriert!", "category": "", "in": [ { "x": 40, "y": 120, "wires": [ { "id": "5dfc7ea9.dacc7" } ] } ], "out": [ { "x": 1680, "y": 80, "wires": [ { "id": "5789b533.ab3f1c", "port": 0 }, { "id": "52580831.7bf218", "port": 0 } ] } ], "env": [], "color": "#E2D96E", "icon": "node-red/parser-csv.svg" }, { "id": "5dfc7ea9.dacc7", "type": "change", "z": "d9c9c1e0.5e69d", "name": "Match Array", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$match(payload, /([\\da-f]{2})+$/i)\t", "tot": "jsonata" }, { "t": "set", "p": "payload", "pt": "msg", "to": "payload.match", "tot": "msg" }, { "t": "set", "p": "payload", "pt": "msg", "to": "$match(payload,/[\\da-f]{2}/i)\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 190, "y": 120, "wires": [ [ "2e1e4681.070eba" ] ] }, { "id": "3d07c465.1b3f6c", "type": "split", "z": "d9c9c1e0.5e69d", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 640, "y": 160, "wires": [ [ "c2faaf77.92add" ] ] }, { "id": "c2faaf77.92add", "type": "change", "z": "d9c9c1e0.5e69d", "name": "payload = match", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.match", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 820, "y": 160, "wires": [ [ "1aa74150.a187cf" ] ] }, { "id": "1aa74150.a187cf", "type": "function", "z": "d9c9c1e0.5e69d", "name": "to HEX", "func": "msg.payload = parseInt(msg.payload, 16);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 1000, "y": 160, "wires": [ [ "cc5c9f9d.6d62d" ] ] }, { "id": "50984962.df4c28", "type": "join", "z": "d9c9c1e0.5e69d", "name": "sammeln", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 1300, "y": 160, "wires": [ [ "52580831.7bf218" ] ] }, { "id": "52580831.7bf218", "type": "change", "z": "d9c9c1e0.5e69d", "name": "Setze Array zusammen", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$join(payload, ',')\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1490, "y": 160, "wires": [ [] ] }, { "id": "cc5c9f9d.6d62d", "type": "change", "z": "d9c9c1e0.5e69d", "name": "toString", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$string(payload, prettify)\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1150, "y": 160, "wires": [ [ "50984962.df4c28" ] ] }, { "id": "2e1e4681.070eba", "type": "switch", "z": "d9c9c1e0.5e69d", "name": "Output = Array or Number ? ", "property": "payload.match", "propertyType": "msg", "rules": [ { "t": "istype", "v": "string", "vt": "string" }, { "t": "else" } ], "checkall": "true", "repair": false, "outputs": 2, "x": 420, "y": 120, "wires": [ [ "3616e58a.0770ea" ], [ "3d07c465.1b3f6c" ] ] }, { "id": "3616e58a.0770ea", "type": "change", "z": "d9c9c1e0.5e69d", "name": "payload = match", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "payload.match", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 660, "y": 80, "wires": [ [ "5789b533.ab3f1c" ] ] }, { "id": "5789b533.ab3f1c", "type": "function", "z": "d9c9c1e0.5e69d", "name": "to HEX", "func": "msg.payload = parseInt(msg.payload, 16);\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 840, "y": 80, "wires": [ [] ] }, { "id": "78863adb.5af204", "type": "debug", "z": "6e170384.60c96c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 2710, "y": 3840, "wires": [] }, { "id": "64e0a461.9aa91c", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "0xFF", "payloadType": "str", "x": 2270, "y": 3840, "wires": [ [ "7bfad8cf.bc95d8" ] ] }, { "id": "7bfad8cf.bc95d8", "type": "subflow:d9c9c1e0.5e69d", "z": "6e170384.60c96c", "name": "", "env": [], "x": 2500, "y": 3900, "wires": [ [ "78863adb.5af204", "14c09538.f63b2b" ] ] }, { "id": "d13dab9c.7e7398", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "03", "payloadType": "str", "x": 2270, "y": 3800, "wires": [ [ "7bfad8cf.bc95d8" ] ] }, { "id": "96520e18.1acc8", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "255", "payloadType": "str", "x": 2270, "y": 3880, "wires": [ [ "7bfad8cf.bc95d8" ] ] }, { "id": "762c28fe.249aa8", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "0xFF00FF", "payloadType": "str", "x": 2260, "y": 3920, "wires": [ [ "7bfad8cf.bc95d8" ] ] }, { "id": "e749cdb3.ee418", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "0xAFF00FF", "payloadType": "str", "x": 2250, "y": 3960, "wires": [ [ "7bfad8cf.bc95d8" ] ] }, { "id": "73111c78.827e14", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "#AAFF00FF", "payloadType": "str", "x": 2250, "y": 4000, "wires": [ [ "7bfad8cf.bc95d8" ] ] }, { "id": "14c09538.f63b2b", "type": "split", "z": "6e170384.60c96c", "name": "", "splt": ",", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 2700, "y": 3900, "wires": [ [ "171295b.f07116a" ] ] }, { "id": "b392f58e.316c68", "type": "join", "z": "6e170384.60c96c", "name": "", "mode": "custom", "build": "array", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "\\n", "joinerType": "str", "accumulate": false, "timeout": "", "count": "3", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 3030, "y": 3900, "wires": [ [ "f32ccc6a.31503" ] ] }, { "id": "4e1ea3d3.4b031c", "type": "debug", "z": "6e170384.60c96c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 3430, "y": 3900, "wires": [] }, { "id": "171295b.f07116a", "type": "change", "z": "6e170384.60c96c", "name": "to Number", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "$number(payload)\t", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 2870, "y": 3900, "wires": [ [ "b392f58e.316c68" ] ] }, { "id": "f32ccc6a.31503", "type": "change", "z": "6e170384.60c96c", "name": "Erstelle RGB Objekt", "rules": [ { "t": "set", "p": "rgb", "pt": "msg", "to": "{\"Rot\":0,\"Grün\":0,\"Blau\":0}", "tot": "json" }, { "t": "set", "p": "rgb.Rot", "pt": "msg", "to": "payload[0]", "tot": "msg" }, { "t": "set", "p": "rgb.Grün", "pt": "msg", "to": "payload[1]", "tot": "msg" }, { "t": "set", "p": "rgb.Blau", "pt": "msg", "to": "payload[2]", "tot": "msg" }, { "t": "move", "p": "rgb", "pt": "msg", "to": "payload", "tot": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 3220, "y": 3900, "wires": [ [ "4e1ea3d3.4b031c" ] ] } ]
-
Na - ich bin ja immer noch überzeugt, dass das eine oder andere Template oder HowTo vielleicht jemand Arbeit abnimmt, deswegen habe ich auch noch eine Node für die umgekehrte Konvertierung gemacht - also von Dezimalzahlen in einen Bytestring.
Hier erst wieder die Node zum Import:
[ { "id": "ab16e708.7973e8", "type": "subflow", "name": "Decimal to Byte", "info": "# Decimal to Byte\r\nThe node accepts any decimal number as number, string, comma separated string with decimal values, arrays or objects as `msg.payload`. \r\nIf strings can not be converted into numbers the whole string, object, array will be ignored.\r\nFlot numbers will be converted to integers. \r\n\r\nThe output will always be a string, representing each number as a string, representing each byte with 2 characters (i.e. 8 ==> '08').\r\n\r\nPrefixes can be added by consecutive change nodes. Using a hashtag ('#'), follwed by 3 bytes will be detected in the debug window as color code.\r\n\r\n\r\n# Dezimal nach Byte\r\nDie Node akzeptiert jede Dezimalzahl als Zahl, String, durch Kommas getrennte Zahlen als String/Zeichenkette, Array oder Objekt als `msg.payload`.\r\n\r\nWenn ein String nicht in eine Zahl umgewandelt werden kann, wird die gesamte Eingabe ignoriert. Fließkommazahlen werden in Ganzzahlen/Integerwerte umgewandelt. \r\n\r\nDie Ausgabe ist immer ein String/Zeichenkette. Jede Dezimalzahl wird als Zeichenkette ausgegeben, wobei jedes Byte mit 2 Zeichen dargestellt wird (z.Bsp. 8 ==> '08'). \r\n\r\nPräfixe müssen durch nachfolgende Change-Nodes selbst vorangestellt werden. Stellt man einer Bytefolge von 3 Zahlen ein Hashtag ('#') voran, wird dieser im Debug-Fenster bereits als Farbcode interpretiert.", "category": "", "in": [ { "x": 60, "y": 160, "wires": [ { "id": "da75483e.1f9f18" } ] } ], "out": [ { "x": 1300, "y": 80, "wires": [ { "id": "1a81a4c8.b8095b", "port": 0 }, { "id": "4b071cab.37d0c4", "port": 0 }, { "id": "65fca19a.41ef9", "port": 0 } ] } ], "env": [], "color": "#E2D96E", "icon": "node-red/hash.svg" }, { "id": "1a81a4c8.b8095b", "type": "function", "z": "ab16e708.7973e8", "name": "to HEX String Byte Format", "func": "if (typeof(msg.payload) === \"string\"){\n msg.payload = Number(msg.payload);\n if (isNaN(msg.payload) ) return null;\n}\nmsg.payload=Math.floor(msg.payload);\nmsg.payload= (msg.payload.toString(16)).toUpperCase();\nif ((msg.payload).length%2 > 0) msg.payload = '0' + msg.payload;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 520, "y": 80, "wires": [ [] ] }, { "id": "da75483e.1f9f18", "type": "switch", "z": "ab16e708.7973e8", "name": "", "property": "payload", "propertyType": "msg", "rules": [ { "t": "istype", "v": "number", "vt": "number" }, { "t": "istype", "v": "string", "vt": "string" }, { "t": "istype", "v": "array", "vt": "array" }, { "t": "istype", "v": "object", "vt": "object" } ], "checkall": "true", "repair": false, "outputs": 4, "x": 190, "y": 160, "wires": [ [ "1a81a4c8.b8095b" ], [ "4349febf.96d86" ], [ "fabf9af5.c72b38" ], [ "fabf9af5.c72b38" ] ] }, { "id": "4349febf.96d86", "type": "split", "z": "ab16e708.7973e8", "name": "", "splt": ",", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 380, "y": 140, "wires": [ [ "370c9cd2.a93664" ] ] }, { "id": "370c9cd2.a93664", "type": "function", "z": "ab16e708.7973e8", "name": "to HEX String Byte Format", "func": "if (typeof(msg.payload) === \"string\"){\n msg.payload = Number(msg.payload);\n if (isNaN(msg.payload) ) return null;\n}\nmsg.payload=Math.floor(msg.payload);\nmsg.payload= (msg.payload.toString(16)).toUpperCase();\nif ((msg.payload).length%2 > 0) msg.payload = '0' + msg.payload;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 600, "y": 140, "wires": [ [ "c3312bd6.16ea18" ] ] }, { "id": "c3312bd6.16ea18", "type": "join", "z": "ab16e708.7973e8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 810, "y": 140, "wires": [ [ "4b071cab.37d0c4" ] ] }, { "id": "fabf9af5.c72b38", "type": "split", "z": "ab16e708.7973e8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 380, "y": 180, "wires": [ [ "2c13cf5c.73981" ] ] }, { "id": "2c13cf5c.73981", "type": "function", "z": "ab16e708.7973e8", "name": "to HEX String Byte Format", "func": "if (typeof(msg.payload) === \"string\"){\n msg.payload = Number(msg.payload);\n if (isNaN(msg.payload) ) return null;\n}\nmsg.payload=Math.floor(msg.payload);\nmsg.payload= (msg.payload.toString(16)).toUpperCase();\nif ((msg.payload).length%2 > 0) msg.payload = '0' + msg.payload;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 600, "y": 180, "wires": [ [ "63d1eccf.a09034" ] ] }, { "id": "63d1eccf.a09034", "type": "join", "z": "ab16e708.7973e8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "num", "reduceFixup": "", "x": 810, "y": 180, "wires": [ [ "19ca6af6.1e37c5" ] ] }, { "id": "4b071cab.37d0c4", "type": "change", "z": "ab16e708.7973e8", "name": "", "rules": [ { "t": "change", "p": "payload", "pt": "msg", "from": ",", "fromt": "str", "to": "", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1000, "y": 140, "wires": [ [] ] }, { "id": "19ca6af6.1e37c5", "type": "split", "z": "ab16e708.7973e8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 960, "y": 180, "wires": [ [ "65fca19a.41ef9" ] ] }, { "id": "65fca19a.41ef9", "type": "join", "z": "ab16e708.7973e8", "name": "", "mode": "custom", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 1110, "y": 180, "wires": [ [] ] }, { "id": "c6f7c6fb.b053c8", "type": "subflow:ab16e708.7973e8", "z": "6e170384.60c96c", "name": "", "x": 2950, "y": 4420, "wires": [ [] ] } ]
Auch hier wieder die Beschreibung in der Standardhilfe:
Hier wieder die getesteten Beispiele als Ausgabe:
Fügt man eine Hashtag als Präfix hinzu - wird dieser im Debugfenster bei einem RGB Object gleich als Farbe interpretiert.
Zum Schluss nochmal alles zum selbst Ausprobieren:
[ { "id": "ab16e708.7973e8", "type": "subflow", "name": "Decimal to Byte", "info": "# Decimal to Byte\r\nThe node accepts any decimal number as number, string, comma separated string with decimal values, arrays or objects as `msg.payload`. \r\nIf strings can not be converted into numbers the whole string, object, array will be ignored.\r\nFlot numbers will be converted to integers. \r\n\r\nThe output will always be a string, representing each number as a string, representing each byte with 2 characters (i.e. 8 ==> '08').\r\n\r\nPrefixes can be added by consecutive change nodes. Using a hashtag ('#'), follwed by 3 bytes will be detected in the debug window as color code.\r\n\r\n\r\n# Dezimal nach Byte\r\nDie Node akzeptiert jede Dezimalzahl als Zahl, String, durch Kommas getrennte Zahlen als String/Zeichenkette, Array oder Objekt als `msg.payload`.\r\n\r\nWenn ein String nicht in eine Zahl umgewandelt werden kann, wird die gesamte Eingabe ignoriert. Fließkommazahlen werden in Ganzzahlen/Integerwerte umgewandelt. \r\n\r\nDie Ausgabe ist immer ein String/Zeichenkette. Jede Dezimalzahl wird als Zeichenkette ausgegeben, wobei jedes Byte mit 2 Zeichen dargestellt wird (z.Bsp. 8 ==> '08'). \r\n\r\nPräfixe müssen durch nachfolgende Change-Nodes selbst vorangestellt werden. Stellt man einer Bytefolge von 3 Zahlen ein Hashtag ('#') voran, wird dieser im Debug-Fenster bereits als Farbcode interpretiert.", "category": "", "in": [ { "x": 60, "y": 160, "wires": [ { "id": "da75483e.1f9f18" } ] } ], "out": [ { "x": 1300, "y": 80, "wires": [ { "id": "1a81a4c8.b8095b", "port": 0 }, { "id": "4b071cab.37d0c4", "port": 0 }, { "id": "65fca19a.41ef9", "port": 0 } ] } ], "env": [], "color": "#E2D96E", "icon": "node-red/hash.svg" }, { "id": "1a81a4c8.b8095b", "type": "function", "z": "ab16e708.7973e8", "name": "to HEX String Byte Format", "func": "if (typeof(msg.payload) === \"string\"){\n msg.payload = Number(msg.payload);\n if (isNaN(msg.payload) ) return null;\n}\nmsg.payload=Math.floor(msg.payload);\nmsg.payload= (msg.payload.toString(16)).toUpperCase();\nif ((msg.payload).length%2 > 0) msg.payload = '0' + msg.payload;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 520, "y": 80, "wires": [ [] ] }, { "id": "da75483e.1f9f18", "type": "switch", "z": "ab16e708.7973e8", "name": "", "property": "payload", "propertyType": "msg", "rules": [ { "t": "istype", "v": "number", "vt": "number" }, { "t": "istype", "v": "string", "vt": "string" }, { "t": "istype", "v": "array", "vt": "array" }, { "t": "istype", "v": "object", "vt": "object" } ], "checkall": "true", "repair": false, "outputs": 4, "x": 190, "y": 160, "wires": [ [ "1a81a4c8.b8095b" ], [ "4349febf.96d86" ], [ "fabf9af5.c72b38" ], [ "fabf9af5.c72b38" ] ] }, { "id": "4349febf.96d86", "type": "split", "z": "ab16e708.7973e8", "name": "", "splt": ",", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 380, "y": 140, "wires": [ [ "370c9cd2.a93664" ] ] }, { "id": "370c9cd2.a93664", "type": "function", "z": "ab16e708.7973e8", "name": "to HEX String Byte Format", "func": "if (typeof(msg.payload) === \"string\"){\n msg.payload = Number(msg.payload);\n if (isNaN(msg.payload) ) return null;\n}\nmsg.payload=Math.floor(msg.payload);\nmsg.payload= (msg.payload.toString(16)).toUpperCase();\nif ((msg.payload).length%2 > 0) msg.payload = '0' + msg.payload;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 600, "y": 140, "wires": [ [ "c3312bd6.16ea18" ] ] }, { "id": "c3312bd6.16ea18", "type": "join", "z": "ab16e708.7973e8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 810, "y": 140, "wires": [ [ "4b071cab.37d0c4" ] ] }, { "id": "fabf9af5.c72b38", "type": "split", "z": "ab16e708.7973e8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 380, "y": 180, "wires": [ [ "2c13cf5c.73981" ] ] }, { "id": "2c13cf5c.73981", "type": "function", "z": "ab16e708.7973e8", "name": "to HEX String Byte Format", "func": "if (typeof(msg.payload) === \"string\"){\n msg.payload = Number(msg.payload);\n if (isNaN(msg.payload) ) return null;\n}\nmsg.payload=Math.floor(msg.payload);\nmsg.payload= (msg.payload.toString(16)).toUpperCase();\nif ((msg.payload).length%2 > 0) msg.payload = '0' + msg.payload;\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 600, "y": 180, "wires": [ [ "63d1eccf.a09034" ] ] }, { "id": "63d1eccf.a09034", "type": "join", "z": "ab16e708.7973e8", "name": "", "mode": "auto", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "num", "reduceFixup": "", "x": 810, "y": 180, "wires": [ [ "19ca6af6.1e37c5" ] ] }, { "id": "4b071cab.37d0c4", "type": "change", "z": "ab16e708.7973e8", "name": "", "rules": [ { "t": "change", "p": "payload", "pt": "msg", "from": ",", "fromt": "str", "to": "", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 1000, "y": 140, "wires": [ [] ] }, { "id": "19ca6af6.1e37c5", "type": "split", "z": "ab16e708.7973e8", "name": "", "splt": "\\n", "spltType": "str", "arraySplt": 1, "arraySpltType": "len", "stream": false, "addname": "", "x": 960, "y": 180, "wires": [ [ "65fca19a.41ef9" ] ] }, { "id": "65fca19a.41ef9", "type": "join", "z": "ab16e708.7973e8", "name": "", "mode": "custom", "build": "string", "property": "payload", "propertyType": "msg", "key": "topic", "joiner": "", "joinerType": "str", "accumulate": false, "timeout": "", "count": "", "reduceRight": false, "reduceExp": "", "reduceInit": "", "reduceInitType": "", "reduceFixup": "", "x": 1110, "y": 180, "wires": [ [] ] }, { "id": "2191832.9e0d37c", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "1040403", "payloadType": "num", "x": 2120, "y": 3600, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "9b87093.1e4b4f8", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "1040403", "payloadType": "str", "x": 2120, "y": 3640, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "6862064f.d059e8", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "104,04,03", "payloadType": "str", "x": 2120, "y": 3680, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "4470c439.42ae6c", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "255,0,255", "payloadType": "str", "x": 2120, "y": 3760, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "a612a150.79fa", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "Hallo", "payloadType": "str", "x": 2130, "y": 3560, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "a807801e.86536", "type": "inject", "z": "6e170384.60c96c", "name": "[2,6,99]", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[2,6,99]", "payloadType": "jsonata", "x": 2130, "y": 3800, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "3ee98195.e48d4e", "type": "inject", "z": "6e170384.60c96c", "name": "['ab','cd',99]", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "['ab','cd',99]", "payloadType": "jsonata", "x": 2110, "y": 3840, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "69d5b78b.9a1348", "type": "inject", "z": "6e170384.60c96c", "name": "[99]", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[99]", "payloadType": "jsonata", "x": 2130, "y": 3880, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "620be0a5.46383", "type": "inject", "z": "6e170384.60c96c", "name": "[99,'255']", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[99,'255']", "payloadType": "jsonata", "x": 2120, "y": 3920, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "81373293.b970d", "type": "inject", "z": "6e170384.60c96c", "name": "[99,'ef']", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "[99,'ef']", "payloadType": "jsonata", "x": 2130, "y": 3960, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "a41dba5d.037848", "type": "inject", "z": "6e170384.60c96c", "name": "{\"Rot\":255,\"Grün\":255,\"Blau\":0}", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "{\"Rot\":255,\"Grün\":0,\"Blau\":255}", "payloadType": "json", "x": 2050, "y": 4000, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "a2229b55.07ef38", "type": "inject", "z": "6e170384.60c96c", "name": "{\"Rot\":255,\"Grün\":\"128\",\"Blau\":0}", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "{\"Rot\":255,\"Grün\":\"128\",\"Blau\":0}", "payloadType": "json", "x": 2050, "y": 4040, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "8455c0a1.f7aab", "type": "inject", "z": "6e170384.60c96c", "name": "{\"Rot\":255,\"Grün\":\"gh\",\"Blau\":0}", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "{\"Rot\":255,\"Grün\":\"gh\",\"Blau\":0}", "payloadType": "json", "x": 2050, "y": 4080, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "bdc50d1b.f93bd", "type": "inject", "z": "6e170384.60c96c", "name": "\"11806311026742\"", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "11806311026742", "payloadType": "str", "x": 2090, "y": 3720, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "aa69cddf.3210e", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "15.6", "payloadType": "str", "x": 2130, "y": 3520, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "f5cea9b4.72e1a8", "type": "inject", "z": "6e170384.60c96c", "name": "", "props": [ { "p": "payload" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "15.6", "payloadType": "num", "x": 2130, "y": 3480, "wires": [ [ "333333a7.cfa17c" ] ] }, { "id": "333333a7.cfa17c", "type": "subflow:ab16e708.7973e8", "z": "6e170384.60c96c", "name": "", "env": [], "x": 2600, "y": 3840, "wires": [ [ "5fb9015.fbd98", "7af82e5f.719f4", "f4d59886.753238" ] ] }, { "id": "7af82e5f.719f4", "type": "change", "z": "6e170384.60c96c", "name": "Präfix 0x", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "'0x' & payload", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 2790, "y": 3880, "wires": [ [ "5fb9015.fbd98" ] ] }, { "id": "f4d59886.753238", "type": "change", "z": "6e170384.60c96c", "name": "Präfix #", "rules": [ { "t": "set", "p": "payload", "pt": "msg", "to": "'#' & payload", "tot": "jsonata" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 2800, "y": 3920, "wires": [ [ "5fb9015.fbd98" ] ] }, { "id": "5fb9015.fbd98", "type": "debug", "z": "6e170384.60c96c", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "statusVal": "", "statusType": "auto", "x": 2990, "y": 3840, "wires": [] } ]
-
@mickym Klasse Arbeit und Danke fürs zur Verfügung stellen.
Auch sehr nützlich in Verbindung mit der Alexa Node. -
@frankyboy73 sagte in Konvertierung Byte nach Dezimal und umgekehrt:
@mickym Klasse Arbeit und Danke fürs zur Verfügung stellen.
Auch sehr nützlich in Verbindung mit der Alexa Node.Danke schön für das Feedback. Da fühlt man dann doch, dass es nicht ganz umsonst ist. Man merkt halt das die NR Fans innerhalb der iobroker Gemeinde doch eine arge Minderheit darstellen.
Momentan integriere ich gerade die Flot Charts in das NR Dashboard - das kann ich ja auch mal veröffentlichen, weil ich denke durch die Datenbankanbindung ist man da doch wesentlich flexibler, als mit den NR eigenen Charts. Zu dem muss man hier ja dann ebenfalls noch die Daten extrahieren, was im Falle der Flot Diagramme ja der iobroker für uns macht.
-
@mickym Hi, ja hier ist nicht viel Los im Node Red Bereich, auch ist das Thema Node Red im Deutschsprachigen Bereich sehr eingeschränk. Da musste ich sonst immer Hilfe im Englischsprachigen Bereich suchen, geht auch und man verbessert noch seine Englisch Kentnisse. Aber es fällt mir auf Deutsch doch einfacher über Probleme zu kommunizieren.
Deshalb bin ich auch froh das du hier so aktiv bist.
Für die Flot Charts hatte ich mich auch interessiert, aber dann wieder verworfen, da ich nur das Node Red Dash Board nutze. Ich hatte zwar auch mal Visu am laufen, bin dann aber umgestiegen, da mir das Ausehen nicht so wichtig ist und ich eher funktionalität brauche.
Ich bin eigentlich mal nur auf Node Red umgestiegen weil es viel Resourcenschonender ist (Arbeitsspeicher) Früher hatte ich Blockly, Visu, Telegramm, TexttoSpeech, usw. Da war mein PI 3 voll an der Grenze. Danach alles in Node Red vereint und der halbe Speicher war wieder frei. Mitlerweile finde ich Node Red auch so toll das ich nie wieder zurück wechseln würde. Trotz mitlerweile Pi 4 -
@frankyboy73 sagte in Konvertierung Byte nach Dezimal und umgekehrt:
@mickym ...
Für die Flot Charts hatte ich mich auch interessiert, aber dann wieder verworfen, da ich nur das Node Red Dash Board nutze. Ich hatte zwar auch mal Visu am laufen, bin dann aber umgestiegen, da mir das Ausehen nicht so wichtig ist und ich eher funktionalität brauche.Nun dann dürfte Dich das interessieren, da ich nun einigermaßen geschafft habe, die Flot Charts gut in das Node Red Dashboard einzubetten.
Fehlen noch ein paar Kleinigkeiten - dann mache ich einen neuen Thread hierfür auf.
-
@mickym Sieht gut aus. Wie kriegst du denn diese Darstellung des Charts hin? Bei mir hab ich da nur eine Linie. Oder kommt das vom Flot?
Dann werde ich mich mal vorab schon mit dem Flot Adapter beschäftigen.Edit: Was mich auch noch interessieren würde, wie logst du deine Daten? (Leistung, Temperatur) Nutzt du dafür nen History Adapter oder schreibst du sie über Node Red in Files?
-
@frankyboy73 Na das war bis jetzt eben meine Schwachstelle. Bislang habe ich das gar nicht genutzt und die Daten selbst abzuspeichern, fand ich viel zu mühsam und das ist ja meines Erachtens auch die große Stärke des iobrokers, dass man das alles automatisiert hat mit dem "Schraubenschlüssel".
Ich nutze den SQL Adapter und habe mysql installiert. Ich habe mich mit influxDB nicht beschäftigt, aber mysql bietet halt - weil es das wohl schon so lange gibt - die Möglichkeit sowohl über AddIns - Daten direkt ohne Import von Dateien in Excel zu importieren:
Und unter Windows hast Du mit HeidiSQL auch ein vernünftiges FrontEnd, um die Daten direkt zu manipulieren ohne dass Du zum SQL Experten werden musst.
Ausserdem habe ich es auch schon geschafft - Daten aus Node Red direkt in die Datenbank zu schreiben. Das werde ich mir wohl mal für eigene Logs zu Nutze machen - aber dahin ist noch ein weiter Weg - aber Du siehst man hat immer neue Ideen.
-
@mickym sagte in Konvertierung Byte nach Dezimal und umgekehrt:
@frankyboy73 sagte in Konvertierung Byte nach Dezimal und umgekehrt:
@mickym Klasse Arbeit und Danke fürs zur Verfügung stellen.
Danke schön für das Feedback. Da fühlt man dann doch, dass es nicht ganz umsonst ist. Man merkt halt das die NR Fans innerhalb der iobroker Gemeinde doch eine arge Minderheit darstellen.
Moin, ich zähle mich auch zur "argen Minderheit" der NR Fans
und finde das Node Red hier viel zu wenig Beachtung geschenkt wird.
Da steckt unheimlich viel Potential drin...sieht man ja schon an der ständig wachsenden Zahl an Nodes.Ich komme auch mit NR besser zurecht, als mit Blockly...ist einfach intuitiver
Super Arbeit übrigens und mach weiter so