Node-RED running on Multitech Conduit

218 views
Skip to first unread message

Akshay Bhavsar

unread,
Feb 9, 2017, 1:01:45 AM2/9/17
to Node-RED
Hi there,

I have got payload as follow.

000254fdbd805308a088e5 

I need to slice it and take particular part from it and then need to convert it into signed decimal number. How can I do that ?

I have tried as follow, but it is failing at parseFloat function, it doesn't give me any data even I tried parseInt function as well, but it also doesn't work.


data = ((msg.payload).slice((msg.payload.length)-8,(msg.payload.length)-4)) ;  // this return "fdbd8053" from payload mentioned above

var val = parseFloat(longitude,32);  

return val;


Another issue is that instead of using slice command to extract the data I decided to use hardcore value just to check parseFloat command. I did it as follow.
 
data = 0xfdbd8053 ;

var val = parseFloat(longitude,32);  

return val;

This is returning a decimal value of 4257054879, which unsigned. I need it signed conversion. The value should come as -37912417. 

How can I solve this two problems.

Your help will be great !!

Thanks
Akshay

Mark Setrem

unread,
Feb 9, 2017, 6:45:29 AM2/9/17
to Node-RED


Your first line doesn't return what you think it returns.  You are only slicing 4 characters (8 from the end to 4 from the end) so it will return "08a0"
Your next line then uses a different variable for the parseFloat longitude rather than data
You then return a variable where it is good practice in node-red to return an object ( generally msg with the useful bit being in the property payload)

Perhaps you can fix the issues with your examples and repost?

It is also useful if the title you give your post describes the issue you are having, rather than the machine you are running node-red on.
Imagine if every other post was titled "Node-red running on a RaspberryPi" :-)


Lawrence Griffiths

unread,
Feb 9, 2017, 11:50:34 AM2/9/17
to Node-RED
Akshay I use MT Conduit and process LoRa msg as a node buffer e.g.
var rBuf = new Buffer(msg.payload,'hex')
You can then use Most of nodejs buffer functions

data = "fdbd8053";
var rBuf = new Buffer(data,'hex');
msg.payload = "long:"+rBuf.readInt32BE(0);

From a quick test it get's round your sign issue and if you need unsigned .readUInt32BE()

Lawrence

Akshay Bhavsar

unread,
Feb 9, 2017, 6:07:57 PM2/9/17
to Node-RED
Thanks Lawrence,

It is working. appreciated your help.
Thanks man.
Reply all
Reply to author
Forward
0 new messages