Adding multiple MQTT data to one function node

Hi! I am new to the Forum.
I am creating an IoT app which register certain data into a database from an smart rollator. I have 4 sensors in 4 different topics. I want all of the data to be inserted simultaneously in the database, so I am joining all the mqtt outputs into a function node with the INSERT INTO chart (xxxx) VALUES (a,b,c,.....) inside. My problem is that I don´t know how to give each MQTT output data a different name (a, b, c) so I can do it. All outputs are are called with the same object name: msg.

I am attaching a screenshot of the flow:

I am pretty sure it must be pretty easy but my knowledge in Javascript its non-existing ( I only know C++ ).

Any help would be really useful! Thanks in advance :slight_smile:

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

This video describes it very well too.

once you have all the data in a single msg object, you can use a template node or a function to generate the SQL statement.

Thanks Steve!

And how can I access to each part of the new object created in the function node? The object is:
duda2

I tried msg.payload.ID/Fuerza/Izq but it does not work.

good stuff, you made it this far :slight_smile:

That video was one of about 18 short videos which are really worth watching - you will get a whole bunch of good tips.

If you view the 8th video, at about the 1:10 mark, you will see where Nick hovers over the debug message and copies the path to an item.

that is essentially what you need to do to get the path to the value.

Have a watch (its like mins long or something)

this article is also helpfull on the same subject

Great thanks!
I see there is a lot of information but sometimes its hard to get exactly what you want. I will watch them.

I forgot to say - you have to use the JavaScript property accessor feature called "bracket notation"
so this example would be msg.payload["ID/Fuerza/Izq"]

but watch the video - it will save you having to remember the above info!

Sometimes the blocker is not knowing what things are called (object / property, array / element, etc) - get them straight and you're half way there.

Thanks!

Sure will :wink:

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