Keyboard Shortcuts
Likes
Search
Re: Parsing a string
¿ªÔÆÌåÓýMick has an extra msg.out. Only need 0 ¨C 7. ? Here¡¯s a flow using split/switch/function to give false (0) or true (1) for each bit. First bit is top function node and last bit is bottom. Then feed into GPIO node. ? Dave wo2x ? [ ??? { ??????? "id": "4e7a77e9.defc48", ??????? "type": "tab", ??????? "label": "Flow 2", ??????? "disabled": false, ??????? "info": "" ??? }, ??? { ??????? "id": "cd5a6a57.fb77d8", ??????? "type": "inject", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "props": [ ??????????? { ??????????????? "p": "payload" ??????????? } ??????? ], ??????? "repeat": "", ??????? "crontab": "", ??????? "once": false, ??????? "onceDelay": 0.1, ??????? "topic": "", ??????? "payload": "01010101", ??????? "payloadType": "str", ??????? "x": 300, ??????? "y": 220, ??????? "wires": [ ??????????? [ ??????????????? "fe4dc4d6.037c98" ??????????? ] ??????? ] ??? }, ??? { ??????? "id": "dd5611e4.15976", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 160, ??????? "wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "3ed35afa.0a1936", ??????? "type": "switch", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "property": "parts.index", ??????? "propertyType": "msg", ??????? "rules": [ ??????????? { ??????????????? "t": "eq", ??????????????? "v": "0", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ??????????????? "v": "1", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ??????????????? "v": "2", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ???????? ???????"v": "3", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ??????????????? "v": "4", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ??????????????? "v": "5", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ??????????????? "v": "6", ??????????????? "vt": "num" ??????????? }, ??????????? { ??????????????? "t": "eq", ??????????????? "v": "7", ??????????????? "vt": "num" ??????????? } ??????? ], ??????? "checkall": "true", ??????? "repair": false, ??????? "outputs": 8, ??????? "x": 600, ??????? "y": 280, ??????? "wires": [ ??????????? [ ??????????????? "dd5611e4.15976" ??????????? ], ?????????? ?[ ??????????????? "b656e3bc.3661f" ??????????? ], ??????????? [ ??????????????? "b3ccafd3.6efc2" ??????????? ], ??????????? [ ??????????????? "65512697.166d98" ??????????? ], ??????????? [ ??????????????? "e6171e3d.e5f4d" ??????????? ], ??????????? [ ??????????????? "96d14c2b.9798e" ??????????? ], ??????????? [ ??????????????? "ccbba3c4.d57db" ??????????? ], ??????????? [ ??????????????? "4916a72a.09bbc8" ??????????? ] ??????? ] ??? }, ??? { ??????? "id": "fe4dc4d6.037c98", ??????? "type": "split", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "splt": "1", ??????? "spltType": "len", ??????? "arraySplt": 1, ??????? "arraySpltType": "len", ??????? "stream": false, ??????? "addname": "", ??????? "x": 450, ??????? "y": 220, ???? ???"wires": [ ??????????? [ ??????????????? "3ed35afa.0a1936" ??????????? ] ??????? ] ??? }, ??? { ??????? "id": "b656e3bc.3661f", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 200, ??? ????"wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "b3ccafd3.6efc2", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 240, ??????? "wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "65512697.166d98", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 280, ??????? "wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "e6171e3d.e5f4d", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 320, ??????? "wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "96d14c2b.9798e", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 360, ??????? "wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "ccbba3c4.d57db", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 400, ??? ????"wires": [ ??????????? [] ??????? ] ??? }, ??? { ??????? "id": "4916a72a.09bbc8", ??????? "type": "function", ??????? "z": "4e7a77e9.defc48", ??????? "name": "", ??????? "func": "if (msg.payload == \"1\") {\n??? msg.payload = \"true\";\n} else msg.payload = \"false\";\n\nreturn msg;", ??????? "outputs": 1, ??????? "noerr": 0, ??????? "initialize": "", ??????? "finalize": "", ??????? "x": 760, ??????? "y": 440, ??????? "wires": [ ??????????? [] ??????? ] ??? } ] ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? From: [email protected] <[email protected]> On Behalf Of Mick - W8BE
Sent: Friday, January 29, 2021 3:01 PM To: [email protected] Subject: Re: [nodered-hamradio] Parsing a string ? Here is a function to split the input and output a msg for each bit.? ?I used a string of 10000000 as the inject ? ? The output gives you the msg.payload and msg.topic ? Here is the function. ? var output = msg.payload.split(""); You could then run this into a switch node for further?processing or just modify it by creating a var instead of msg and then process it in the function.? ? On Fri, Jan 29, 2021 at 1:53 PM David De Coons wo2x <RocketNJ@...> wrote:
|