Convert ASCII/Hex to Decimal Number

1,816 views
Skip to first unread message

adisti...@gmail.com

unread,
Apr 22, 2017, 6:04:30 AM4/22/17
to Node-RED

Hi everyone,

I need your help because I am new to Node-RED. I tried to send data from BME to cloud with smart mesh. In the node RED, I received a message that looks like this:

4‎/‎21‎/‎2017 2‎:‎46‎:‎45 PMnode: mote events/responsesiot-2/type/mote/id/00-17-0d-00-00-58-f2-6c/evt/notifData/fmt/json : msg.payload : Object

 

{ d: object }object

d
: object

utcSecs
: 1029561249

utcUsecs
: 536750

macAddress
: "00-17-0d-00-00-58-f2-6c"

srcPort
: 60000

dstPort
: 60000

data
: array[5]

0: 50

1: 53

2: 46

3: 52

4: 51


I need the array of data to be converted to temperature, in this case it’s 25.43. I tried to convert it to decimal, but failed several times. Oh, the array of data looks like ASCII, but it will be converted to Hex if I clicked the number. Can anyone help me? It is really appreciated. Thank you.

Ixora

Dave C-J

unread,
Apr 22, 2017, 8:27:58 AM4/22/17
to node...@googlegroups.com
Hi,
the data array is of ascii like characters so the easiest way to convert it is to make that into a buffer then convert that to a number...

so a function with something like

msg.payload.data = Number(new Buffer(msg.payload.data));
return msg;

should replace the existing data with a number. Of course you can rename the property if you like/need to.

adisti...@gmail.com

unread,
Apr 25, 2017, 9:38:13 AM4/25/17
to Node-RED
Hi,
Thank you for the fast reply. And it works perfectly fine! Thank you very much..
Thumbs up!
Reply all
Reply to author
Forward
0 new messages