Function Node coding?

I'm sorry but I can't figure out how to code my function node.

This is what I need to run.

slope = 184.0 - 0.0 / 3730.0 - 746.0
offset = 0.0 - (slope * 746.0)

(msg.payload * slope) + offset

Try...

const slope = 184.0 - 0.0 / 3730.0 - 746.0
const offset = 0.0 - (slope * 746.0)

msg.payload = (msg.payload * slope) + offset

return msg

I think the OP probably meant
const slope = (184.0 - 0.0) /( 3730.0 - 746.0)
Otherwise it does not make sense.

You can do that with a Range node.

I'm still getting errors.

This is exactly what I have in my function node:

msg.payload =
{
const slope = 184.0 - 0.0 / 3730.0 - 746.0
const offset = 0.0 - (slope * 746.0)
     "Metrics": [
          {    "name": "Sensor1",
               "Value": (msg.payload * slope) + offset
          },
          ]
}
return msg;

Have you tried this in your function node??

const slope = (184.0 - 0.0) / (3730.0 - 746.0);
const offset = 0.0 - (slope * 746.0);

msg.payload =
{
     "Metrics": [
          {    "name": "Sensor1",
               "Value": (msg.payload * slope) + offset
          },
          ]
}
return msg;

When I inject 1 as msg.payload I get this result...
result_function_node

Yes, thank you, I really don't know how I would get along without this forum, and everyones help.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.