First time working with MQTT and I'm excited how easy it was to setup the broker and configure 2 Clients in Node-Red to connect.
First a general question: Is it possible to send more than the "payload" via MQTT e.g. an additional Header?
In my case I receive an HTTP Call with a payload , which I send to the MQTT Broker. But I also need one of the objects from msg.res.xxx.xxx (doesn't really matter) to be send in the same call to the broker.
I tried to just add the field to the payload via a function node, but on the subscribed client side just the "original" payload is received.
Function node:
var payload=msg.payload; //get payload
var parsedUrl=msg.req._parsedUrl.search;
msg.payload.parsedUrl=parsedUrl;
return msg;
It seems that I can't change the payload due to the format? As changing the topic or adding another field is working fine.
So rephrasing my question a little bit:
Can I add an additional object send via MQTT. Something like "msg.header" or "msg.payload2"
Or how to change the payload format? Trying to convert it to JSON String gives me the error "Ignored non-object payload"
MQTT messages are generally a string sent to a specific topic. But you can send a json formatted object via mqtt and encode or decode it with the help of the json node.
Or you can do the same thing in a Change node.
However, I don't see msg.req._parsedURL.search in your debug output, are you sure you don't mean msg.req.url?