cancel
Showing results for 
Search instead for 
Did you mean: 

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

SC26
Associate II

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.

17 REPLIES 17

@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...

SC26
Associate II

Hi !

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

Nice ! ��

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 ��

I will check about MX overwriting code ...

SC26
Associate II

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 !!!

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

 LmHandlerGetDevEUI();

 LmHandlerGetNwkKey();

 LmHandlerGetAppKey();

Cheers,

Dana

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 ?

I'd start with ST documents UM2073 ("STM32 LoRaWAN® Expansion Package for STM32Cube") and AN5406 ("How to build a LoRa® application with STM32CubeWL").

Section 6.7 of AN5406 documents the LmHandler Set/Get functions. Note that you'll surely need to enable context management for this to be persistent (see 9.2.11 in AN5406).

I believe these functions can be called anytime after

  /* Init the Lora Stack*/
  LmHandlerInit(&LmHandlerCallbacks, APP_VERSION);
 
  LmHandlerConfigure(&LmHandlerParams);

Oh, but I just learned - once the mote is activated/joined, you can't update these persistent values. Makes sense, except sometimes you want to change them and re-join. Frankly there should be an LmHandler interface to 'de-activate' to program new values.

  MibRequestConfirm_t mibReq;
  LoRaMacStatus_t status;
 
  mibReq.Type = MIB_NETWORK_ACTIVATION;
  mibReq.Param.NetworkActivation = ACTIVATION_TYPE_NONE;
 
..........
 
  /* Init Info table used by LmHandler*/
  LoraInfo_Init();
 
  /* Init the Lora Stack*/
  LmHandlerInit(&LmHandlerCallbacks, APP_VERSION);
 
  LmHandlerConfigure(&LmHandlerParams);
 
  status = LoRaMacMibSetRequestConfirm( &mibReq );

This will clear the activation setting when needed to reconfigure. Also need to #include "LoRaMac.h"