(Sort of following on from my other post/question)
What I know about MQTT
:
1 - basically the payload
is the only part of the message that is sent to the other end.
(that's about it)
If you want to send other stuff, you need to construct a special message where the payload
is not just text.
JSON node/s.
Way back when I first started (and this may be wrong) if you wanted to send fancy mesasges through MQTT
you would have to use a JSON
node going in and coming out of the MQTT
node. WAS (Past tense)
Seems now the newer version/s of the nodes have auto detect and so you don't need to use the JSON
nodes as before.
But I've just annoyed Sean (well: he helped me) with getting something that should be easy to work.
Given I have (example) a message like this:
{"payload":"2022-12-29 12:05:09 Main - Up"}
and
{"state":"Online"}
and I want BOTH of these to go through MQTT
. How do I do it?
Seems my old way works:
Put it into a function
node - code:
let msg2 = {};
msg2.payload = {"payload":msg.payload,"state":msg.state};
return msg2;
Then at the other end I get:
{"topic":"test","payload":{"payload":"2022-12-29 12:05:09 Main - Up","state":"Up"},"qos":0,"retain":false,"_topic":"test","_msgid":"d7f246aadb65e10b"}
But that isn't usable to me.
I want a payload
and state
. Not payload.payload
and payload.state
.
I seem to remember that the JSON
node was the answer. But it is no longer.
I have to basically do the opposite to what I did at the other end.
let msg2 = {};
msg2 = msg.payload;
return msg2;
And I guess: Fair enough.
But I can't believe that .... 4 years ago (nominal, maybe more) I got this right and BEFORE it was how to do it.
No: I'm not boasting. I'm confused.
Where's the elephant I'm missing?