Search code examples
javascriptraspberry-pinode-red

pi sense and exporting data


I'm new to node red. I've added the PI Sense the Raspberry PI and want to retrieve just the acceleration Z axis as show below (extracted from the debug window). I've written a function to extract just the acceleration and pass that on the flow. However, the function isn't work. Please help?

Function
var z = msg.payload.acceleration.z;
return [z]; 

.

Extracted from the debug window
19/03/2017, 20:59:06node: fa789a6a.8d4f98
motion : msg : Object
object
topic: "motion"
payload: object
acceleration: object
x: 0.0279
y: -0.3536
z: 0.9068
gyroscope: object
x: 0.0011
y: 0.0022
z: -0.0004
orientation: object
roll: 338.8994
pitch: 358.3852
yaw: 123.876
compass: 124
_msgid: "51b99603.7dac98"

Solution

  • You have to return a msg object from a function node not just a value.

    Something like this:

    msg.payload = msg.payload.acceleration.z;
    return msg;