Navigation

    Logo
    • Register
    • Login
    • Search
    • Recent
    • Tags
    • Unread
    • Categories
    • Unreplied
    • Popular
    • GitHub
    • Docu
    • Hilfe
    1. Home
    2. Deutsch
    3. Skripten / Logik
    4. Boolean Verknüpfung

    NEWS

    • Neuer Blog: Fotos und Eindrücke aus Solingen

    • ioBroker@Smart Living Forum Solingen, 14.06. - Agenda added

    • ioBroker goes Matter ... Matter Adapter in Stable

    Boolean Verknüpfung

    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      rewenode last edited by

      Das verstehe ich noch nicht ganz. Heißt das, du hast eine 'Eingangsnachricht" msg.payload="01 00 37 00 00 05 01" als String mit Leerzeichnen getrennt?

      Falls ja, kannst du alles komplett und recht simpel mit einem Funktionsnode machen.

      • String splitten in die einzelnen Werte A…G

      • msg.payload = XOR aller Werte

      Fertig

      Dein gezeichneter XOR als separate node kann so nicht gehen, da du nur einen Eingang hast.

      Die Werte müssten also nacheinander an das node gesendet werden, das node kümmert sich dann jeweils um die Zwischenspeicherung (global/flow context)

      Ich würde in jedem Fall ein Funktion node nehme.

      Fall die Eingangsdaten nicht als einzige Nachricht (wie gezeichnet) sondern als separate Nachrichten eintrudeln, bietet sich alternativ auch das join-node(verkettet die 7 eingehenden Nachrichten zu einer einzelnen Nachricht) gefolgt von einem Funktion node für das XOR an.

      Also du musst erst genau beschreiben, wie die eingehende Nachricht genau aussieht und wo die herkommen soll.

      1 Reply Last reply Reply Quote 0
      • P
        pfuhsy last edited by

        @rewenode:

        Das verstehe ich noch nicht ganz. Heißt das, du hast eine 'Eingangsnachricht" msg.payload="01 00 37 00 00 05 01" als String mit Leerzeichnen getrennt? `

        Ne, die Daten kommen an einem Stück als String an, also "0100370000050131". Die 31 am Ende wird auch mitübertragen. Die angeschlossene Elektronik errechnet die 31 und sendet sie mit. Ich will Sie mit dem Node Red überprüfen.

        @rewenode:

        Dein gezeichneter XOR als separate node kann so nicht gehen, da du nur einen Eingang hast. `
        Ja, richtig. Da war was. Ich dachte mir, dass ich die Daten an der blau markierten Stelle abgreife und mit XOR verknüpfe. An dieser Stelle hab ich die Daten bereits in 2er Strings getrennt. Wenn es nicht anders geht dann eben an der rot markierten Stelle. Dort müssen sie eben nochmal getrennt und mit XOR verknüpft werden.

        Kannst Du mir da ein Tritt in die richtige Richtung geben, wie so ein Script aussehen würde ?
        6863_unbenannt.jpg

        1 Reply Last reply Reply Quote 0
        • R
          rewenode last edited by

          > Ich dachte mir, dass ich die Daten an der blau markierten Stelle abgreife und mit XOR verknüpfe

          Mach doch mal einen Export von deiner bisherigen Lösung. Bin mir immer noch nicht sicher was da geXORt werden muss. Wenn wirklich so sein soll:

          (Achtung Pseudocode)

          if (01 xor 00 xor 37 xor 00 xor 00 xor 05 xor 01) == 31

          01 an Ausgang 1

          …

          01 an Ausgang 7

          sonst

          error an Ausgang 8

          endif

          Da sollte ein Funktionsnode mit 8 Ausgängen seichen. Das kommt dann in das rote Kringel. Die "String kürzen"-nodes fallen dann weg.

          Vor die obige obigen Abfrage muss dann natürlich das Splitten in die einzelnen Zahlen erfolgen

          1 Reply Last reply Reply Quote 0
          • R
            rewenode last edited by

            Vlt. wird es mit einem Flow klarer wie ich das meine.

            ! ````
            [
            {
            "id": "88369d90.4822e8",
            "type": "inject",
            "z": "75b1b7ef.e930c",
            "name": "",
            "topic": "",
            "payload": "01003f000005013a",
            "payloadType": "str",
            "repeat": "",
            "crontab": "",
            "once": false,
            "onceDelay": 0.1,
            "x": 293.5,
            "y": 146,
            "wires": [
            [
            "584c8bca.751a8c"
            ]
            ]
            },
            {
            "id": "417f228a.a35d0c",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 1",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 40,
            "wires": []
            },
            {
            "id": "584c8bca.751a8c",
            "type": "function",
            "z": "75b1b7ef.e930c",
            "name": "split Input and xor",
            "func": "//weis grad nicht, wie ich die regex formulieren muss, \n//damit keine arrayelemente mit '' erzeugt werden\n//deswegen werden sie mit .filter wieder entfernt\n\n// zahlen, länge 2\nlet re = /(\d{2})/;\n\n//splitte in Array und lösche zellen mit ""\nlet aI = msg.payload.split(re).filter(value => value !== "");\n\n//convertiere Hex Strings to Integer\naI = aI.map(x => parseInt(x,16));\n\n//xor vom inputArray\nlet mustXor = aI[aI.length-1];\n\n//xor aus inputArry entfernen\naI.splice(-1, 1);\n\n//xor aus inputaary bilden\nvar ifXor = aI.reduce((v, vnext) => v ^ vnext);\n\nmsg.ifXor = ifXor;\nmsg.mustXor = mustXor;\nmsg.payload = aI;\n\nif (ifXor == mustXor) { //no error\n let msg1 = {payload: aI[0]}; \n let msg2 = {payload: aI[1]}; \n let msg3 = {payload: aI[2]}; \n let msg4 = {payload: aI[3]}; \n let msg5 = {payload: aI[4]}; \n let msg6 = {payload: aI[5]}; \n let msg7 = {payload: aI[6]}; \n let msg8 = {payload: 'no error'}; \n node.status({fill:"green",shape:"dot",text:'no error'})\n node.send([msg1,msg2,msg3,msg4,msg5,msg6,msg7,msg8]);\n\n \n} else { //xor error\n \n node.status({fill:"red",shape:"dot",text:'XOR error'})\n node.send([null,null,null,null,null,null,null,{payload: 'XOR error'}]);\n}\n\n",
            "outputs": 8,
            "noerr": 0,
            "x": 533.5,
            "y": 147,
            "wires": [
            [
            "417f228a.a35d0c"
            ],
            [
            "ecf7bdee.b46b2"
            ],
            [
            "341f2479.61e85c"
            ],
            [
            "b9de5124.c6a1d8"
            ],
            [
            "752bb597.8ca724"
            ],
            [
            "d01c5901.ee03a"
            ],
            [
            "7d99ca62.8085f4"
            ],
            [
            "43ff8a94.7813c4"
            ]
            ],
            "inputLabels": [
            "input str"
            ],
            "outputLabels": [
            "object 1",
            "object 2",
            "object 3",
            "object 4",
            "object 5",
            "object 6",
            "object 6",
            "erros occurs"
            ]
            },
            {
            "id": "ecf7bdee.b46b2",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 2",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 100,
            "wires": []
            },
            {
            "id": "341f2479.61e85c",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 3",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 160,
            "wires": []
            },
            {
            "id": "b9de5124.c6a1d8",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 4",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 220,
            "wires": []
            },
            {
            "id": "752bb597.8ca724",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 5",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 280,
            "wires": []
            },
            {
            "id": "d01c5901.ee03a",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 6",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 340,
            "wires": []
            },
            {
            "id": "7d99ca62.8085f4",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "object 7",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 400,
            "wires": []
            },
            {
            "id": "43ff8a94.7813c4",
            "type": "debug",
            "z": "75b1b7ef.e930c",
            "name": "XOR error",
            "active": true,
            "tosidebar": true,
            "console": false,
            "tostatus": true,
            "complete": "payload",
            "x": 800,
            "y": 480,
            "wires": []
            }
            ]

            
             ![3999_voila_capture_2018-08-30_02-53-05_pm.png](/assets/uploads/files/3999_voila_capture_2018-08-30_02-53-05_pm.png) 
            1 Reply Last reply Reply Quote 0
            • P
              pfuhsy last edited by

              @rewenode:

              > Ich dachte mir, dass ich die Daten an der blau markierten Stelle abgreife und mit XOR verknüpfe
              Mach doch mal einen Export von deiner bisherigen Lösung. Bin mir immer noch nicht sicher was da geXORt werden muss. `

              Meine bisherige Lösung. Wie gesagt, teilt Sie bis jetzt nur die ankommenden Daten.

              ! [
              ! {
              ! "id": "2da69b37.1df24c",
              ! "type": "tab",
              ! "label": "HAA Empfangen",
              ! "disabled": false,
              ! "info": "Empfangene Daten werden hier auf den jeweiligen\nBytes gekürzt und maskiert."
              ! },
              ! {
              ! "id": "fc292ded.300e98",
              ! "type": "debug",
              ! "z": "2da69b37.1df24c",
              ! "name": "Input ungekürzt",
              ! "active": true,
              ! "tosidebar": true,
              ! "console": false,
              ! "tostatus": false,
              ! "complete": "true",
              ! "x": 400,
              ! "y": 200,
              ! "wires": []
              ! },
              ! {
              ! "id": "46b4f56f.ea0dc4",
              ! "type": "serial in",
              ! "z": "2da69b37.1df24c",
              ! "name": "Statusempfang",
              ! "serial": "da7b24a1.565828",
              ! "x": 120,
              ! "y": 280,
              ! "wires": [
              ! [
              ! "fc292ded.300e98",
              ! "65ee1056.98349",
              ! "92d59a98.232b7",
              ! "c2cb0851.237438",
              ! "1d1f4b9a.95161c",
              ! "ea03f2c9.a0e1a"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "65ee1056.98349",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "String kürzen (0. / 1. Stelle) / BAS",
              ! "func": "var string = msg.payload; //ankommende payload speichern\n\n//String kürzen\nvar string_teil = string.substring(0,2);\n\nreturn [{payload: string_teil}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 440,
              ! "y": 280,
              ! "wires": [
              ! [
              ! "381721c3.e06106"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "92d59a98.232b7",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "String kürzen (2. / 3. Stelle) / SIR",
              ! "func": "var string = msg.payload; //ankommende payload speichern\n\n//String kürzen\nvar string_teil = string.substring(2,4);\n\nreturn [{payload: string_teil}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 440,
              ! "y": 480,
              ! "wires": [
              ! [
              ! "78bdb8a6.e688a"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "c2cb0851.237438",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "String kürzen (4. / 5. Stelle) / REE",
              ! "func": "var string = msg.payload; //ankommende payload speichern\n\n//String kürzen\nvar string_teil = string.substring(4,6);\n\nreturn [{payload: string_teil}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 460,
              ! "y": 680,
              ! "wires": [
              ! [
              ! "dec6c73.c1cf638"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "8a72b235.d47318",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "String kürzen (10. / 11. / 12. / 13. Stelle) / SW",
              ! "func": "var string = msg.payload; //ankommende payload speichern\n\n//String kürzen\nvar string = string.substring(10,14);\n\nreturn [{payload: string}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 500,
              ! "y": 900,
              ! "wires": [
              ! [
              ! "22af2a70.c8faee"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "381721c3.e06106",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "BAS (Byte0) Splitten - Basis",
              ! "func": "var bas_int = parseInt(msg.payload, 16); //ankommende Hex-Nachricht (Basis 16) in Integer wandeln\n\nvar kal = false;\nif((bas_int & 1) == "1") //Maskierung und gleichzeitig in Boolean ändern\n{\n kal = true;\n}\n\nvar val = false;\nif((bas_int & 2) == "2") //Maskierung und gleichzeitig in Boolean ändern\n{\n val = true;\n}\n\nvar alm = false;\nif((bas_int & 4) == "4") //Maskierung und gleichzeitig in Boolean ändern\n{\n alm = true;\n}\nvar als = false;\nif((bas_int & 😎 == "8") //Maskierung und gleichzeitig in Boolean ändern\n{\n als = true;\n}\n\nvar alf = false;\nif((bas_int & 16) == "16") //Maskierung und gleichzeitig in Boolean ändern\n{\n alf = true;\n}\nvar sab = false;\nif((bas_int & 32) == "32") //Maskierung und gleichzeitig in Boolean ändern\n{\n sab = true;\n}\n\nreturn [{payload: kal}, {payload: val},{payload: alm}, {payload: als},{payload: alf}, {payload: sab}];",
              ! "outputs": 6,
              ! "noerr": 0,
              ! "x": 920,
              ! "y": 280,
              ! "wires": [
              ! [
              ! "6d2f24fd.83778c"
              ! ],
              ! [
              ! "f57b8515.a2eb38"
              ! ],
              ! [
              ! "881e87f5.694ca"
              ! ],
              ! [
              ! "e928711b.a11db"
              ! ],
              ! [
              ! "a0fe88a7.655cf8"
              ! ],
              ! [
              ! "203ddcf0.ae3e1c"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "881e87f5.694ca",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Alarm",
              ! "topic": "node-red.0.HAA.Basis.Alarm",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1230,
              ! "y": 240,
              ! "wires": []
              ! },
              ! {
              ! "id": "6d2f24fd.83778c",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Kontaktalarm",
              ! "topic": "node-red.0.HAA.Basis.Kontaktalarm",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1250,
              ! "y": 120,
              ! "wires": []
              ! },
              ! {
              ! "id": "e928711b.a11db",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Start",
              ! "topic": "node-red.0.HAA.Basis.Start",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1230,
              ! "y": 300,
              ! "wires": []
              ! },
              ! {
              ! "id": "f57b8515.a2eb38",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Voralarm",
              ! "topic": "node-red.0.HAA.Basis.Voralarm",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1240,
              ! "y": 180,
              ! "wires": []
              ! },
              ! {
              ! "id": "a0fe88a7.655cf8",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Scharf",
              ! "topic": "node-red.0.HAA.Basis.Scharf",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1230,
              ! "y": 360,
              ! "wires": []
              ! },
              ! {
              ! "id": "203ddcf0.ae3e1c",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Sabotagekontakt",
              ! "topic": "node-red.0.HAA.Basis.Sabotagealarm",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1270,
              ! "y": 420,
              ! "wires": []
              ! },
              ! {
              ! "id": "78bdb8a6.e688a",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "SIR (Byte1) Splitten - Sirene",
              ! "func": "var sir_int = parseInt(msg.payload, 16); //ankommende Hex-Nachricht (Basis 16) in Integer wandeln\n\nvar sto = false;\nif((sir_int & 1) == "1") //Maskierung und gleichzeitig in Boolean ändern\n{\n sto = true;\n}\n\nreturn [{payload: sto}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 920,
              ! "y": 480,
              ! "wires": [
              ! [
              ! "e9e1c426.6757f8"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "e9e1c426.6757f8",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Störung",
              ! "topic": "node-red.0.HAA.Sirene.Störung",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1240,
              ! "y": 480,
              ! "wires": []
              ! },
              ! {
              ! "id": "dec6c73.c1cf638",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "REE (Byte2) Splitten - Reedkontakte",
              ! "func": "var ree_int = parseInt(msg.payload, 16); //ankommende Hex-Nachricht (Basis 16) in Integer wandeln\n\nvar ree0 = false;\nif((ree_int & 1) == "1") //Maskierung und gleichzeitig in Boolean ändern\n{\n ree0 = true;\n}\n\nvar ree1 = false;\nif((ree_int & 2) == "2") //Maskierung und gleichzeitig in Boolean ändern\n{\n ree1 = true;\n}\n\nvar ree2 = false;\nif((ree_int & 4) == "4") //Maskierung und gleichzeitig in Boolean ändern\n{\n ree2 = true;\n}\n\nvar ree3 = false;\nif((ree_int & 😎 == "8") //Maskierung und gleichzeitig in Boolean ändern\n{\n ree3 = true;\n}\n\nvar ree4 = false;\nif((ree_int & 16) == "16") //Maskierung und gleichzeitig in Boolean ändern\n{\n ree4 = true;\n}\n\nvar ree5 = false;\nif((ree_int & 32) == "32") //Maskierung und gleichzeitig in Boolean ändern\n{\n ree5 = true;\n}\n\nreturn [{payload: ree0}, {payload: ree1},{payload: ree2}, {payload: ree3},{payload: ree4}, {payload: ree5}];",
              ! "outputs": 6,
              ! "noerr": 0,
              ! "x": 950,
              ! "y": 680,
              ! "wires": [
              ! [
              ! "e6d3475a.15eed8"
              ! ],
              ! [
              ! "8f916e73.1d74b"
              ! ],
              ! [
              ! "de1a6728.a2b8"
              ! ],
              ! [
              ! "83b12b42.bbcc18"
              ! ],
              ! [
              ! "197e4e9a.388119"
              ! ],
              ! [
              ! "389d88ee.224938"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "e6d3475a.15eed8",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Eingangstür",
              ! "topic": "node-red.0.HAA.Reed.Eingangstür",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1250,
              ! "y": 540,
              ! "wires": []
              ! },
              ! {
              ! "id": "8f916e73.1d74b",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Eingangsfenster",
              ! "topic": "node-red.0.HAA.Reed.Eingangsfenster",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1260,
              ! "y": 600,
              ! "wires": []
              ! },
              ! {
              ! "id": "de1a6728.a2b8",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Garage",
              ! "topic": "node-red.0.HAA.Reed.Garage",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1240,
              ! "y": 660,
              ! "wires": []
              ! },
              ! {
              ! "id": "83b12b42.bbcc18",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Wohnzimmer",
              ! "topic": "node-red.0.HAA.Reed.Wohnzimmer",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1250,
              ! "y": 720,
              ! "wires": []
              ! },
              ! {
              ! "id": "197e4e9a.388119",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Esszimmer",
              ! "topic": "node-red.0.HAA.Reed.Esszimmer",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1250,
              ! "y": 780,
              ! "wires": []
              ! },
              ! {
              ! "id": "389d88ee.224938",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Keller",
              ! "topic": "node-red.0.HAA.Reed.Keller",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1230,
              ! "y": 840,
              ! "wires": []
              ! },
              ! {
              ! "id": "22af2a70.c8faee",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "SW (Byte5/6) Splitten - Software",
              ! "func": "var string = msg.payload; //ankommende payload speichern\n//vom string kürzen\nvar string_teil1 = string.substring(0,2);\nvar swh_hex = parseInt(string_teil1, 16); //ankommende Hex-Nachricht (Basis 16) in Integer wandeln\nvar string_teil2 = string.substring(2,4);\nvar swn_hex = parseInt(string_teil2, 16); //ankommende Hex-Nachricht (Basis 16) in Integer wandeln\n\n//–--------SWH--------------\nvar swh = 0;\nif((swh_hex & 1) == "1") //Maskierung und gleichzeitig in eine Zahl wandeln\n{\n swh += 1;\n}\n\nif((swh_hex & 2) == "2") \n{\n swh += 2;\n}\n\nif((swh_hex & 4) == "4") \n{\n swh += 4;\n}\n\nif((swh_hex & 😎 == "8") \n{\n swh += 8;\n}\n\nif((swh_hex & 16) == "16") \n{\n swh += 16;\n}\n\nif((swh_hex & 32) == "32") \n{\n swh += 32;\n}\n\nif((swh_hex & 64) == "64") \n{\n swh += 64;\n}\n\nif((swh_hex & 128) == "128") //Maskierung und gleichzeitig in Boolean ändern\n{\n swh += 128;\n}\n\n//----------SWN--------------\nvar swn = 0;\nif((swn_hex & 1) == "1") //Maskierung und gleichzeitig in eine Zahl wandeln\n{\n swn += 1;\n}\n\nif((swn_hex & 2) == "2") \n{\n swn += 2;\n}\n\nif((swn_hex & 4) == "4") \n{\n swn += 4;\n}\n\nif((swn_hex & 😎 == "8") \n{\n swn += 8;\n}\n\nif((swn_hex & 16) == "16") \n{\n swh += 16;\n}\n\nif((swn_hex & 32) == "32") \n{\n swn += 32;\n}\n\nif((swn_hex & 64) == "64") \n{\n swn += 64;\n}\n\nif((swn_hex & 128) == "128") //Maskierung und gleichzeitig in Boolean ändern\n{\n swn += 128;\n}\n\n//Hex wieder in String wandeln und zusammensetzten\nvar version = "v";\nversion += swh.toString();\nversion += ".";\nversion += swn.toString();\n\nreturn [{payload: version}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 930,
              ! "y": 900,
              ! "wires": [
              ! [
              ! "5157645f.db9a4c"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "5157645f.db9a4c",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Softwareversion",
              ! "topic": "node-red.0.HAA.Software.Version",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1260,
              ! "y": 900,
              ! "wires": []
              ! },
              ! {
              ! "id": "1d1f4b9a.95161c",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "String kürzen (14. / 15. Stelle) / CHK",
              ! "func": "var string = msg.payload; //ankommende payload speichern\n\n//String kürzen\nvar string_teil = string.substring(14,16);\n\nreturn [{payload: string_teil}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 470,
              ! "y": 960,
              ! "wires": [
              ! [
              ! "4088645b.a1ca94"
              ! ]
              ! ]
              ! },
              ! {
              ! "id": "4088645b.a1ca94",
              ! "type": "ioBroker out",
              ! "z": "2da69b37.1df24c",
              ! "name": "Checksumme HAA",
              ! "topic": "node-red.0.HAA.Chk.HAA",
              ! "ack": "true",
              ! "autoCreate": "true",
              ! "x": 1270,
              ! "y": 960,
              ! "wires": []
              ! },
              ! {
              ! "id": "ea03f2c9.a0e1a",
              ! "type": "function",
              ! "z": "2da69b37.1df24c",
              ! "name": "Test",
              ! "func": "var x = parseInt(5, 16);\nvar y = parseInt(4, 16);\n\nvar test = x ^ y;\n\nreturn [{payload: test}];",
              ! "outputs": 1,
              ! "noerr": 0,
              ! "x": 370,
              ! "y": 140,
              ! "wires": [
              ! []
              ! ]
              ! },
              ! {
              ! "id": "da7b24a1.565828",
              ! "type": "serial-port",
              ! "z": "2da69b37.1df24c",
              ! "serialport": "/dev/ttyAMA0",
              ! "serialbaud": "9600",
              ! "databits": "8",
              ! "parity": "none",
              ! "stopbits": "1",
              ! "newline": "16",
              ! "bin": "false",
              ! "out": "count",
              ! "addchar": true
              ! }
              ! ]

              Der Code sieht schon sehr gut aus was Du da gemacht hast. Ich hab das mal ausprobiert, es scheint zu funktionieren, vielen Dank. Ich muss das jetzt nur noch verstehen, dann bin ich glücklich.

              1 Reply Last reply Reply Quote 0
              • R
                rewenode last edited by

                Mein function-node hat noch Schönheitsfehler. Habe erst zuspät bemerkt, dass der Input Hex-Zahlen sind. Deshalb ist auf die Regular Expression kein Verlass. Außerdem verhält sich die string.split() Methode recht sperrig bei regEx. Mit string.match() gehts deutlich einfacher.

                ! ````
                //splitte string in int-Array
                let aI = msg.payload.match(/.{1,2}(?=(.{2})+(?!.))|.{1,2}$/g) //split in 2stellige strings
                .map(x => parseInt(x,16)); //konvertiere HEX strings nach Integer
                ! //xor vom inputArray
                let mustXor = aI[aI.length-1];
                ! //xor aus inputArry entfernen, ist nötig, damit sich die reduce() Methode verwenden läßt
                aI.splice(-1, 1);
                ! //xor aus inputarry bilden
                let ifXor = aI.reduce((v, vnext) => v ^ vnext);
                ! if (ifXor == mustXor) { //no error
                ! node.status({fill:"green",shape:"dot",text:'no error'})
                node.send([{payload: aI[0]},
                {payload: aI[1]},
                {payload: aI[2]},
                {payload: aI[3]},
                {payload: aI[4]},
                {payload: aI[5]},
                {payload: aI[6]},
                {payload: 'no error'}]);
                ! } else { //xor error

                node.status({fill:"red",shape:"dot",text:'XOR error'})
                node.send([null,null,null,null,null,null,null,{payload: 'XOR error'}]);
                

                }

                ! ````

                Du kannst den beiliegenden Code einfach komplett in das function-node pasten.

                Ist soweit eigentlich kommentiert. Ansonsten frag einfach.

                1 Reply Last reply Reply Quote 0
                • P
                  pfuhsy last edited by

                  Top. Das geht. Danke.

                  In "mustXor" steht der errechnete Wert, soviel hab ich verstanden. Wie bekomme ich ihn wieder in Hex gewandelt, also damit 3A anstatt 58 drin steht ? Am besten auch immer 2stellig. D.h. wenn ich eine 4 habe, brauche ich in Hex genauer genommern eine 04.

                  1 Reply Last reply Reply Quote 0
                  • R
                    rewenode last edited by

                    Also mit toString() Methode kannst du eine Zahl wieder in einen String konvertieren.

                    https://www.w3schools.com/jsref/jsref_t … number.asp

                    Also falls do mustXor wieder als String brauchst, wäre das mustXor.toString(16). Aber wozu? Der XOR Test ist ja schon gemacht.

                    1 Reply Last reply Reply Quote 0
                    • P
                      pfuhsy last edited by

                      Weil ich einen Sheldon-Tick habe und die beiden auch noch in 2 Objekten sehen will.
                      6863_unbenannt.jpg

                      1 Reply Last reply Reply Quote 0
                      • R
                        rewenode last edited by

                        Na dann schreib ihn vlt. gleich zum Ausgang 8.

                        if (ifXor == mustXor) {  //no error
                        
                            node.status({fill:"green",shape:"dot",text:'no error'})
                            node.send([{payload: aI[0]},
                                       {payload: aI[1]},
                                       {payload: aI[2]},
                                       {payload: aI[3]},
                                       {payload: aI[4]},
                                       {payload: aI[5]},
                                       {payload: aI[6]},
                                       {payload: mustXor.toString(16)}]);
                        
                        } else {  //xor error
                        
                            node.status({fill:"red",shape:"dot",text:'XOR error'})
                            node.send([null,null,null,null,null,null,null,{payload: 'XOR error'}]);
                        }
                        
                        

                        Falls du ihn im Fehlerfall auch haben willst, dann halt statt {payload: 'XOR error'} ebenfalls {payload: mustXor.toString(16)}

                        1 Reply Last reply Reply Quote 0
                        • P
                          pfuhsy last edited by

                          Ok ist drin. Funkioniert. Und wie bekomme ich den letzten Schönheitsfehler noch raus, 2Stellig ? ich suche gerne bei google "node red String format". Ich finde was mit "%2" oder so ähnlich. Kenn ich auch C, hab ich die Syntax noch nicht richtig drin.

                          1 Reply Last reply Reply Quote 0
                          • R
                            rewenode last edited by

                            Versuch mal````
                            {payload: mustXor.toString(16).padStart(2, '0')}

                            Fall du alle Ausgänge als hex 2stellig haben willst, dann musst du das .toString(16).padStart(2, '0') überall anhängen.
                            1 Reply Last reply Reply Quote 0
                            • P
                              pfuhsy last edited by

                              Super. Ich danke dir für die Unterstützung, hast mir sehr geholfen. Ich probiere das morgen mal aus.

                              1 Reply Last reply Reply Quote 0
                              • R
                                rewenode last edited by

                                Sorry, ich seh grad, das geht wohl in node-red nicht mit dem padstart() hier getestet: https://www.jdoodle.com/execute-nodejs-online

                                Muss mal sehen was man da machen kann.

                                1 Reply Last reply Reply Quote 0
                                • R
                                  rewenode last edited by

                                  Nicht schön, aber auf die Schnelle fällt mir auch nur eine eigene Funktion ein.

                                  //splitte string in int-Array 
                                  let aI = msg.payload.match(/.{1,2}(?=(.{2})+(?!.))|.{1,2}$/g)  //split in 2stellige strings
                                                      .map(x => parseInt(x,16));                 //konvertiere HEX strings nach Integer
                                  
                                  //xor vom inputArray
                                  let mustXor = aI[aI.length-1];
                                  
                                  //xor aus inputArry entfernen
                                  aI.splice(-1, 1);
                                  
                                  //xor aus inputaary bilden
                                  let ifXor = aI.reduce((v, vnext) => v ^ vnext);
                                  
                                  let fix2 = (x) => ('0'+x).slice(-2);  // einstelligen String mit führender Null
                                  
                                  if (ifXor == mustXor) {  //no error
                                  
                                      node.status({fill:"green",shape:"dot",text:'no error'})
                                      node.send([{payload: fix2(aI[0].toString(16))},
                                                 {payload: fix2(aI[1].toString(16))},
                                                 {payload: fix2(aI[2].toString(16))},
                                                 {payload: fix2(aI[3].toString(16))},
                                                 {payload: fix2(aI[4].toString(16))},
                                                 {payload: fix2(aI[5].toString(16))},
                                                 {payload: fix2(aI[6].toString(16))},
                                                 {payload: fix2(mustXor.toString(16))}]);
                                  
                                  } else {  //xor error
                                  
                                      node.status({fill:"red",shape:"dot",text:'XOR error'})
                                      node.send([null,null,null,null,null,null,null,{payload: 'XOR error'}]);
                                  }
                                  

                                  Jetzt wird an allen Ausgängen ein 2stelliger String ausgegeben.

                                  Edit: geht auch etwas kürzer s.o. und diesmal ohne Copy/Paste Fehler –hoffe ich 😉

                                  1 Reply Last reply Reply Quote 0
                                  • First post
                                    Last post

                                  Support us

                                  ioBroker
                                  Community Adapters
                                  Donate

                                  671
                                  Online

                                  31.7k
                                  Users

                                  79.9k
                                  Topics

                                  1.3m
                                  Posts

                                  2
                                  20
                                  3000
                                  Loading More Posts
                                  • Oldest to Newest
                                  • Newest to Oldest
                                  • Most Votes
                                  Reply
                                  • Reply as topic
                                  Log in to reply
                                  Community
                                  Impressum | Datenschutz-Bestimmungen | Nutzungsbedingungen
                                  The ioBroker Community 2014-2023
                                  logo