如何在 Node-RED 中远程部署流文件?

How can I remotely deploy a flow file in Node-RED?

有什么方法可以将现有的 Node-RED 流文件 myflow.json 部署到远程机器 运行 Node-RED?

经过多次谷歌搜索后,我在相关的 Google 组中偶然发现了 this discussion,但这并不是很有启发性。

更新(在下面的建议答案之后)

这是来自远程机器的建议请求的输出:

[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

204 响应(表示 success)。

这是本地机器控制台中的相应输出:

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

之后什么都没有发生。

要部署的流程 remote_test.json 确实显示在本地计算机的 GUI 中,但不是 运行;此外,当我尝试手动注入或启用调试节点时,我在本地 GUI 中得到一个 Error: node not deployed(并且 'Deploy' 按钮处于非活动状态)。

这是超简单的流程:

format 节点每 5 秒简单地解析从 get_temp 收到的温度测量值并添加时间戳:

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;

下面是本地部署流程时的控制台输出:

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 } ] }

使用 node-red-startnode-red 启动服务,以及在请求中包含或不包含参数 -H "Node-RED-Deployment-Type: full",都没有任何区别。

系统配置:

更新 2

问题似乎出在 Node.js and/or Node-RED 版本上。在不同的 Pi,运行 Node.js 6.9.5 和 Node-RED 0.16.2 中尝试过,它工作正常。

Node-RED 运行时公开了一个 REST api,它提供了在运行时部署新流配置的方法。

此处记录了具体的 API 问题:http://nodered.org/docs/api/admin/methods/post/flows/

它允许您执行包含您希望运行时部署的流配置的 HTTP POST。

例如流文件在myflow.json,Node-RED在http://localhost:1880运行,可以使用curl部署:

curl -X POST http://localhost:1880/flows -H "Content-Type: application/json" --data "@myflow.json"