Unable to decode the data with JavaScript codec


#21

No need to convert into integer. Simply convert the base64 into text… search for some library that converts base64(decoded) to text…


#22

Please don’t create additional topics for this, this is the right topic to discuss this issue.


#23

That was the reason that i asked @brocaar…any tip about?


#24

When I return this object:{"byte_array":bytes} It outputs as the base64 encoded string when I look at the “live device data” in the app server. Am I somehow not grabbing the base64 decoded array instead of the encoded string?

When I try and do something like byte_array=bytes[0] I get an error when trying to take index 0 of ‘undefined’


#25

Potentially a device could send no data on a fPort > 0. In that case, make sure to first check bytes is non undefined or null, before further processing it.


#26

I was able to figure out my issue. When I return {"byte_array":bytes} I see the base64 encoded value.

When I return {"byte_array":bytes[0]} I get the value.


#27

I use thi function to print the bytes received by Decode in hex:

function toHexString(bytes) {
    return bytes.map(function(byte) {
        return ("00" + (byte & 0xFF).toString(16)).slice(-2)
      }).join('')
}

function Decode(fPort, bytes) {

    var tempObj = new Object();
    tempObj.dataHex = toHexString(bytes);

    tempObj.message = "Raw message bytes";

    return tempObj;

}