【发布时间】:2017-02-09 17:51:43
【问题描述】:
有没有办法将现有的 Node-RED 流文件 myflow.json 部署到运行 Node-RED 的远程机器上?
经过一番谷歌搜索,我在相关的谷歌群组中偶然发现了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(并且“部署”按钮处于非活动状态)。
这是超简单的流程:
使用 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",没有任何区别。
系统配置:
- 树莓派 3
- Node.js 7.4.0
- Node-RED 0.13.4
更新 2
问题似乎出在 Node.js 和/或 Node-RED 版本上。在不同的 Pi 中尝试过,运行 Node.js 6.9.5 和 Node-RED 0.16.2,它工作正常。
【问题讨论】:
-
@Sergio 好吧,这是 4 年前的事了,恐怕我已经没有流量了
标签: node-red