NEWS
[GELÖST] JSON String für Arduino aus ioBroker Objekten erstellen
-
Hallo zusammen,
ich stehe gerade Irgendiwe auf dem Schlauch. :?
Ich lasse mir über Arduino einige Daten für eine eigenentwickelte Poolsteuerung per Serielle Schnitstele im JSON Format an Noered schicken.
Diese schicke ich dann von NodeRed an ioBroker. Das klappt wunderbar
nun möchte ich dem Arduino aber auch einige Daten im JSON Format von NodeRed aus schicken. Hier hänge ich gerade.
Wie kann ich aus mehreren Objekte einen JSON String erstellen?
Mit nur einem Objekt klappt das halbwegs, jedoch ist der Name der Nachricht auch noch falsch. (val –> PoolSollTemp)
So sieht es aus: "{"val":50}"
So müsste es aussehen: {"PoolSollTemp":50,"P1SolarPumpe":true} (hier mit weiteren Werten)
Wer hatte damit schon zu tun und kann mir einen Tipp geben?
Hier mal mein Flow:
[ { "id": "5ec56b41.f215c4", "type": "serial out", "z": "aca75de6.d3a82", "name": "", "serial": "c6e3ab46.9b7588", "x": 1015.7735557556152, "y": 401.74220085144043, "wires": [] }, { "id": "70af1a43.93aee4", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_PoolSollTemp", "topic": "admin.0.Eigene.Pool.Change_PoolSollTemp", "payloadType": "object", "onlyack": "", "func": "all", "gap": "", "x": 215.7735252380371, "y": 527.4063394069672, "wires": [ [ "59c84b9d.d6a334", "52f87b90.8cebc4" ] ] }, { "id": "c841ef2b.d5cd8", "type": "debug", "z": "aca75de6.d3a82", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "x": 1014.0236129760742, "y": 362.0390682220459, "wires": [] }, { "id": "4870430b.bcf56c", "type": "json", "z": "aca75de6.d3a82", "name": "", "property": "payload", "action": "", "pretty": false, "x": 798.781307220459, "y": 413.64063835144043, "wires": [ [ "c841ef2b.d5cd8" ] ] }, { "id": "59c84b9d.d6a334", "type": "change", "z": "aca75de6.d3a82", "name": "Unnötiges löschen", "rules": [ { "t": "delete", "p": "payload.ack", "pt": "msg" }, { "t": "delete", "p": "payload.ts", "pt": "msg" }, { "t": "delete", "p": "payload.q", "pt": "msg" }, { "t": "delete", "p": "payload.lc", "pt": "msg" }, { "t": "delete", "p": "payload.from", "pt": "msg" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 520.0234603881836, "y": 475.0390911102295, "wires": [ [ "4870430b.bcf56c", "11011ec3.911771" ] ] }, { "id": "52f87b90.8cebc4", "type": "debug", "z": "aca75de6.d3a82", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "x": 516.0234489440918, "y": 560.0390758514404, "wires": [] }, { "id": "11011ec3.911771", "type": "debug", "z": "aca75de6.d3a82", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "x": 760.0234451293945, "y": 501.03910636901855, "wires": [] }, { "id": "45d396a5.ecbb98", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_P1SolarPumpe", "topic": "admin.0.Eigene.Pool.Change_P1SolarPumpe", "payloadType": "object", "onlyack": "", "func": "all", "gap": "", "x": 230.0234375, "y": 588.0390625, "wires": [ [] ] }, { "id": "c6e3ab46.9b7588", "type": "serial-port", "z": "", "serialport": "/dev/ttyUSB0", "serialbaud": "19200", "databits": "8", "parity": "none", "stopbits": "1", "newline": "\\n", "bin": "false", "out": "char", "addchar": false } ]
-
Ich hab die Lösung falls es jemanden interessiert
[ { "id": "5ec56b41.f215c4", "type": "serial out", "z": "aca75de6.d3a82", "name": "Pool", "serial": "c6e3ab46.9b7588", "x": 1417.773754119873, "y": 644.7422542572021, "wires": [] }, { "id": "70af1a43.93aee4", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_KollektorStart", "topic": "admin.0.Eigene.Pool.Change_KollektorStart", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 187.7736053466797, "y": 586.4064445495605, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "45d396a5.ecbb98", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_KollektorStop", "topic": "admin.0.Eigene.Pool.Change_KollektorStop", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 187.02349853515625, "y": 649.0391654968262, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "9406678e.0446a8", "type": "debug", "z": "aca75de6.d3a82", "name": "", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "false", "x": 1431.773494720459, "y": 739.7502040863037, "wires": [] }, { "id": "880909c2.bc7478", "type": "function", "z": "aca75de6.d3a82", "name": "Daten sammel", "func": "out=context.data ||{}\nnode.log(\"start\" + msg.payload);\nnode.log(\"start stored\" + context.data);\ntopic=msg.topic;\nnode.log(topic);\n\nif (msg.payload==\"send\")\n{\n msg.payload=context.data;\n msg.out=\"Sent data to \" +out.house;\n msg.topic=\"pool/settings\";\n context.data=null;\n return [msg];\n}\n\nelse \n{\n out[topic]=msg.payload;\n context.data=out;\n node.log(\"stored\" + context.data);\n return null;\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "x": 712.0234756469727, "y": 645.0391654968262, "wires": [ [ "c8d42c65.ffb99" ] ] }, { "id": "7c5156c5.da5478", "type": "inject", "z": "aca75de6.d3a82", "name": "", "topic": "pool/settings", "payload": "send", "payloadType": "str", "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "x": 587.0234298706055, "y": 1158.0392265319824, "wires": [ [ "880909c2.bc7478" ] ] }, { "id": "5bd55717.1388d8", "type": "change", "z": "aca75de6.d3a82", "name": "", "rules": [ { "t": "change", "p": "topic", "pt": "msg", "from": "admin/0/Eigene/Pool/Change_", "fromt": "str", "to": "", "tot": "str" } ], "action": "", "property": "", "from": "", "to": "", "reg": false, "x": 474.02344512939453, "y": 773.0391502380371, "wires": [ [ "880909c2.bc7478" ] ] }, { "id": "63fa34f5.6bc9cc", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_Automatik", "topic": "admin.0.Eigene.Pool.Change_Automatik", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 193.0234375, "y": 523.0390739440918, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "cc0f415c.25d71", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_P2PoolPumpe", "topic": "admin.0.Eigene.Pool.Change_P2PoolPumpe", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 181.0234375, "y": 764.0390625, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "18454efa.588f31", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_PoolSollTemp", "topic": "admin.0.Eigene.Pool.Change_PoolSollTemp", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 185.27333068847656, "y": 818.6717948913574, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "4a86fdf1.13acb4", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_P1SolarPumpe", "topic": "admin.0.Eigene.Pool.Change_P1SolarPumpe", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 174.2732696533203, "y": 709.6717185974121, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "39a7e1ea.0064ee", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_minMessungenAnzahl", "topic": "admin.0.Eigene.Pool.Change_minMessungenAnzahl", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 171.0234375, "y": 930.0390739440918, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "630e44a.891eabc", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_minimaldifferenz", "topic": "admin.0.Eigene.Pool.Change_minimaldifferenz", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 185.27333068847656, "y": 986.6717948913574, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "9ba23aa1.01fe68", "type": "ioBroker in", "z": "aca75de6.d3a82", "name": "Change_SollSperTakte", "topic": "admin.0.Eigene.Pool.Change_SollSperTakte", "payloadType": "value", "onlyack": "", "func": "all", "gap": "", "x": 194.2732696533203, "y": 870.6717643737793, "wires": [ [ "5bd55717.1388d8" ] ] }, { "id": "c8d42c65.ffb99", "type": "json", "z": "aca75de6.d3a82", "name": "", "property": "payload", "action": "str", "pretty": false, "x": 976.0195693969727, "y": 635.753927230835, "wires": [ [ "a1920200.7f4e4" ] ] }, { "id": "a1920200.7f4e4", "type": "function", "z": "aca75de6.d3a82", "name": "\\n - Line Feed anfügren", "func": "msg.payload = msg.payload+\"\\n\"; \nreturn msg;", "outputs": 1, "noerr": 0, "x": 1170.8906631469727, "y": 710.648458480835, "wires": [ [ "9406678e.0446a8", "5ec56b41.f215c4" ] ] }, { "id": "c6e3ab46.9b7588", "type": "serial-port", "z": "", "serialport": "/dev/ttyUSB0", "serialbaud": "19200", "databits": "8", "parity": "none", "stopbits": "1", "newline": "\\n", "bin": "false", "out": "char", "addchar": false } ]