Insert a mqtt tree ( directories? )

hello ,

i'm learning nodered and mqtt.
i use also homeassistant , and when i create an esp32node with mqtt enabled , then i got a very nice tree-structure in mqtt-explorer

now i want to create some data to send to my mqtt broker , but as test i want to inject some hardcoded values to my broker.
but it need to have a nice tree-strucure like in this image above.

my first test is complete differtent result in mqtt-explorer :

how can i create a kind of directory and subdirectorries ?

The 'tree' structure is just the parts of the topic in the msg being published. The topic. is broken into levels with a slash /.

You should spend some time and read thru this tutorial MQTT Essentials - All Core Concepts explained

is there no easy flow to generate a mqtt wit a 'directory structure with values ' with 1inject node ?

It is very easy to create a topic in a msg with various levels for example setting msg.topic to:


but really you should go read the tutorial, it examines a lot and has a complete section on topics and hoe to subscribe to them. It will be worth your time to learn the terminology and get an understanding of how the pub/sub process works.

I like to reproduce internal JSON structures to equivalent trees in MQTT. The best way is to create a function node that walks through the JSON input and outputs the topic/value pairs. Done right, you only need to do it once and then you should be able to reuse it.

I guess I should probably write a node for that at some point unless someone has beaten me to it.

As a matter of interest, why do you want to do this? Under what circumstances?

i want to send a simple hardcode big mqtt structure , so i can test my recievers and other flows.

just a matter to inject something to "debug/unit tes"t my recieving flows

OK, good reason. In a function node you can do something like

node.send({topic: "a/b/c1", payload: "somevalue"})
node.send({topic: "a/b/c2", payload: "someothervalue"})

thank u Colin

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