How to generate the eui keys?

I’ve come to understand from the guide and other posts that in the web interface you can simply enter in random values in the eui fields. However, when using the lmic library for arduino based nodes, all the example codes have a different format such as:

// 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] = { 0x13, 0xF9, 0x00, 0xD0, 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] = { 0x56, 0x46, 0x54, 0x95, 0x78, 0x56, 0x34, 0x12 };
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.
// The key shown here is the semtech default key.
static const u1_t PROGMEM APPKEY[16] = { 0xFC, 0x64, 0xAD, 0xE6, 0x05, 0xF9, 0x69, 0x73, 0x5F, 0xD7, 0x12, 0x47, 0x7B, 0x1A, 0x89, 0xFC };
void os_getDevKey (u1_t* buf) {
memcpy_P(buf, APPKEY, 16);

How do we convert the values entered into the web interface to be in the format matching the example code???

It sure would be nice if the web interface would assist with either generating these eui values or providing a converted format based off our random values. Or at least provide more info in guide as to how to do that.

Edit: I just want to mention to @brocaar that you’ve done an amazing job with this project. You probably hear that - but probably not enough. Also, I was going to look into the project to see about contributing to add generator functionality, but looks like you’ve got something in the works?!

{ 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01};

This would translate to 0102030405060708 in HEX format. Note the comment that the values must be put into reverse order in your code.

Thanks for the reply. So just take whatever random int numbers we come up with and convert them to hex? Is there a recommended way of doing that?

And for the reverse, reverse the int number prior to hex convert?

Since the original post, I’ve come to the conclusion that I need to use abp in my project. In the web interface there’s generate links that generate alphanumeric values.

Would you please provide an example of how to take those values and put them into the lmic arduino code for nwkskey and appskey.

I would really appreciate that. I’ve been trying to learn about how to convert or use these key values but not able to find any clear information. Everything I find is TTN related and they have generators with the formatting applied.

Anyone able to help clear this please chime in.

Thank you

This is not too difficult:

Given 010203AABBCC (which is not a full key), this would be in code:


{0x01, 0x02, 0x03, 0xAA, 0xBB, 0xCC}

LSB (the reverse order of the bytes):

{0xCC, 0xBB, 0xAA, 0x03, 0x02, 0x01}

Note that the 0x prefix is to indicate that the byte value is base16, so is the given key 010203AABBCC. As a base16 needs two chars per byte, this results in 01 02 03 AA BB CC when you put a space between them and then to turn this into a byte array (for C) you prefix each byte with 0x, so you get 0x01, 0x02, 0x03, ... :slight_smile:


Thank you!

I realize this must be trivial for you and others, but for me, all this is new. Hex, base16, byte, why “0x”, and how… all of that is new. Searching wasn’t producing answers and probably because I didn’t know what I needed to search for… the right terminology, formatting, etc…

So, your reply completely clarified that and I appreciate it. I suggest you add that to the devices page. That alone would have saved me so much time and may help others too.

There’s 3 (hopefully) last questions which I would just like to confirm.

  1. I assume I don’t need to do any MSB/LSB for the NWKSKEY and APPSKEY right? That’s not specified on the devices page for ABP like it is for OTAA.

  2. What about the case? The generated keys are all lowercase. Do I leave them lowercase?

  3. Lastly… if you would, just confirm the following is correct: Field name and value to code.

On “Activation” tab of the page:

Applications / MyAppName / Devices / MySensorName

Device address: 00a0dca1
add as
static const u4_t DEVADDR = 0x00a0dca1;

Network session encryption key: 2b7e151628aed2a6abf7158809cf4f3c
add as
static const PROGMEM u1_t NWKSKEY[16] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c };

Application session key: 2b7e151628aed2a6abf7158809cf4f3c
add as
static const u1_t PROGMEM APPSKEY[16] = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6, 0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c }

Thanks for taking the time to clarify these things. :slight_smile: