MQTT data synchronization

Hello everyone!
I have a question: how can I synchronize the data of various sensors with mqtt?
Imagine this scenario: 15 temperature sensors distributed in my home, which detect temperatures every 15 minutes.
sensor # 01: 08:00:00 -> 20 degrees
sensor # 02: 08:10:23 -> 21 degrees (...)
sensor # 15: 08:14:55 -> 23 degrees.
Is there a way to start acquisitions at about the same time?
sensor # 01: 08:00:00 -> 20 degrees
sensor # 02: 08:00:10 -> 21 degrees (...)
sensor # 15: 08:00:50 -> 23 degrees.

How are you triggering the acquisition at the moment?

Node Red is waiting for incoming packets from sensors ("build" using Wemos & Tasmota, with teleperiod = 600)

var dbTHP = {};
var command = msg.topic.split("/")[0];
var group = msg.topic.split("/")[1];
var topic = msg.topic.split("/")[2];
var section = msg.topic.split("/")[3];
var tmpChip = "BME280";
var offline = 0;
var tpcErr = false;

switch(topic) {
case 'thp01': dbTHP.tpn = 1; dbTHP.tpc = "MTE"; dbTHP.flr = "MT"; break; // Meteo
case 'thp02': dbTHP.tpn = 2; dbTHP.tpc = "CLD"; dbTHP.flr = "TV"; tmpChip = "SI7021"; break; // Caldaia
(...)
case 'thp14': dbTHP.tpn =14; dbTHP.tpc = "LAB"; dbTHP.flr = "MN"; break; // Laboratorio
default : dbTHP.tpn = 0; dbTHP.tpc = "UNK"; dbTHP.flr = "!!"; tpcErr = true; // Errore!
}

node.warn("[THP] TPC:"+topic+" -> "+dbTHP.tpc+" FLR:"+dbTHP.flr+" GRP:"+group+" - CMD:"+command+" SCT:"+section);

if (tpcErr) {
node.error("[TOPIC] ERROR "+tpc+" NOT IN LIST!");
return [ null, null ];
}

OK, so to rephrase the question: "How do I tell Tasmota/Wemos devices to synchronise their sampling and data transmission?". That isn't a node red question. Someone here may be able to help but you might be better to ask on the sonoff/Tasmota mailing list. I can give you a link for that if you can't find it, when I am at my computer.

thank you!
I apologize for the "out of topic" request.

LR

You could rewrite your code so that the sensors subscribe to a MQTT topic. Every 15 mins you could then publish a message, which the sensors then respond to by publishing their data.

I'd just adjust sensors to publish every 60 secs instead of every 600 rather that try to get them to sync up

As @cymplecy suggests you could use a sledgehammer approach in node-red by setting the period in the devices to, for example, 10 secs, then in node-red feed them all into a Join node set to combine the payloads into key/value pairs, then have an inject node which, every 15 mins, sends msg.complete to the Join node. It will then, every 15 mins, send a message with all the values in it.

I would be interested to know why you need them synchronised, I have not found a need to do anything like that.

The Sonoff/Tasmota list is https://groups.google.com/forum/#!categories/sonoffusers

at the expense of battery life...

Presumably so if they are being battery driven. I didn't see any mention of that.

A properly designed temperature sensor would only send data on change and a heartbeat (eg xiaomi sensors).

Whats the reason you like to "synchronize" with mqtt?

One way to have all data at once, is to activate the retain flag for the msgs.

One way would be to store the sensor data in a context data variable thingy and then run a inject node on repeat at the intervals you want and use the context data value.

I think my join node suggestion would do that without the need for saving in context. Well it is saved in the Join node's context of course but you don't have to think about it yourself.

1 Like

A brief explanation ...

  1. perhaps it is not necessary to synchronize the temperature sensors, but the request arises from a more elementary necessity: "If I want to do this, how could I do it in the best way?"
  2. The "elementary" question is the consequence of a really basic knowledge of Node Red, which I have been using for a few months.

I try different ways, for example by asking the sensor status or by binding the data transmission only when a threshold is exceeded.
But the habit of working with a clock perhaps led me to the less correct solution.

... and a clarification ...

  1. Data are stored on Influxdb
  2. All sensors are powered by a dedicated 7 Volt line
  3. All sensors are home-made
  4. Many things are not clear to me yet, but I think you have understood it! :grinning:

Thanks for your help!
It was really appreciated!