节点红色将消息输出到CSV [英] Node-red output a message to CSV

查看:131
本文介绍了节点红色将消息输出到CSV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几天里,我一直在尝试并阅读以在Node-Red中完成一些非常具体的事情:我想将(LoRa)消息发送到CSV. 该CSV文件应包含以下项目:

For the past couple of days I have been trying and reading to get something very specific done in Node-Red: I want to send the (LoRa) message to a CSV. This CSV should contain the following items:

  • 主题
  • 日期
  • 有效载荷

我可以使用功能节点插入日期:

I can insert the date using a function node:

var str1 = Date();

我一直在使用CSV节点,但是无法输出逗号分隔的值.所有这些可能与我缺乏JavaScript编程技能有关,这就是为什么我求助于您.

I have been playing around with CSV node, but I can't get it to output comma separated values. All this has probably to do with my lack of javascript programming skills, which is why I turn to you.

你能帮我吗?

我仍在寻找答案,这给我带来了以下好处: 功能节点:

I'm still looking for the answer, which has brought me the following: Function node:

var res = Date() + "," + msg.topic + "," + msg.payload; return [ { payload: res } ]; 

输出:

[{"col1":"Mon Oct 17 2016 17:10:20 GMT+0200 (CEST)","col2":"1/test/1","col3":"string1"}]

我现在想要的是丢失多余的信息,例如列名和[{}]

All I want now is to lose the extra information such as column names and [{}]

推荐答案

CSV节点仅在msg.payload字段上起作用,因此您必须将多余的数据复制到有效负载对象中才能获取所需的输出.

The CSV node works only on the msg.payload field so you will have to copy the extra data into the payload object to get it to output what you want.

因此,要正确格式化数据,您需要在CSV节点之前放置一个具有以下内容的功能节点:

So to format the data correctly you need to place a function node with the following before the CSV node:

var originalPayload = msg.payload;
var newPayload = {};
newPayload.date = new Date().toString();
newPayload.topic = msg.topic;
newPayload.payload = originalPayload;
msg.payload = newPayload;

return msg;

并配置CSV节点以输出列"date,topic,payload"

And configure the CSV node to output columns "date,topic,payload"

这篇关于节点红色将消息输出到CSV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆