MQTT store in mysql

Hello Guys, I need help correct my code, i fail store data on mysql
this my flow:

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;

and this my error

Thanks Guys

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:

error code:

"Error: WARN_DATA_TRUNCATED: Data truncated for column 'L1_N_VOLTAGE' at row 1"

Fyi debug response data mqtt:

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.

Thank Guys this promblem solve

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