Scenario

I wish to deploy sensor nodes that publish sensor data to a central MQTT Broker and then send this information to InfluxDB.

Requirements

Adding metadata to the Sensor nodes whilst publishing information to the broker. This requirement comes in lieu as the sensor nodes will be deployed in specific rooms and these information needs to be saved in the InfluxDB as tags which can help me for post processing. Scenario simplified as below. Scenario

Metadata

Example:

 measurement: sensors
 type: temperature, humidity
 location: GATEA

This metadata can be used as a query as follows:

  SELECT * FROM "sensors" WHERE "type"='humidity' AND "location"='GATEA' LIMIT 100

The above mentioned query provides me all humidity sensor values coming from GateA.

Question

How does one add such metadata when publishing information with standard MQTT?

Initial Understanding suggests:

  1. I make topics based on Gates where each sensor nodes publish information to specific gate topic like GATEA, GATEB etc. I am not sure if this makes sense as then the InfluxDB might take the topic as a measurement and the query might look like:

      SELECT * FROM "GATEA" LIMIT 100
    

    however this does not address the type tag that could be pushed as metadata.

  2. Vice versa would be topic creation based on type of sensors e.g. temp, humidity for each sensor nodes

Is there any standard practice or architecture design advice for MQTT deployment in such scenarios? Or any advice as to what path should be selected in the context of this scenario?

References

MQTT, Docker, Grafana, InfluxDB, ESP32 Blog Post is a great blog post which I would like to start as a base point for such a setup

  • Topics should not start with a leading /, while allowed in the spec it breaks things like shared subscriptions so better to just never do it. – hardillb Nov 21 at 10:46
  • Let me correct it in order to avoid misscommunication. I meant them as they were in text GATEA, GATEB etc. – Shan-Desai Nov 21 at 10:51

With MQTT version 3.x there is nowhere to include any meta data except in the message payload it's self. This means the sensors will need to build this in before they publish the message.

You can encode some information in the topic and this makes sense for certain things, e.g. having each sensor publish on their own topic and subscribe to wild cards. Topics are hierarchical for this reason e.g.

country/city/building/floor/sensor1/temperature
country/city/building/floor/sensor1/humidity

MQTT v5 (the new version of the spec 2017/18) spec supports user properties for each message as well as the payload which will probably be useful for including extra meta data as more things come to support it.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.