Unable to decode the data with JavaScript codec

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

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

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

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’

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.

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.

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)

function Decode(fPort, bytes) {

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

    tempObj.message = "Raw message bytes";

    return tempObj;


I used this to get the original message (bypassing the decode issues), having the same issue as these people.

function Decode(fPort, bytes) {
  return {
    data: String.fromCharCode.apply(null,bytes)

hi everyone,
I also have an issue when it comes to decoding the payload.
I’m sending the string “hi” from my Arduino using LMIC this way:

void do_send(osjob_t *j)
  static uint8_t message[] = "hi";
  // Check if there is not a current TX/RX job running
  if (LMIC.opmode & OP_TXRXPEND)
    Serial.println(F("OP_TXRXPEND, not sending"));
    // Prepare upstream data transmission at the next possible time.
    LMIC_setTxData2(1, message, sizeof(message) - 1, 0);

    Serial.println(F("Packet queued"));
    Serial.print(">> ");
    Serial.println(reinterpret_cast<char *>(message));
  // Next TX is scheduled after TX_COMPLETE event.

This is the JSON I get from the MQTT Client:

  "applicationID" : "1",
  "applicationName" : "testApp",
  "deviceName" : "abpTest",
  "devEUI" : "xxxxx",
  "rxInfo" : [ {
    "gatewayID" : "xxxxxx",
    "name" : "testGW",
    "rssi" : -51,
    "loRaSNR" : 9.8,
    "location" : {
      "latitude" : 0,
      "longitude" : 0,
      "altitude" : 0
  } ],
  "txInfo" : {
    "frequency" : 868100000,
    "dr" : 5
  "adr" : true,
  "fCnt" : 21,
  "fPort" : 1,
  "data" : "br4="

The data-field changes on every transmission. br4=, DjI= and so on. When I Base64 decode the data-field, I just get gibberish. Do you have any idea what I do wrong?

I managed to fix this. The AppSKey was saved MSB, not LSB…