How can I convert char code numbers to string characters?

Hi,

How can compare two input values and change output accordingly on dashboard. please help me.
or
combine all values and change into ASCII character.

Thanks.

Br,
Devendra

You are going to have to be a bit more specific if you want an answer.

Are the values in the same message?
What do you mean by “combine all values and change into ASCII character.”?

Hello,

Are the values in the same message? - yes,

RFID values received in dashboard in byte format & i want to change into ASCII characters of a same value & show in a same row or line continue.

ex. 7273768367726982 convert into ASCII character as HILSCHER text

What i am getting see below screen shot.

image

How? Are you typing them in or are they already in Node-RED? You must be able to see them in a debug node (displayed in the debug panel)

Values coming from RFID tag, what i already write in RFID tag as HILSCHER ascii character. i am able to see the values in debug panel.

So you said

One message is : image

so this value want to show on dashboard as ASCII Character.

Take a look at the JavaScript functions for this:
String.fromCharCode does what you’re looking for: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/fromCharCode
<string>.charCodeAt does exactly the reverse: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt

Next I would look at pushing those messages together, get those characters in an array and do a join before displaying.

Hi

thanks, i am able made a string of RFID receiving data or value & showing on dashboard, but still output is not in ASCII character, could you please provide me code or node setting to convert decimal value as 7273768367726982 to ASCII character as a HILSCHER.

complete data string
image

when i remove tag from RFID device it is showing only updated 2 values (1335) not showing complete string.

image

The post from @afelix showed you the javascript command to use.
So how have you configured your function node to do this?

If you show us your code we can guide you so that you learn to do it correctly rather than just giving you the answer.

Post your function code here...

Hi.

Just as @ukmoose and @afelix said, but in demo code instead...
jsbin.com/tiyilolapo/edit?js,console
.. That should put you on the right track

EDIT...
I updated the title do be more descriptive of your question - for future users searching this & to help those who know how to do this to understand the topic before diving in

I am getting the same value.

Please look on my node red flow. what need to change.

[{"id":"7701343f.56242c","type":"debug","z":"2dd4e6c8.10259a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":480,"y":260,"wires":}]

Unfortunately your flow isn't currently importable.Please read the following post How to share code or flow json and then edit the above message.

Actually you have only exported your debug node, which isn't of use. Just copy and paste the function nodes contents (and format them as per the above link)

sorry,

[{"id":"2e6efd07.1f3ad2","type":"inject","z":"2dd4e6c8.10259a","name":"","topic":"","payload":"72","payloadType":"num","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":140,"wires":[["e314b0b.31a2b5"]]},{"id":"7701343f.56242c","type":"debug","z":"2dd4e6c8.10259a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":480,"y":260,"wires":[]},{"id":"e314b0b.31a2b5","type":"function","z":"2dd4e6c8.10259a","name":"ASCII","func":"\nconsole.log(String.fromCharCode(72))\n\nreturn msg;\n","outputs":1,"noerr":0,"x":320,"y":180,"wires":[["7701343f.56242c"]]}]

So your function node contains the following

console.log(String.fromCharCode(72))

This isn't taking the value from your inject node, and won't pass the results on to your debug node.

I think its probably worth taking sometime to read the introduction flows.
https://nodered.org/docs/tutorials/
Which will take you through the basics of how to program in Node-RED.

You need to modify something in the msg object, and to store the result in the msg object.

1 Like

change
console.log(String.fromCharCode(72))
to
node.warn(String.fromCharCode(72))
to see it in the debug tab

Surely he just needs...

msg.payload = String.fromCharCode(msg.payload);
return msg;

@DSongra11_forum.com you need to understand a few fundamentals about node red.

  • Each node passes a msg through the wires to connected nodes.
  • in order for you to see what happened to the msg on-route, add debug nodes
  • console.log (normally) logs to your browsers console (i.e. F12 Dev Tools, not the debug side-bar). Node-red Function nodes run on the server (inside node-red - not in your browser). Therefore console.log() wont appear in the browser console nor the debug side-bar - for that, use node.warn("my warning text to appear in the debug side-bar") as demonstrated by @zenofmud )

This topic is a must for people new to node red - Working with messages : Node-RED

With that in mind...

  • your inject will pass 72 in msg.payload to the function node
  • the function node will be able to do something with msg.payload and pass it on to the next node (debug node in this case)
  • the debug node shows you what is now inside the msg.

I am a new on node red. but i did what i want to do on dashboard. Thank you so much.

image