Add new entry on msg

I think is a stupid error but this flow does not work. I've already used this function but now, in this example, it does not do the job.

[{"id":"266afe29.6f9e82","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"bdbdb8e2.66f7d8","type":"inject","z":"266afe29.6f9e82","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":120,"wires":[["e961c946.c39c6"]]},{"id":"e961c946.c39c6","type":"function","z":"266afe29.6f9e82","name":"Add data","func":"msg.payload[\"measure\"] = 123;\nmsg.payload[\"hex\"] =  \"0x\";\nmsg.payload[\"empty\"] = {};\n\nreturn msg;","outputs":1,"noerr":0,"x":370,"y":120,"wires":[["ed667d93.b8f6f8"]]},{"id":"ed667d93.b8f6f8","type":"debug","z":"266afe29.6f9e82","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":520,"y":120,"wires":[]}]

Where is my mistake?

Thanks

In the inject node, you've added the default payload which is a timestamp (long integer).

In your function node, you tried to treat that as an object to add properties too.

You can add msg.payload = {} at the top of your function or change the inject node to make the payload a json object.

This isn't a stupid mistake but is a common beginners mistake and one that I still make from timet-to-time even after all these years. :smile:

2 Likes

Thank you for a quick reply, it's a clear explanation.

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