FlowFuse / nr-project-nodes

A set of Node-RED nodes for inter-project communication within the FlowFuse platform
Apache License 2.0
5 stars 0 forks source link

First publish of project link nodes #1

Closed Steve-Mcl closed 1 year ago

Steve-Mcl commented 1 year ago

part of https://github.com/flowforge/flowforge/issues/662

About

The basic premise of the project link nodes are similar to that of the core Node-RED link nodes whereby there are 3 nodes that provide invisible linkage between nodes. However, the project link nodes operate across multiple Node-RED projects

Nodes...

The whole msg object is transmitted from project to project meaning that properties like msg.topic and msg.my_custom_property will be included in the transmission

project link in

This node listens for msgs sent by either project link call or project link out

project link out

This node sends msgs to the target project/path and will be received by a matching project link in node

project link call

This node sends msgs to the target project link in project/. The msg MUST be returned by a project link out set to mode "return" The returned msg will then be sent out of the project link call output

Known issues

Configuration

The settings file must contain a flowForge setting and other properties in order for the node to loaded into the runtime. If these are missing, the node will NOT be loaded.

    flowforge: {
        forgeURL: 'http://xxxxxxxxx:3000',
        teamID:  'xxxxxxxx',
        projectID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx',
        projectLink: {
            token: 'fft_xxxxxx-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
            broker: {
                url: '',
                username: 'xxxx',
                password: 'xxxx',
                clientID: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx:n'
            }
        }
    }

TODO

Future possibilities

Steve-Mcl commented 1 year ago

Nodes

Project Link nodes

image

Project Link In

image

Project Link Out

chrome_oGdXqxiLf3

Project Link Call

image

Demo

image

Demo flows (to aid reviewer testing)

Project 1

[{"id":"76983376f21fd538","type":"group","z":"49f61d916c8f6022","name":"Project 1","style":{"label":true},"nodes":["e806c9c13eb8949e","cded4dfd5a89a202","0f1123444aef553f","760cd251b4a41e55","e84d337f40002578","01c5c687c012db8d","5cb655aa0ca2a335","40d75caf3597df6b","0e3bb7e082b5417c","45ced513e3f5e049","6d2ed99ed1190b98","a6aa06da0cae4cd3","1ba72241caaf0b81","b1d567767f575fe5","f008b57981ad055e","15c252c0fbe13929"],"x":1894,"y":39,"w":692,"h":462},{"id":"e806c9c13eb8949e","type":"inject","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1990,"y":80,"wires":[["45ced513e3f5e049"]]},{"id":"cded4dfd5a89a202","type":"project link in","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","project":"ca65f5ed-aea0-4a10-ac9a-2086b6af6700","topic":"flow1/getdata","x":2010,"y":220,"wires":[["a6aa06da0cae4cd3"]]},{"id":"0f1123444aef553f","type":"project link out","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","mode":"return","project":"broadcast","topic":"b1/b1","x":2480,"y":300,"wires":[]},{"id":"760cd251b4a41e55","type":"inject","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"Gather data from projects","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"Gather data from projects","payload":"{}","payloadType":"json","x":2050,"y":400,"wires":[["e84d337f40002578"]]},{"id":"e84d337f40002578","type":"project link call","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","project":"ca65f5ed-aea0-4a10-ac9a-2086b6af6700","topic":"flow1/getdata","timeout":"5","x":2270,"y":400,"wires":[["01c5c687c012db8d"]]},{"id":"01c5c687c012db8d","type":"debug","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"Nested calls result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":2450,"y":400,"wires":[]},{"id":"5cb655aa0ca2a335","type":"project link call","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"Project 2: flow1/getdata","project":"23d79df8-183c-4104-aa97-8915e1897326","topic":"flow1/getdata","timeout":"5","x":2110,"y":300,"wires":[["15c252c0fbe13929"]]},{"id":"40d75caf3597df6b","type":"inject","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":1955,"y":460,"wires":[["0e3bb7e082b5417c"]],"l":false},{"id":"0e3bb7e082b5417c","type":"function","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"rapid fire","func":"for (let index = 0; index < 5; index++) {\n    const element = {payload: index+1};\n    node.send(element);\n    \n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2060,"y":460,"wires":[["e84d337f40002578"]]},{"id":"45ced513e3f5e049","type":"change","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","rules":[{"t":"set","p":"data","pt":"flow","to":"{\"value\":1,\"info\":\"i am from project1:flow.data\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":2130,"y":80,"wires":[[]]},{"id":"6d2ed99ed1190b98","type":"change","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","rules":[{"t":"set","p":"project1","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2320,"y":220,"wires":[["5cb655aa0ca2a335"]]},{"id":"a6aa06da0cae4cd3","type":"link call","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","links":["b1d567767f575fe5"],"linkType":"static","timeout":"30","x":2160,"y":220,"wires":[["6d2ed99ed1190b98"]]},{"id":"1ba72241caaf0b81","type":"function","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"Get flow.data","func":"msg.payload = flow.get(\"data\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":2070,"y":140,"wires":[["f008b57981ad055e"]]},{"id":"b1d567767f575fe5","type":"link in","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"getdata","links":[],"x":1955,"y":140,"wires":[["1ba72241caaf0b81"]]},{"id":"f008b57981ad055e","type":"link out","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"link out 1","mode":"return","links":[],"x":2185,"y":140,"wires":[]},{"id":"15c252c0fbe13929","type":"change","z":"49f61d916c8f6022","g":"76983376f21fd538","name":"","rules":[{"t":"set","p":"project2","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":2320,"y":300,"wires":[["0f1123444aef553f"]]}]

Project 2

[{"id":"960896f888749d89","type":"project link in","z":"49f61d916c8f6022","name":"","project":"23d79df8-183c-4104-aa97-8915e1897326","topic":"flow1/getdata","x":1330,"y":220,"wires":[["a6aa06da0cae4cd3"]]},{"id":"e245dfe4785d94fc","type":"project link out","z":"49f61d916c8f6022","name":"","mode":"return","project":"broadcast","topic":"","x":1640,"y":220,"wires":[]},{"id":"e806c9c13eb8949e","type":"inject","z":"49f61d916c8f6022","name":"init","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":1330,"y":100,"wires":[["45ced513e3f5e049"]]},{"id":"45ced513e3f5e049","type":"change","z":"49f61d916c8f6022","name":"","rules":[{"t":"set","p":"data","pt":"flow","to":"{\"value\":2,\"info\":\"i am from project2:flow.data\"}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":1470,"y":100,"wires":[[]]},{"id":"a6aa06da0cae4cd3","type":"link call","z":"49f61d916c8f6022","name":"","links":["b1d567767f575fe5"],"linkType":"static","timeout":"30","x":1500,"y":220,"wires":[["e245dfe4785d94fc"]]},{"id":"b1d567767f575fe5","type":"link in","z":"49f61d916c8f6022","name":"getdata","links":[],"x":1275,"y":160,"wires":[["1ba72241caaf0b81"]]},{"id":"1ba72241caaf0b81","type":"function","z":"49f61d916c8f6022","name":"Get flow.data","func":"msg.payload = flow.get(\"data\")\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1410,"y":160,"wires":[["f008b57981ad055e"]]},{"id":"f008b57981ad055e","type":"link out","z":"49f61d916c8f6022","name":"link out 1","mode":"return","links":[],"x":1525,"y":160,"wires":[]}]
knolleary commented 1 year ago

If the client is not authorised to publish for any reason (mis configuration etc), it is currently an uncaught exception that kills Node-RED:

[NR] 2 Aug 10:58:57 - [red] Uncaught Exception:
[NR] 2 Aug 10:58:57 - [error] Error: Publish error: Not authorized
[NR]     at MqttClient._handleAck (/Users/nol/code/flowforge/flowforge-nr-project-nodes/node_modules/mqtt/lib/client.js:1612:15)