node-red-contrib-coap
node-red-contrib-coap copied to clipboard
Response payload option for "undefined" content
Is it possible to add an option for undefined content in the response? For my specific use I needed to send an unencoded payload back but the Coap Response node doesn't allow for that.
if (_checkContentFormat(contentFormat, "text/plain")) {
return msg.payload.toString();
} else if (_checkContentFormat(contentFormat, "json")) {
return JSON.stringify(msg.payload);
} else if (_checkContentFormat(contentFormat, "cbor")) {
return cbor.encode(msg.payload);
} else {
return msg.payload.toString();
To get my flow working I changed "text/plain" toreturn.msg.payload;
but a better solution would be to have one more option for contentFormat, "undefined" with a return of msg.payload;
Thank you for reporting this issue! Having another look into the underlying node-coap, it seems to me as if the .toString()
call in the "else" case might be a bit redundant/unnecessary anyway. Maybe that could already be the fix here?
Is the return msg.payload tied to the type of content you select in the coap-response node? For the device I'm working with the payload must not be formatted so I'm not sure if "text/plain" should be just msg.payload or if there should be another option for "raw-buffer"?
Is the returned payload type determined by the list in the drop down Content-Format menu?
I may try editing the code to add this option...