node-red-contrib-coap icon indicating copy to clipboard operation
node-red-contrib-coap copied to clipboard

Response payload option for "undefined" content

Open JohnnyPicnic opened this issue 1 year ago • 3 comments

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;

JohnnyPicnic avatar May 25 '23 13:05 JohnnyPicnic

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?

JKRhb avatar May 29 '23 15:05 JKRhb

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"?

JohnnyPicnic avatar May 29 '23 15:05 JohnnyPicnic

Is the returned payload type determined by the list in the drop down Content-Format menu? image

I may try editing the code to add this option...

JohnnyPicnic avatar Jun 28 '23 12:06 JohnnyPicnic