Converting bit string to multiple boolean device attributes

function-node
binary
#1

I was able to convert a integer to a integer string such as 1001010.
Now I want each of those binary positions to translate to individual boolean bit values to use as device attributes.
Any suggestions?

0 Likes

#2

I think the string node seems to be a good start

0 Likes

#3

I found this on Stack Overflow that could be helpful for you. You should be able to do something like this in the Function Node.

var bitString = 1001010;
var arrayOfDigitsAsStrings = bitString.toString().split('');
var arrayOfDigits = arrayOfDigitsAsStrings.map(Number)
console.log(arrayOfDigits); // [1, 0, 0, 1, 0, 1, 0]

Then, you can put that value back on the payload in the Function Node using:

payload.arrayOfDigits = arrayOfDigits

After that, you can use the Device State Node to report your values.

0 Likes