我有覆盆子pi和感觉帽子。我希望将加速度z,y,x,温度和压力以及时间提取到csv。但是,我写的代码没有按照我的意愿去做。我期待数据将函数保留在数组中,但调试窗口将它们显示为单独的对象。如何将加速度z,y,x和时间作为一个数组保留,以便我可以导出为CSV?
29/03/2017, 17:17:23node: abf1ef08.31a6f
msg : Object
object
payload: 0.9487
_msgid: "ae0db049.020f6"
29/03/2017, 17:17:23node: abf1ef08.31a6f
msg : Object
object
payload: 0.2781
_msgid: "ae0db049.020f6"
29/03/2017, 17:17:23node: abf1ef08.31a6f
msg : Object
object
payload: 0.1491
_msgid: "ae0db049.020f6"
29/03/2017, 17:17:23node: abf1ef08.31a6f
msg : Date
"Wed Mar 29 2017 16:17:25 GMT+0000 (UTC)
这是功能代码:
var msgAccelZ,msgAccelX,msgAccelY,msgTemperature,msgPressure,msgCurrentTime;
if (msg.topic === 'motion') {
msgAccelZ = { payload: msg.payload.acceleration.z, };
msgAccelX = { payload: msg.payload.acceleration.x, };
msgAccelY = { payload: msg.payload.acceleration.y, };
} else if (msg.topic === 'environment') {
msgTemperature = { payload: msg.payload.temperature };
msgPressure = { payload: msg.payload.pressure };
}
msgCurrentTime = new Date();
return [ [msgAccelZ, msgAccelX, msgAccelY,msgCurrentTime] ,[msgTemperature, msgPressure, msgCurrentTime] ];
答案 0 :(得分:1)
Function需要返回一个消息对象,而不仅仅是一个原始值。
按照惯例,您要将要返回的数据放在msg.payload
:
msg.payload = [ [msgAccelZ, msgAccelX, msgAccelY,msgCurrentTime] ,[msgTemperature, msgPressure, msgCurrentTime] ];
return msg;
“功能”节点的文档更详细地说明:http://nodered.org/docs/writing-functions