B
B
Balkonsky2016-11-15 22:12:16
JavaScript
Balkonsky, 2016-11-15 22:12:16

How to collect information from multiple mqtt Node-Red nodes?

The existing scheme in Node-Red:
a330b5580b7b4240aa9f9248a4418b3e.png
the db_query function is described as follows and only populates the database with the values ​​of one node:

var newMsg = {payload : msg.payload};
newMsg.topic ="INSERT INTO `m2m`.`sens1` (`TEMP`) VALUES ("+newMsg.payload+")";
return newMsg;

Please tell me how to write data collection (collect_data function) from nodes into several variables to pass them to the db_query function and create one SQL INSERT query in the database.
The table in the database in which the data is entered:
select * from sens1;
+----+------+-------+-------+-----+---------------------+
| id | TEMP | HUMID | PRESS | AIR | date                |
+----+------+-------+-------+-----+---------------------+
|  1 | 41.2 |     0 |     0 |   0 | 2016-11-15 22:08:54 |
+----+------+-------+-------+-----+---------------------+
1 row in set (0.00 sec)

Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
ratatyq, 2017-06-28
@ratatyq

As an option, use the global node-red space, that is, use either global.get/set or flow.get/set
nodered.org/docs/writing-functions (find the Flow context subheading)
You can put readings from these mqqt into this global variable blocks and do a check for filling them, as soon as they are filled, make an entry in the database and reset this global variable and everything will start over again.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question