Pass data to a function node?

Hi,

I have a function node that is accessed via a call node.

The function sends data to a database.
I have numerous meters that I wish to save the data into the same database.
At the moment I copy the function and just change device & Garage and add it in another flow.

2 examples ...
let device = "IP15";
let location = "Garage"

let device = "IP21";
let location = "Shed"

Is there a way to only have one function ... and pass the device & locations to it ?
Thanks
.

let meter           = msg.payload
let device          = "IP15";                                                               // ENTER HERE ...  the last part of the IP address.
let location        = "Garage";                                                             // ENTER HERE ... Location

let new_date        = new Date();                                                           

let iso             = new Date().toISOString();                                           

let timestamp       = Math.round(new_date.getTime() / 1000);                                


let   payload =
      { 
          iso:            iso,
          location:       location,      
          timestamp:      timestamp,
          meter_reading:  meter
      };

Pass them in on the msg object

e.g. msg.location and msg.device

Thanks hardillb :slightly_smiling_face:

That worked, so simple but took me ages to work out how to pass them on :roll_eyes:

For anyone else in the future, create a function node and then this will pass it on ...

msg.device   = 'IP15';
msg.location = 'Garage';
return msg;

Also very simple and more elegant with a change node!

Why didn't i think of that :upside_down_face:

I usually look for existing nodes to use, never occurred to me to use that one , thanks
So much easier and elegant, I like elegant code :+1:

Thanks

It's very easy, especially if you are used to a more traditional programming language, to automatically reach for a function node to tackle a problem.

A perfectly valid approach but at the cost of possibly losing the editor's visual representation of the program logic