Solved: Formatting message with subtopics for mqtt

I am trying to send a mqtt message where I have a subtopic but I am having no luck getting my message formatted correctly. The main topic contains identifiers and the subtopic will be an array with the name/values. My exact code has lots of private info but this is some sudo code of my message structures

payload = {
    Id1: "value"
    Id2: "value"
    Id3: "value"
    dimensions: {
        array[]
    }
}

I would like to be able access the values only on the mqtt message with main/dimensions. How do I need to reformat this so I can get that?

Hopefully you mean msg.payload = {, which is not what you have written.

I don't understand what you mean by that, can you explain in a bit more detail what you mean? In particular what does the word 'access' mean here. Do you mean subscribe? If so then you need to use the topic to identify that, not something in the payload.

Yes, sorry I meat subscribe. The mqtt publisher node sets the topic and that part is fine and I can subscribe to that. The problem is right now all my data has to go to that topic with no hierarchy...which is obviously not a very clean method of doing things.

If you different types of data then publish them to different topics.

That is not particularly useful because I need to know what that data belongs too. Across, for instance, 40 devices the concept or trying to organize that data into 40 different to level topics sounds rather terrible. I have another way I can do this but this seemed to be the easiest way to deploy at scale. However, maybe I misunderstanding what this means:

"Topics are treated as a hierarchy, using a slash (/) as a separator. This allows sensible arrangement of common themes to be created, much in the same way as a filesystem."

If you have multiple similar devices you can publish to main/dev1, main/dev2 for example. Then you can get them all by subscribing to main/# or you can subscribe to them individually if you prefer.
If you not already done so work through the hive mqtt essentials guides. Your search engine will find it.

1 Like

Ok I tried that and subscribing to main/# returns nothing but subscribing to main/dev1 or main/dev2 will return the expected data that was published to them. It is almost like it is just treating main/dev1 as a name. Might just go for a different addressing approach.
edit: I forgot the"#" silly mistake, no wildcard, no result Thanks, that got it!

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