Function inserts '[object Object]' instead of it´s payload

Hi there,

for whatever reason i fail inserting the value of a msg object into a topic - he only shows '[object Object]':

I assume the error is within the "MakeSQL" function:

var temp = {payload: msg.payload.temperatur};
var vent = {payload: msg.payload.ventil};

msg.topic = "INSERT INTO `Markus_HO` (`ID`, `Raum`, `Temperatur`, `Timestamp`,`Ventil`) VALUES (NULL, 'Markus_HO', '"+temp+"', CURRENT_TIMESTAMP, '"+vent+"');";
return msg;

I am sure it´s a small thing but i can´t see it and hope for a quick: "It´s so damn easy friend: It´s..." :slight_smile:

Its because you are defining both variables as objects which have the value under a key called payload within in them. If you actually want to assign the value from the wanted message property directly to the variable in a way that can be used in string concatenation you would just have to do something like this:

var temp = msg.payload.temperatur;

Johannes

Thanks - this does the trick after moving to var temp = msg.payload.Temperatur;

1 Like

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