有没有办法将现有的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
(并且&#39; Deploy&#39;按钮处于非活动状态)。
这是超简单的流程:
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-start
或node-red
启动服务,以及请求中包含或不包含参数-H "Node-RED-Deployment-Type: full"
,不会有任何区别。
系统配置:
再次非常感谢。
更新2
似乎问题出在Node.js和/或Node-RED版本上。尝试在另一个Pi中运行Node.js 6.9.5&amp; Node-RED 0.16.2,它运行正常。
答案 0 :(得分:6)
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"