Convert buffer to string using core nodes

Following last years string - > buffer thread :slight_smile:
https://discourse.nodered.org/t/convert-string-to-buffer/60755/12

This year I wanted the other way so this is what I've done
Split payload

and join back again

2 Likes

Hi, I'm trying to do the same thing with NR 4.0.2 :

image
one of the payloads at the exit of the SPLIT node

I see that the JOIN node is different:
I have to check this box otherwise I have no payload:

So I do have a string payload at the end of JOIN node, but not as I would like: I'm waiting for "81733B0D....FF" instead I have this:

image
there is a transformation in ASCII (probably ?) that I can't understand why?

Your data looks to be byte pairs of ascii with some odd chars up front.

Where are you getting the data from?

The buffer-parser nodes can do this without resorting to splits and joins (or you can use a function node - but the difficulty of that depends on the data format, byte-swapping etc)

If you want further help, paste a copy of the raw buffer data and tell me what is SHOULD be when represented as a string.

the data comes from an iot device which sends via MQTT a buffer frame of bytes which I must assemble then separate according to a protocol.

yes that's exactly what I want to do with your "Buffer-parser"node :

Yes, I can also do it in a Function node (my javascript basics are starting to be good thanks to your help :wink: )

But, here the idea was to take what @cymplecy proposed with core nodes WITHOUT having to use a node-red-contrib :
Example from a buffer : [0x79, 0x35, 0x32 ..., 0x33] To a string: "793532...33"

Fair enough & good luck making something in less than 5 minutes in less than 5 nodes that is performant, extensible, easy to understand and reusable in place of a node specifically designed for this purpose.

that's why the proposal of a split followed by a join node was cool.. but obviously doesn't give the expected result... too bad. I will pass through your buffer-parser node (or Function node).

external systems, passing binary or ascii data often require specialise conversion that requires specialist routines that strip out control characters, CRCs, do data type conversions etc. If this were a simple, single string, then you can use core nodes (inluding a single function and probably a change+jsonata) but in most real life cases, interfacing real devices that often encode multiple data element in multiple differing formats (often for good reason, often for no good reason) - you will need specialist nodes or custom programming.

1 Like