How to - if partly missing payload no node error

Hello
i got a function Node to prepare the output for InfluxDB

msg.payload = {
name: msg.payload.name,
mode: msg.payload.mode,
powerOut:msg.payload.poweroutW,
frq: msg.payload.freq
}
return msg;

the problem sometimes the information i got is empty.
and if as example msg.payload.poweroutW is not in the packet the writing to the DB will just file for all information.

Would it be possible to have like a Variable which hold a number if the msg.payload would be missing the variable would be picked up and the other payload would not be lost.

have a nice day
vinc

You can use shortcut or statements e.g.

msg.payload = {
  name: msg.payload.name,
  mode: msg.payload.mode,
  powerOut: msg.payload.poweroutW || 44,
  frq: msg.payload.freq
}
return msg;

@hardillb
thanks for your fast feedback.
i have changed my node i wait to get a faulty packet
have a nice day
vinc

@hardillb
would something like

powerOut: msg.payload.poweroutW || "",

Also Work?
i do not add a value but leave it empty or mayber || , would be enough?

have a nice day
vinc

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