Questionmark in red diamond

This one I can't find a solution for, so if someone could send me in the right direction.

I have this "test" flow, that send a message as buffer, that one gives me red diamond with question mark.
If I receive as sting via funtion node "msg.payload = msg.payload.toString();" I get does wrong.
But if received directly to debug node, i see the buffer numbers with raw, and when i click i see the text correctly.

I know that is some thing with coding UTF-8 etc. but can't find the way.

image

[{"id":"b6998e3a1546c93c","type":"debug","z":"7f4d18d1b36d451f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1410,"y":600,"wires":[]},{"id":"9200dc257b4ec2ba","type":"function","z":"7f4d18d1b36d451f","name":"Buffer to String","func":"msg.payload = msg.payload.toString();\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1240,"y":600,"wires":[["b6998e3a1546c93c"]]},{"id":"0af5e5f9eb1b43cd","type":"debug","z":"7f4d18d1b36d451f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1230,"y":640,"wires":[]},{"id":"502b7419641df689","type":"inject","z":"7f4d18d1b36d451f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[171,116,101,115,116,187]","payloadType":"bin","x":1010,"y":620,"wires":[["0af5e5f9eb1b43cd","9200dc257b4ec2ba"]]}]

The character is unprintable in the default encoding of toString(), try encoding "ascii" . You can also pass start and end position to toString().
eg

[{"id":"502b7419641df689","type":"inject","z":"bf9e1e33.030598","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[171,116,101,115,116,187]","payloadType":"bin","x":130,"y":140,"wires":[["9200dc257b4ec2ba","1a2ba019.3831f"]]},{"id":"9200dc257b4ec2ba","type":"function","z":"bf9e1e33.030598","name":"Buffer to String","func":"msg.payload = msg.payload.toString(\"ascii\");\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":360,"y":120,"wires":[["b6998e3a1546c93c"]]},{"id":"1a2ba019.3831f","type":"function","z":"bf9e1e33.030598","name":"Buffer to String","func":"msg.payload = msg.payload.toString(\"ascii\",1,msg.payload.length-1);\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":310,"y":180,"wires":[["b6998e3a1546c93c"]]},{"id":"b6998e3a1546c93c","type":"debug","z":"bf9e1e33.030598","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":120,"wires":[]}]

Could not use your example, but figured it out myself, maybe not the right solution - but it works.

[{"id":"1d93606f948378fc","type":"inject","z":"7f4d18d1b36d451f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[78,52,48,49,100,48,115,171,84,101,115,116,32,116,101,115,116,187]","payloadType":"bin","x":970,"y":560,"wires":[["9200dc257b4ec2ba"]]},{"id":"b6998e3a1546c93c","type":"debug","z":"7f4d18d1b36d451f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1570,"y":580,"wires":[]},{"id":"9200dc257b4ec2ba","type":"function","z":"7f4d18d1b36d451f","name":"Buffer to String","func":"//msg.payload = msg.payload.toString();\nnum = {payload: Buffer.from(msg.payload).toString('hex')};\n\nvar num = num.payload;\nnode.warn(num);\n\nreturn {payload: new Buffer(num, \"hex\")};\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1180,"y":580,"wires":[["6a61da8deefc76a9"]]},{"id":"0af5e5f9eb1b43cd","type":"debug","z":"7f4d18d1b36d451f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":640,"wires":[]},{"id":"502b7419641df689","type":"inject","z":"7f4d18d1b36d451f","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[171,116,101,115,116,187]","payloadType":"bin","x":970,"y":600,"wires":[["0af5e5f9eb1b43cd","9200dc257b4ec2ba"]]},{"id":"6a61da8deefc76a9","type":"converter","z":"7f4d18d1b36d451f","name":"","from":"ISO-8859-16","x":1380,"y":580,"wires":[["b6998e3a1546c93c","b4ab20a1a404a890"]]}]

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.