Uplink frames with unexpected data

Hi!

@brocaar thank you for an opportunity to have an opensource Lora gateway, network and app servers. This is really cool to be able to get a fully functional Lora setup by yourself with a such detailed documentation. I am making my own POC with your product and Globalsat devices on AWS and when my POC will be ready I will gladly add my step-by-step how to for a fully AWS native setup (EC2, RDS, Elasticache, Cloudwatch, IOT etc). But right now I am facing some issue which I cannot understand (yet!) from a Lora AppServer.

When I troubleshoot radio traffic which is captured by my gateway from my class A end device (GlobalSat LT-100) I can see proper uplink data frames captured and forwarded to my Lora Network Server and Lora AppServer:

If I get PHYPayload from the frames and use lora-packet decoder with valid NwkSKey and AppSKey I can see expected data payload (PHYPayload=405F376D10000C0002C330DC1ADE48B4A93A214356A85C8A) which gives me proper decrypted end data: 00822102117FEA01F84F4B

So based on that I assume that end device sends proper payloads which are properly encrypted and transmitted.

Unfortunately when I check relevant MQTT topics or Live LoraWAN Frames / Live Device Data in Lora AppServer GUI I can see something weird under Data: AllhAhF/6gH4T0s=. How this data had been calculated by AppServer? What should I do to get expected encrypted data that had been sent by the end device (00822102117FEA01F84F4B)?

Thank you in advance.

Data there is base64 encoded for presentation. You can write your own custom codec at the application configuration: the decoding function receives the data as a bytes array and allows to create and object based on your way of encoding/decoding sent data.

Thank you @iegomez
I assumed this based on information that I had found here on forum. But unfortunately it is still not very clear for me how this 00822102117FEA01F84F4B is converted to this AllhAhF/6gH4T0s=

I tried base64 decoder/encoder and I did not manage to make this data conversion. Can you please give some more details on that?

Thank you.

Here’s an example in Go that goes both ways: https://play.golang.org/p/BZE5y2mWbiu
But as said, you can decode the bytes directly with a custom codec.

1 Like

Thanks for that! I think I can go further from here.

Ok, I’ve managed to prepare JS function which encodes my base64 to hex and then encodes my bytes to a decimal values. Here is a working example. Unfortunately when I use it as a custom JS codec AppServer shows me that atob function is not defined.

You don’t need to mess with base 64 representation at the codec function, the data is given to you as an array of bytes. That means that for the data you provided (00822102117FEA01F84F4B in hex) :

function Decode(fPort, bytes) {
  //bytes is [0, 130, 33, 2, 17, 127, 234, 1, 248, 79, 75].
  console.log(bytes[1]) //This would print 130 to the console.
  ...
}

As I said, base 64 representation is only used for presentation of data, you don’t have to deal with it. As for atob erroring, here’s the package used for the JS vm: https://github.com/robertkrimen/otto

Hi @mijgun, I read your post and I’m exactly like you. I also have the LT-100 and I received uplink frames but I dont know how to decrypt de data.
Can you help me please?

// Decode decodes an array of bytes into an object.
//  - fPort contains the LoRaWAN fPort number
//  - bytes is an array of bytes, e.g. [225, 230, 255, 0]
// The function must return an object, e.g. {"temperature": 22.5}
function Decode(fPort, bytes) {
	var HEX = '';
    for (var i = 0; i < bytes.length; i++) {
		var _hex = bytes[i].toString(16);
    	HEX += (_hex.length == 2 ? _hex : '0' + _hex);
  }
  var result = HEX.toUpperCase();  
  return {"data": result};
}

I received uplink frames but I dont know how to decrypt de data.

As already explained here, if you are looking at the MQTT messages on the application/ topics, then you nee to do base64 decoding.

While if you are talking about writing a javascript decoder to be run by the LoRa application server itself, then you are given a vector of bytes and should follow the example decoder given there.

And if you are talking about raw traffic as on the gateway/ topics, this is still encrypted, you would need to base64 decode it and then unpack and decrypt the LoRaWan packet using your knowledge of your own keys - but that is what the application server does for you when it publishes to the application/ topics.

Hi mate, here is my JS function to decode LT-100

    function Decode(fPort, bytes) {
    var Battery = bytes[2];
    var d = bytes[3];
    var e = bytes[4];
    var f = bytes[5];
    var g = bytes[6];
    var h = bytes[7];
    var i = bytes[8];
    var j = bytes[9];
    var k = bytes[10];

    var Byte03 = d.toString(16);
    var Byte04 = e.toString(16);
    var Byte05 = f.toString(16);
    var Byte06 = g.toString(16);
    var Lat = "0x"+Byte03+Byte04+Byte05+Byte06;
    var Latitude = parseInt(Lat, 16) * 0.000001;

    var Byte07 = h.toString(16);
    var Byte08 = i.toString(16);
    var Byte09 = j.toString(16);
    var Byte10 = k.toString(16);
    var Lon = "0x"+Byte07+Byte08+Byte09+Byte10;
    var Longitude = parseInt(Lon, 16) * 0.000001;


    return {Battery:Battery,Latitude:Latitude,Longitude:Longitude};
  }
1 Like

Hello @mijgun, you are the only person that I find that use the LT-100.
I want to send data to the tracker, for example to active the buzzer or the vibrate, but I dont know how to send data to the device. Can you explain me how to do it? Thank you!