Is there any way for deploying an existing Node-RED flow file myflow.json
to a remote machine running Node-RED?
After much googling, I stumbled upon this discussion in the relevant Google group, but it is not very enlightening.
UPDATE (after the suggested answer below)
Here is the output of the suggested request from a remote machine:
[scripts]$ curl -v -X POST http://192.168.70.73:1880/flows -H "Content-Type: application/json" --data "@remote_test.json"
* About to connect() to 192.168.70.73 port 1880 (#0)
* Trying 192.168.70.73... connected
* Connected to 192.168.70.73 (192.168.70.73) port 1880 (#0)
> POST /flows HTTP/1.1
> User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.21 Basic ECC zlib/1.2.3 libidn/1.18 libssh2/1.4.2
> Host: 192.168.70.73:1880
> Accept: */*
> Content-Type: application/json
> Content-Length: 1088
> Expect: 100-continue
>
< HTTP/1.1 100 Continue
< HTTP/1.1 204 No Content
< X-Powered-By: Express
< Date: Fri, 10 Feb 2017 11:45:24 GMT
< Connection: keep-alive
<
* Connection #0 to host 192.168.70.73 left intact
* Closing connection #0
with a 204 response (indicating success).
Here is the respective output in the local machine console:
10 Feb 13:45:24 - [info] Stopping flows
10 Feb 13:45:24 - [info] Stopped flows
10 Feb 13:45:24 - [info] Starting flows
10 Feb 13:45:24 - [info] Started flows
after which nothing happens.
The flow-to-be-deployed remote_test.json
does indeed show up in the GUI of the local machine, but it is not running; furthermore, when I try to manually inject or enable the debug node, I get an Error: node not deployed
in the local GUI (and the 'Deploy' button is inactive).
This is the ultra-simple flow:
with the format
node simply parsing the temperature measurements received from get_temp
every 5 seconds and adding a timestamp:
var temp = parseFloat(msg.payload.replace( /[^\d\.]*/g, ''));
var time = new Date().toISOString().replace(/\..+/, '');
msg.payload = {'measurements' : [ { 'time' : time },
{ 'temperature' : temp } ]
};
console.log(msg.payload);
return msg;
And here is the console output when the flow is deployed locally:
10 Feb 14:08:25 - [info] Stopped flows
10 Feb 14:08:25 - [info] Starting flows
10 Feb 14:08:25 - [info] Started flows
{ measurements: [ { time: '2017-02-10T12:08:30' }, { temperature: 34.7 } ] }
{ measurements: [ { time: '2017-02-10T12:08:35' }, { temperature: 34.2 } ] }
{ measurements: [ { time: '2017-02-10T12:08:40' }, { temperature: 33.6 } ] }
{ measurements: [ { time: '2017-02-10T12:08:45' }, { temperature: 33.6 } ] }
Starting the service with node-red-start
or node-red
, as well as including or not the argument -H "Node-RED-Deployment-Type: full"
in the request, do not make any difference.
System configuration:
UPDATE 2
It seems that the issue was with the Node.js and/or Node-RED versions. Tried it in a different Pi, running Node.js 6.9.5 & Node-RED 0.16.2, and it works OK.
This means that currently running flows are interrupted and restarted. Inject nodes will fire. If for some reason when you deploy a flow node-red stalls or crashes then restarting node-red will usually result in a stall or crash as there is something in the deployed flow that is causing it.
All deployed flows will be redeployed. This means that currently running flows are interrupted and restarted. Inject nodes will fire. If for some reason when you deploy a flow node-red stalls or crashes then restarting node-red will usually result in a stall or crash as there is something in the deployed flow that is causing it.
If a flow is disabled, none of the nodes it contains will be created when the flow is deployed. The button in the Information sidebar can also be used to enable or disable the node/flow.
Inject nodes will fire. If for some reason when you deploy a flow node-red stalls or crashes then restarting node-red will usually result in a stall or crash as there is something in the deployed flow that is causing it. In this case you can start node-red using the safe option which starts node-red but doesn’t deploy the flows.
The Node-RED runtime exposes a REST api that provides methods for deploying a new flow configuration on the runtime.
The specific API in question is documented here: http://nodered.org/docs/api/admin/methods/post/flows/
It allows you to do an HTTP POST containing the flow configuration you want the runtime to deploy.
For example, if flow file is in myflow.json
and Node-RED is running at http://localhost:1880
, you can use curl to deploy it:
curl -X POST http://localhost:1880/flows -H "Content-Type: application/json" --data "@myflow.json"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With