I've created a very minimal flow that subscribes to an MQTT broker (mosquitto) with topic "readings" and stores whatever it receives into a file "readings.json".
The content of the file storage (the messages) is not really a valid JSON - every JSON message coming from the MQTT broker is just appended to the file, but I am trying to figure out how to import/export flows between different instances in an automatic way - without human interaction.
For completeness - the message is published with this command:
mosquitto_pub -h ${MY_LOCAL_IP} -p 1883 -t "readings" -i foo001 -m '{"deviceId":"foo001","fooMetric":42.42}' -d`)
If I put the JSON representing the flow in various places e.g.:
~/.node-red/
~/.node-red/lib/
~/.node-red/lib/flows/
Then I restart the Systemd service with: sudo systemctl restart nodered.service
Then I open the web browser on <MY_LOCAL_IP>:1880
and check around in the dashboard, I am not able to find this job I would like to import.
Clicking on menu > Import > Library I get an empty list, but I was expecting to find my custom flow.
- Is there a way to automatically import a flow from a JSON file? I am looking for something that does not require human interactions.
- What should I do if I want to automatically deploy this automatically imported flow?
The only useful doc I found is this one regarding the manual process of importing/exporting flows: https://nodered.org/docs/user-guide/editor/workspace/import-export
Also: various people on the internet claim they have automatically imported flows, but the screenshots they show and the procedure they describe look like it's referring an outdated version of Node-RED.
My setup:
- Node-RED version: v0.19.5
- Node.js version: v10.15.0
This is the flow for reference:
[
{
"id": "cd5dc7af.0934f8",
"type": "tab",
"label": "Store readings",
"disabled": false,
"info": ""
},
{
"id": "70da9d53.26da74",
"type": "mqtt in",
"z": "cd5dc7af.0934f8",
"name": "mqtt-subscriber",
"topic": "readings",
"qos": "2",
"broker": "b073e910.c235e8",
"x": 260,
"y": 100,
"wires": [
[
"2b5cce9.cde0d32"
]
]
},
{
"id": "2b5cce9.cde0d32",
"type": "file",
"z": "cd5dc7af.0934f8",
"name": "",
"filename": "readings.json",
"appendNewline": true,
"createDir": false,
"overwriteFile": "false",
"x": 510,
"y": 100,
"wires": [
[]
]
},
{
"id": "b073e910.c235e8",
"type": "mqtt-broker",
"z": "",
"name": "mosquitto-mqtt-broker",
"broker": "localhost",
"port": "1883",
"clientid": "",
"usetls": false,
"compatmode": true,
"keepalive": "60",
"cleansession": true,
"birthTopic": "",
"birthQos": "0",
"birthPayload": "",
"closeTopic": "",
"closeQos": "0",
"closePayload": "",
"willTopic": "",
"willQos": "0",
"willPayload": ""
}
]