Node-red Convert Hex number into signed floating number

Home Forums General Node-red Convert Hex number into signed floating number

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #16799
    Akshay Bhavsar
    Participant

    Hi there,

    How can I convert Hex number into signed floating number in node-RED ?
    I have tried parseInt(a,16), but it doesn’t work.

    Thanks

    #16807
    Peter Ferland
    Blocked

    That should work. Are you using a LoRa input node? If so, go to the node’s configuration and confirm that it is in byte mode and not UTF-8 mode.

    #16826
    Akshay Bhavsar
    Participant

    It is in byte mode, but doesn’t give me any data. Is there any alternative ?

    #16827
    Peter Ferland
    Blocked

    Can you post the node red flow?

    #16829
    Akshay Bhavsar
    Participant

    Here is the flow

    var longitude= ((msg.payload).slice((msg.payload.length)-4,msg.payload.length));
    longitude = parseInt(longitude,16);
    return longitude;

    https://drive.google.com/open?id=0B8vP1Z3v0Sw8NHpvZ2ZlUGZVOXM

    #16834
    Peter Ferland
    Blocked

    Ok, can you post the output of a debug node on output of the LoRa node?

    #16835
    Akshay Bhavsar
    Participant

    The output of debug node, without the function is as follow

    00820dfdbd803008a08856

    I want to slice 4 hex number at the end and convert it into decimal.
    I just found that slice doesn’t written data type in hex. If I just assign hard value of hex number as
    var a = 0xfb5216ff

    It does convert into number by using parseInt command.

    #16843
    Akshay Bhavsar
    Participant

    Hi Peter,

    Have you find anything ?

    Thanks
    Akshay

    #17145
    Akshay Bhavsar
    Participant

    Hi there,

    I have solved this by using following command.

    var battery = ((msg.payload).slice((msg.payload.length)-9,(msg.payload.length)-8));
    var rBuf_battery = new Buffer(battery,'hex');
    var battery_val = (rBuf_battery.readInt8(0));

    readInt8(0) function can be readUInt8(0) for unsigned number. Also depending the length of hex number this function can also be write as readInt16(0) and readInt32(0).

    Thanks

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.