Mysql, mariadb INSERT fail - "msg.payload should be an object containing the query arguments."

I try insert data do mysql, but give this error : "msg.payload should be an object containing the query arguments."
If I inject manual ; INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061) - works good

11/07/2020, 17:59:12node: 645b9468.b3369cwhite21_pzem004_fixo : msg : Object
object
topic: "white21_pzem004_fixo"
payload: "INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061)"
qos: 0
retain: false
_topic: "white21_pzem004_fixo"
_msgid: "e22112b1.1c175"

11/07/2020, 17:59:12node: c4c94992.70def8msg : string[63]
"msg.payload should be an object containing the query arguments."

11/07/2020, 17:59:12node: 9df8fbb.7d5b708INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061) : msg : Object
object
topic: "INSERT INTO consumo ( data, hora, voltagem, corrente, potencia, pf, kwh ) VALUES ('2020-07-11', '17:59:13', 235.3, 1.42, 292.0, 0.87, 180061)"
qos: 0
retain: false
_topic: "white21_pzem004_fixo"
_msgid: "e22112b1.1c175"

Flow:

[{"id":"e71cac20.dd98f","type":"Stackhero-MySQL","z":"23f837d8.44d508","server":"59f71098.17a99","name":"","x":690,"y":180,"wires":[[]]},{"id":"903152e1.51393","type":"debug","z":"23f837d8.44d508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":670,"y":240,"wires":[]},{"id":"73571c09.825bd4","type":"mqtt in","z":"23f837d8.44d508","name":"","topic":"white21_pzem004_fixo","qos":"0","datatype":"auto","broker":"a1dff73d.4ba558","x":160,"y":100,"wires":[["6556610c.fb663","3fc9fa54.514e96"]]},{"id":"6556610c.fb663","type":"debug","z":"23f837d8.44d508","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":500,"y":100,"wires":[]},{"id":"3fc9fa54.514e96","type":"change","z":"23f837d8.44d508","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":350,"y":220,"wires":[["e71cac20.dd98f","903152e1.51393"]]},{"id":"59f71098.17a99","type":"Stackhero-MySQL-Server","z":"","name":"","host":"127.0.0.1","port":"3306","tls":false,"database":"pzem_movel"},{"id":"a1dff73d.4ba558","type":"mqtt-broker","z":"","name":"","broker":"127.0.0.1","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

What I'm doing wrong, can someone help.
Thanks.

Put a debug node (set to display the complete msg.object) on the output of your mqtt-in node.
You could also try changing the change node to `set' msg.topic to msg.payload

The move - in the change node does that, it moves msg.payload to msg.topic so msg.payload no longer exists. Maybe ther node can't handle msg.payload being empty.

UPDATE: I just tested and if msg.payload is empty, the node throws an error - I'll open an issue on the node.

so changing the change node should fix the error

Issue on GitHub: https://github.com/stackhero-io/node-red-contrib-stackhero-mysql/issues/1

1 Like

Thanks for your help.
I replaced Stackhero Mysql with mysql node and works fine.

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