Code function to collect data from mqtt

Hi folks,
I have 3 topics in MQTT. I want to use the data of these topics but I don't know how to write code in the function node. Can you suggest to me the code to declare variables in the function node.

If you want all 3 values together for sending to database, you need to use a join node.

See this article in the cookbook for an example of how to join messages into one object.

Once you have the values together, you can then start focusing on the database part.

When you come back, be sure to mention the database type, what nodes you are using and what you have tried so far.

1 Like

I want to declare variables to use each variable to put it to next program in function node

for example to declare variables like
var temperature = <>;
I don't know how to arrange topic and the payload in the code

There is a great page in the docs that will explain how to use the debug panel to find the right path to any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

https://nodered.org/docs/user-guide/messages

Also if you are a beginner with node red then I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot in about 1 hour. A small investment for a lot of gain.

1 Like