Convert

49 views
Skip to first unread message

adisti...@gmail.com

unread,
Apr 22, 2017, 6:01:40 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. Can anyone help me? It is really appreciated. Thank you.

Ixora

Julian Knight

unread,
Apr 22, 2017, 12:13:32 PM4/22/17
to Node-RED
What kind of data is in that array? characters? a buffer?


On Saturday, 22 April 2017 11:01:40 UTC+1, adisti...@gmail.com wrote:

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:

data: array[5]

adisti...@gmail.com

unread,
Apr 25, 2017, 9:40:30 AM4/25/17
to Node-RED
Hi,
It kinds of characters but I can't find the type of data. However, someone in this group told me to change it to buffer first before converting it, and it works fine. Thank you very much.

Neil Cherry

unread,
Apr 30, 2017, 9:20:26 AM4/30/17
to Node-RED
This one looks pretty easy. I'm used to thinking in C so the array would contain 5, 8 bit values which is an ASCII string ( yes I can read ASCII in hex and decimal formats ;-) ). I did a quick search and found this on Stack Exchange:


// You already have d.data[5] so ..
var i, str = '';

for(i = 0; i < d.data.length; i++) {
    str += '%' + ('0'+ d.data[i].toString(16)).slice(-2);
}

var nstr = decodeURIComponent(str);

There's probably an easier way but this was a quick search.

Reply all
Reply to author
Forward
0 new messages