Skip to main content
SC26
Associate II
July 22, 2022
Question

[STM32WLE5JC][LoRaWan - End_Node] How to change device_eui, epp_eui, app_key from program ?

  • July 22, 2022
  • 8 replies
  • 4953 views

Hi,

I have build a custom application from end_node project example on LoRa-E5 board.

All works fine with comissioning from CubeMX.

But now I want to use values loaded from flash.

So I added 3 variables :

uint8_t device_eui[8];

uint8_t app_eui[8];

uint8_t app_key[16];

I can read/write values from flash.

But now : how to use this values for LoRa-Wan OTAA joining ???!!!!

How could this be sooooo hard to do ???!!!!!

Thanks for help.

This topic has been closed for replies.

8 replies

Andrew Neil
Super User
July 22, 2022

The software does OTAA as-is - no changes needed. :beaming_face_with_smiling_eyes:

See this series of videos:

https://www.youtube.com/watch?v=vuc6914B0KM - Part 1; parts 2 & 3 follow

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SC26
SC26Author
Associate II
July 22, 2022

Hi,

I know OTAA is well done ... that's not my answer.

The question was : how to change End device commissioning parameters without rebuibind firmware for each device ?

( I already have read this parameters in variables from flash )

thanks.

SC26
SC26Author
Associate II
July 22, 2022

I have look the 4 video ... not what I'm lokoing for ... he just edit identity.h to change commissioning parameters ...

Andrew Neil
Super User
July 22, 2022

As it tells you in those videos, the Device EUI is taken from the STM32's unique ID.

To change the other parameters, just look at where those values get used - use your IDE's browsing facilities - and supply your own instead.

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SC26
SC26Author
Associate II
July 22, 2022
I have try that ... And don't find.
So i ask here ...
SC26
SC26Author
Associate II
July 23, 2022

The problem is to find where set parameters in the end_node example project.

Of course this must be in USER CODE BEGIN / USER CODE END section for not beiing overwrite by CubeMX on next code generation ...

SC26
SC26Author
Associate II
July 23, 2022

In anycase : thanks for your answers ;)

SC26
SC26Author
Associate II
July 23, 2022

Where am I ?

I have found in "se-identity.h" all the MX's #define :

#define LORAWAN_DEVICE_EUI                 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

#define LORAWAN_JOIN_EUI                  { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }

#define LORAWAN_APP_KEY                  00,00,00,00,00,00,00,00,00,00,00,00,00,00,00,00

And also found where they are used :

[ soft-sec.c :: 527 ]

SecureElementStatus_t SecureElementInit( SecureElementNvmData_t *nvm, SecureElementGetUniqueId seGetUniqueId )

But this section is not user-allowed.

I also see some tools functions :

SecureElementStatus_t SecureElementSetKey( KeyIdentifier_t keyID, uint8_t* key )

SecureElementStatus_t SecureElementSetDevEui( uint8_t* devEui )

SecureElementStatus_t SecureElementSetJoinEui( uint8_t* joinEui )

But I don't found how (from where) I can use this ...

Andrew Neil
Super User
July 23, 2022

@SC26​ "Of course this must be in USER CODE BEGIN / USER CODE END section for not beiing overwrite by CubeMX"

I'm not sure that the LoRaWAN code is subject to CubeMX modifications?

I don't use CubeMX, but it should be easy to do a test to see if your changes survive a re-generation...

A complex system that works is invariably found to have evolved from a simple system that worked.A complex system designed from scratch never works and cannot be patched up to make it work.
SC26
SC26Author
Associate II
July 23, 2022

Hi !

custom device_eui was pretty easy by editing GetUniqueId function (in sys_app.c :: 198 ).

Nice ! :grinning_face:

void GetUniqueId(uint8_t *id)
{
 /* USER CODE BEGIN GetUniqueId_1 */
	extern uint8_t device_eui[8];
	//
	for( int i=0 ; i<8 ; i++ )
	{
		id[i] = device_eui[i];
	}
 return;
 /* USER CODE END GetUniqueId_1 */

Now ... I need to do the same for other parameters :face_savoring_food:

I will check about MX overwriting code ...

SC26
SC26Author
Associate II
July 23, 2022

OK, so ...

I found the way to custom eui/keys :

LoRaMac.c :: 4161

 // Initialize the Secure Element driver
 if( SecureElementInit( &Nvm.SecureElement, callbacks->GetUniqueId ) != SECURE_ELEMENT_SUCCESS ) /* ST_WORKAROUND: Add unique ID callback as input parameter */
 {
 return LORAMAC_STATUS_CRYPTO_ERROR;
 }
 
 // TEST : Set MY eui&keys
 {
 	extern uint8_t device_eui[8];
 	extern uint8_t app_eui[8];
 	extern uint8_t app_key[16];
 
 	SecureElementSetDevEui( device_eui );
 	SecureElementSetJoinEui( app_eui );
 	SecureElementSetKey( APP_KEY, app_key );
 }

This looks OK ... but the code is RESET after MX generation, maybe by editing library source code instead of my project ... but this is definitly not a solution ...

I will try this way, but if anybody have a better way, he is welcome !!!

Dana Myers
Senior
July 25, 2022

I believe these LmHandler functions are what you're looking for:

 LmHandlerGetDevEUI();

 LmHandlerGetNwkKey();

 LmHandlerGetAppKey();

Cheers,

Dana

SC26
SC26Author
Associate II
July 25, 2022

Hi, yes, this looks fine, but I don't know from where can I call them to ensure they are used by LoRaWan middleware ... any advice ?