this my function code:
msg.topic = msg.payload
var tag1 = msg.payload.P1-basic/L1_N_Voltage(V)
var tag2 = msg.payloadP1-basic/L1_L2_Voltage(V)
msg.topic="INSERT INTO test (L1_N_VOLTAGE, L1_L2_VOLTAGE ) VALUES ('"+ tag1 +"', '"+ tag2 +"')";
return msg;
If you have a minus sign in a property name (which is a bad idea, don't do it unless you have not choice) then you can't use the dot shortcut for property access. The interpreter sees the dash and thinks it is a minus operator. You will have to use var tag1 = msg.payload["P1-basic"]/L1_N_Voltage(V)
Is L1_N_Voltage a function? if not then what is L1_N_Voltage(V) supposed to mean?
Or perhaps P1-basic/L1_N_Voltage(V) is the property name, in which case put it all in quotes in brackets.
Also you have a dot missing in the next line.
[Edit] Also, before connecting to the database node, feed it into a debug node and check the query looks correct.
thanks for response collin.
P1-basic/L1_N_Voltage(V) is my topic mqtt publish.
I tried the code you gave it doesn't work.
msg.topic = msg.payload
var tag1 = msg.payload["P1-basic/L1_N_Voltage(V)"]
var tag2 = msg.payload["P1-basic/L1_L2_Voltage(V)"]
//var tag2 = msg.payload.P1-basic/L1_L2_Voltage(V)
msg.topic="INSERT INTO test (L1_N_VOLTAGE, L1_L2_VOLTAGE ) VALUES ('"+ tag1 +"', '"+ tag2 +"')";
return msg;
debug before conneting database:
Your mqtt messages arrive at different times. You will need to join the mqtt messages, use a join node and join manually as key/value object using msg.topic as key, Set the count to 2.