This is most likely a stupid question, but I have a number of devices, identical in all but name which receive input from injects and from MQTT input. Is it possible to use, say, flow variables for topics in these two, rather than fixed strings?
I don't believe so, no.
What I do is make sure that all similar data uses a parent topic. So perhaps all the data from physical devices uses
DEVICES/<deviceid> for example. Then I can simply listen for
DEVICES/+ and get all of the direct descendent data on that master topic. I can then sort out different paths for different devices in Node-RED. You could go another layer deep if, for example, you needed to split by device hub and then by id.
Does that make sense?
Devices/# I think.
It would make sense but for the way I use my topics - devicex/fromesp - and on mqtt outputs I send topic devicex/toesp
Do I don't have a way to use descendent data/
That will give you a full path so you need to take care with that.
DEVICE/# would give you
would only give you
Sometimes quite useful.
I think you can set the mqtt topic string as an ENV variable... so the same flow could run on multiple servers setup with different environments.
But if you need to listen for different device topics within a single node-red instance, use the wildcard topic string
# and then use a
switch node to route to named devices.
Sorry, I can't think of another way.
Exactly, you said "listen for
DEVICES/+ and get all of the direct descendent data on that master topic" which is what the
DEVICE/thing1/something is a direct descendent of
DEVICE isn't it? Though perhaps by 'direct' you meant only one level, which I suppose it could mean, perhaps you are right. Anyway the important thing is that the operation has been clarified.
Urm, no, that's an indirect descendent. Sorry for not being clear.
I don't think so. In family relationships I believe an indirect descendant would be via a cousin or marriage or similar
Haha, I bow to your superior search skills
Well, hopefully everyone now understands what I meant anyway.