Hex, lsb or msb?

In TTN Console id’s can be displayed (and copied) in three formats: hex, lsb and msb:

Copy current value
Toggle hex/C-style
Toggle msb/lsb
lsb

When setting up an Arduino sketch which of these formats should be used for the likes of DevAddr, NwkSKey, AppSKey etc.?

1 Like

HEX is the human-readable format (msb first). In most cases (including Arduino) you can just copy-paste the msb first version. In some libraries (such as LMiC), you need to use the lsb first version.

Perhaps it would be good to expand the “hex”, “msb” and “lsb” labels a bit? E.g. say “msb first”, or perhaps even “msb first (big endian)” to make it clearer. Or also emphasize that it’s just the display format that changes, so “display as big endian (msb first)”?

1 Like

…or even “display as big endian (msb first, for use in Arduino)”.

What does “Arduino” even mean here? Why would all Arduinos require MSB-first? LMIC requires LSB-first and also runs on an Arduino, so I would think adding that is only confusing? Also, before someone suggests to add “for use in LMIC” to the LSB-first version: I’m planning to add some automatic conversion to LMIC, so you can just use the hex version instead (It’ll be opt-in for compatibility). So I think we should stick to describing the format, and leave it up to the documentation of whatever library is used to state what format they expect.

3 Likes

Hm… this is not really helping me.

I’m programming my first ATmega/RFM95 node and I need to copy in three values:

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8]= { 0x99, 0x6B, 0x00, 0xF0, 0x7E, 0xD5, 0xB3, 0x70 };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8); }

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8]= { 0x53, 0xAF, 0xEB, 0xD5, 0x56, 0xCB, 0x6B, 0x00 };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8); }

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { 0x71, 0x00, 0x0D, 0xDB, 0xE8, 0xDA, 0xF6, 0x9D, 0x1C, 0x84, 0x9D, 0x2C, 0x65, 0x3E, 0xF5, 0x47 };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16); }

I think I have done all permutations of MSB/LSB combinations up to the point where I see a join request and an accept message in the gateway console … but no data.
In the application console I only see the requests…

So, is the library updated already and what should I copy in to the three fields…???

If you see the activation in the device data log, or see an accept in the gateway console (and you’re really sure that it’s for your device), then you can be sure the AppEUI, DevEUI and AppKey are correct. If activation is not happening, there might be another problem (possibly in downlink transmission or reception).

1 Like

That’s intentional, you’ll only see an activation (request) when it decrypted successfully and an accept message is actually sent.

For future reference, when using LMIC:

In TTN Console, go to Applications, find your application and then find your device. Configure it for OTAA, and save the settings. Next, if things look like this for the configuration of your device:

MSB

…then for LMIC, click the <> icon (showing “hex/C-style” when hovering your mouse over it) and icon (showing “lsb/msb” when hovering) to the left of the Device EUI and Application EUI, to get “C-style” and “lsb” for those two. Also click the <> icon to get “C-style” and “msb” for the App Key.

When done, this should get you two values labeled as “lsb”, and one as “msb”:

LSB and MSB

Next, use the clipboard icon to the right of all values to copy them into your LMIC code. As every TTN provided AppEUI starts with 0x70B3D57ED, you’ll see that in LSB format the LMIC APPEUI ends with 0xD5, 0xB3, 0x70 }.

For ABP AppSKey and NwkSKey, LMIC wants MSB instead.

See: Format of Keys and ID's for Arduino LMIC libraries [HowTo]

4 Likes