Hi @TotallyInformation @Steve-Mcl and thank you for all the good advices !
Here is a version of my flow with dynamic MQTT :). I can read infos from a .json file, connect to a MQTT broker and get the msg from my devices !
I also added something to append a new object and push it to a new file.
Still a lot of things to do but it's leaning well ! It put it here just in case someone wants more infos. And if you have any advise to do it better, don't hesitate !
Thank you again !
[{"id":"affb109fcb6efdfe","type":"watch","z":"ce6f6a0bdd3686d4","name":"Watch ttn.json","files":"Documents/mobilab_ttn/hubis_test.json","recursive":"","x":490,"y":640,"wires":[["830c9826d1a493e6"]]},{"id":"830c9826d1a493e6","type":"file in","z":"ce6f6a0bdd3686d4","name":"Read ttn.json","filename":"Documents/mobilab_ttn/hubis.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":670,"y":640,"wires":[["e10b2c1981d2f8f3"]]},{"id":"d08b06d4144023bb","type":"inject","z":"ce6f6a0bdd3686d4","name":"Inject auto","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":435,"y":600,"wires":[["830c9826d1a493e6"]],"l":false},{"id":"e10b2c1981d2f8f3","type":"json","z":"ce6f6a0bdd3686d4","name":"","property":"payload","action":"","pretty":false,"x":810,"y":640,"wires":[["262de0462e7dfd34"]]},{"id":"262de0462e7dfd34","type":"function","z":"ce6f6a0bdd3686d4","name":"","func":"msg1={}\nmsgsend=[]\nfor (const i in msg.payload){\n msg1[i]= {\n \"topic\": 'v3/'+ msg.payload[i].appName +'@ttn/devices/'+msg.payload[i].devEUI+'/up',\n \"action\":'subscribe',\n };\n msgsend.push(msg1[i])\n}\nreturn [msgsend];\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":940,"y":640,"wires":[["b6353c010af20c61","7987b5b106616b2e"]]},{"id":"b6353c010af20c61","type":"debug","z":"ce6f6a0bdd3686d4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1150,"y":580,"wires":[]},{"id":"7987b5b106616b2e","type":"mqtt in","z":"ce6f6a0bdd3686d4","name":"MQTT merle app","topic":"","qos":"2","datatype":"json","broker":"c87222d8.d2c36","nl":false,"rap":true,"rh":0,"inputs":1,"x":1100,"y":640,"wires":[["334fb3b44fc9cd25","3acb65ecd036ce61"]]},{"id":"334fb3b44fc9cd25","type":"function","z":"ce6f6a0bdd3686d4","name":"","func":"var message = {\n \"id\": msg.payload.end_device_ids.device_id,\n \"name\":'3C1-WS(Aval)',\n \"lat\":43.642874,\n \"lon\":5.017567,\n \"value\": 1-msg.payload.uplink_message.decoded_payload.bytes[0]\n};\n\nmsg.payload=message;\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1260,"y":640,"wires":[["cabbfe16587345af"]]},{"id":"3acb65ecd036ce61","type":"debug","z":"ce6f6a0bdd3686d4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1350,"y":580,"wires":[]},{"id":"cabbfe16587345af","type":"debug","z":"ce6f6a0bdd3686d4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1410,"y":640,"wires":[]},{"id":"171a5c812c9e20e1","type":"inject","z":"ce6f6a0bdd3686d4","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":395,"y":700,"wires":[["876fdf9ee096eaad"]],"l":false},{"id":"876fdf9ee096eaad","type":"file in","z":"ce6f6a0bdd3686d4","name":"Read ttn.json","filename":"Documents/mobilab_ttn/hubis_test.json","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":510,"y":740,"wires":[["feb033ff708c8de4","1721b699ad331b20"]]},{"id":"feb033ff708c8de4","type":"json","z":"ce6f6a0bdd3686d4","name":"","property":"payload","action":"","pretty":false,"x":670,"y":740,"wires":[["e06b8f7835cd6040"]]},{"id":"1721b699ad331b20","type":"debug","z":"ce6f6a0bdd3686d4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":680,"y":800,"wires":[]},{"id":"e06b8f7835cd6040","type":"function","z":"ce6f6a0bdd3686d4","name":"","func":"\nvar myObj = {\n \"devEUI\":\"eui-70b3d57ed004c18a\",\n \"name\":\"3C3-WS(Aval)\",\n \"appName\" : \"merle\"\n};\n//push the object to your array\nmsg.payload.push(myObj);\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":800,"y":740,"wires":[["a2215c2edddc202f"]]},{"id":"a2215c2edddc202f","type":"file","z":"ce6f6a0bdd3686d4","name":"hubis_test","filename":"Documents/mobilab_ttn/hubis_test.json","appendNewline":true,"createDir":true,"overwriteFile":"true","encoding":"none","x":950,"y":740,"wires":[["9c12aa73277cbab3"]]},{"id":"9c12aa73277cbab3","type":"debug","z":"ce6f6a0bdd3686d4","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1110,"y":740,"wires":[]},{"id":"c87222d8.d2c36","type":"mqtt-broker","name":"merle","broker":"eu1.cloud.thethings.network","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"sessionExpiry":""}]
the file where the json is stored looks like this :
[{"devEUI":"eui-70b3d57ed004c188","devName":"3C1-WS(Aval)","appName":"merle"},{"devEUI":"eui-70b3d57ed004c189","devName":"3C2-WS(Aval)","appName":"merle"},{"devEUI":"eui-70b3d57ed004c18a","name":"3C3-WS(Aval)","appName":"merle"},{"devEUI":"eui-70b3d57ed004c18a","name":"3C3-WS(Aval)","appName":"merle"},{"devEUI":"eui-70b3d57ed004c18a","name":"3C3-WS(Aval)","appName":"merle"}]