Search code examples
node-red

Node-Red: Parsing JSON data and converting it into binary.


Right off the bat, I'm a total noob so any help would be greatly appreciated.

Here is a breakdown of my issue, here are the nodes as seen on my screenshot:

INJECT- Self explanitory

NAME- return{payload:"=00ECC90AG001XQ01" };

HTTP request get point- msg.url = "http://192.168.63/get_points/"+msg.payload msg.method = "GET"; return msg;

http request- Set to GET.

JSONpath- $.points[0].st This is setup to parse the JSON located at http://192.168.63/get_points/=00ECC90AG001XQ01.

The output I get form this is 458886.

I would like to convert this number to Binary. Then I would like to parse out the -7 digit from that Binary.

I tried using the Binary node (the one disconnected on the screenshot), which is for converting inputs to Binary. I could not get passed the "Pattern" requirement.Layout


Solution

  • The binary node is probably not the node you are looking for, it's more for building/parsing complex binary structures.

    The simpler way to do this will be a function node with something like the following:

    var binary = msg.payload.toString(2);
    // 6 because it's zero based count
    var bit7 = binary.charAt(6);
    msg.payload = bit7;
    return msg;
    

    This will find the 7th char from the left