This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

mesh_config_entry_get()/mesh_config_entry_set() are not working as expected

Hi all,

I am developing on nRF Mesh SDK 4.0.0 with nRF52833 DK (PCA10100).

To save/restore persistent model state to flash, I added the code using mesh_config_entry_get()/mesh_config_set() functions as below.

1. I added mesh_config_entry_get() in model initialization function.

   It will fail if there is no entry in flash, but after saved once, it can read it afterwards.

2. I also added mesh_config_entry_set() function in model set callback.

    When I send a set message, log shows that this function call is successful, i.e. returns NRF_SUCCESS.

But, when I power cycled the board, it still cannot get the entry and mesh_config_get() always failed.

What is wrong/missing in my code? Can somebody advice about?

TIA.

Parents
  • Hi Choe, 

    Could you let me know how you define your config ID , have you followed what we did, for example in mesh_opt_provisioner.h in the light switch provisioner example ? 

    You need to define config file using MESH_CONFIG_FILE().

    Please note that you can store your data using the flash library directly by creating your own flash area outside of the mesh config area. You can call this: mesh_stack_persistence_flash_usage() to know the mesh stack flash usage and allocate your own flash area outside of the mesh stack. 

  • I followed the emocean example.

    Below is my code for declaring & getting entries.

    #define LOCATION_FILE_ID                (0x0010)
    #define GLOBAL_LOCATION_RECORD          (0x0001)
    #define LOCAL_LOCATION_RECORD           (0x0002)
    #define GLOBAL_LOCATION_ENTRY_ID        MESH_CONFIG_ENTRY_ID(LOCATION_FILE_ID, GLOBAL_LOCATION_RECORD)
    #define LOCAL_LOCATION_ENTRY_ID         MESH_CONFIG_ENTRY_ID(LOCATION_FILE_ID, LOCAL_LOCATION_RECORD)
    
    MESH_CONFIG_FILE(m_location_file, LOCATION_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
    
    static uint32_t global_location_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void global_location_getter(mesh_config_entry_id_t id, void * p_entry);
    static void global_location_deleter(mesh_config_entry_id_t id);
    static uint32_t local_location_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void local_location_getter(mesh_config_entry_id_t id, void * p_entry);
    static void local_location_deleter(mesh_config_entry_id_t id);
    
    MESH_CONFIG_ENTRY(global_location,
                      GLOBAL_LOCATION_ENTRY_ID,
                      1,
                      sizeof(generic_location_global_status_params_t),
                      global_location_setter,
                      global_location_getter,
                      global_location_deleter,
                      false);
    
    MESH_CONFIG_ENTRY(local_location,
                      LOCAL_LOCATION_ENTRY_ID,
                      1,
                      sizeof(generic_location_local_status_params_t),
                      local_location_setter,
                      local_location_getter,
                      local_location_deleter,
                      false);
    
    static generic_location_global_status_params_t m_location_global =
    {
        .global_latitude = 0x80000000,
        .global_longitude = 0x80000000,
        .global_altitude = 0x7FFF,
    };
    
    static generic_location_local_status_params_t m_location_local =
    {
        .local_north = 0x8000,
        .local_east = 0x8000,
        .local_altitude = 0x7FFF,
        .floor_number = 0xFF,
        .uncertainty = 0x0000,
    };
    
    static uint32_t global_location_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        return NRF_SUCCESS;
    }
    
    static void global_location_getter(mesh_config_entry_id_t id, void * p_entry)
    {
    }
    
    static void global_location_deleter(mesh_config_entry_id_t id)
    {
        m_location_global.global_latitude = 0x80000000;
        m_location_global.global_longitude = 0x80000000;
        m_location_global.global_altitude = 0x7FFF;
    }
    
    static uint32_t local_location_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        return NRF_SUCCESS;
    }
    
    static void local_location_getter(mesh_config_entry_id_t id, void * p_entry)
    {
    }
    
    static void local_location_deleter(mesh_config_entry_id_t id)
    {
        m_location_local.local_north = 0x8000;
        m_location_local.local_east = 0x8000;
        m_location_local.local_altitude = 0x7FFF;
        m_location_local.floor_number = 0xFF;
        m_location_local.uncertainty = 0x0000;
    }
    
    static void model_config_load(void)
    {
        mesh_config_entry_id_t idx = GLOBAL_LOCATION_ENTRY_ID;
        uint32_t status = mesh_config_entry_get(idx, &m_location_global);
        if (status == NRF_SUCCESS)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Load global location: 0x%08X,0x%08X,0x%04X\n",
                  m_location_global.global_latitude, m_location_global.global_longitude, m_location_global.global_altitude);
        }
        idx = LOCAL_LOCATION_ENTRY_ID;
        status = mesh_config_entry_get(idx, &m_location_local);
        if (status == NRF_SUCCESS)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Load local location: 0x%04X,0x%04X,0x%04X,0x%02X,0x%04X\n",
                  m_location_local.local_north, m_location_local.local_east, m_location_local.local_altitude,
                  m_location_local.floor_number, m_location_local.uncertainty);
        }
    }

    And used the following code to set entries.

        // Save to configuration entry
        {
            mesh_config_entry_id_t entry_id = GLOBAL_LOCATION_ENTRY_ID;
            uint32_t status = mesh_config_entry_set(entry_id, &m_location_global);
            if (status == NRF_SUCCESS)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Save global location: 0x%08X,0x%08X,0x%04X\n",
                      m_location_global.global_latitude, m_location_global.global_longitude, m_location_global.global_altitude);
            }
        }
    ...
        // Save to configuration entry
        {
            mesh_config_entry_id_t entry_id = LOCAL_LOCATION_ENTRY_ID;
            uint32_t status = mesh_config_entry_set(entry_id, &m_location_local);
            if (status == NRF_SUCCESS)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Save local location: 0x%04X,0x%04X,0x%04X,0x%02X,0x%04X\n",
                      m_location_local.local_north, m_location_local.local_east, m_location_local.local_altitude,
                      m_location_local.floor_number, m_location_local.uncertainty);
            }
        }
    

    I am a little bit suspicious of using getter/setter code.

    Because I just already have static module variable and try to share it between functions, no code is used inside getter/setter function.

    Can it be problem?

Reply
  • I followed the emocean example.

    Below is my code for declaring & getting entries.

    #define LOCATION_FILE_ID                (0x0010)
    #define GLOBAL_LOCATION_RECORD          (0x0001)
    #define LOCAL_LOCATION_RECORD           (0x0002)
    #define GLOBAL_LOCATION_ENTRY_ID        MESH_CONFIG_ENTRY_ID(LOCATION_FILE_ID, GLOBAL_LOCATION_RECORD)
    #define LOCAL_LOCATION_ENTRY_ID         MESH_CONFIG_ENTRY_ID(LOCATION_FILE_ID, LOCAL_LOCATION_RECORD)
    
    MESH_CONFIG_FILE(m_location_file, LOCATION_FILE_ID, MESH_CONFIG_STRATEGY_CONTINUOUS);
    
    static uint32_t global_location_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void global_location_getter(mesh_config_entry_id_t id, void * p_entry);
    static void global_location_deleter(mesh_config_entry_id_t id);
    static uint32_t local_location_setter(mesh_config_entry_id_t id, const void * p_entry);
    static void local_location_getter(mesh_config_entry_id_t id, void * p_entry);
    static void local_location_deleter(mesh_config_entry_id_t id);
    
    MESH_CONFIG_ENTRY(global_location,
                      GLOBAL_LOCATION_ENTRY_ID,
                      1,
                      sizeof(generic_location_global_status_params_t),
                      global_location_setter,
                      global_location_getter,
                      global_location_deleter,
                      false);
    
    MESH_CONFIG_ENTRY(local_location,
                      LOCAL_LOCATION_ENTRY_ID,
                      1,
                      sizeof(generic_location_local_status_params_t),
                      local_location_setter,
                      local_location_getter,
                      local_location_deleter,
                      false);
    
    static generic_location_global_status_params_t m_location_global =
    {
        .global_latitude = 0x80000000,
        .global_longitude = 0x80000000,
        .global_altitude = 0x7FFF,
    };
    
    static generic_location_local_status_params_t m_location_local =
    {
        .local_north = 0x8000,
        .local_east = 0x8000,
        .local_altitude = 0x7FFF,
        .floor_number = 0xFF,
        .uncertainty = 0x0000,
    };
    
    static uint32_t global_location_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        return NRF_SUCCESS;
    }
    
    static void global_location_getter(mesh_config_entry_id_t id, void * p_entry)
    {
    }
    
    static void global_location_deleter(mesh_config_entry_id_t id)
    {
        m_location_global.global_latitude = 0x80000000;
        m_location_global.global_longitude = 0x80000000;
        m_location_global.global_altitude = 0x7FFF;
    }
    
    static uint32_t local_location_setter(mesh_config_entry_id_t id, const void * p_entry)
    {
        return NRF_SUCCESS;
    }
    
    static void local_location_getter(mesh_config_entry_id_t id, void * p_entry)
    {
    }
    
    static void local_location_deleter(mesh_config_entry_id_t id)
    {
        m_location_local.local_north = 0x8000;
        m_location_local.local_east = 0x8000;
        m_location_local.local_altitude = 0x7FFF;
        m_location_local.floor_number = 0xFF;
        m_location_local.uncertainty = 0x0000;
    }
    
    static void model_config_load(void)
    {
        mesh_config_entry_id_t idx = GLOBAL_LOCATION_ENTRY_ID;
        uint32_t status = mesh_config_entry_get(idx, &m_location_global);
        if (status == NRF_SUCCESS)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Load global location: 0x%08X,0x%08X,0x%04X\n",
                  m_location_global.global_latitude, m_location_global.global_longitude, m_location_global.global_altitude);
        }
        idx = LOCAL_LOCATION_ENTRY_ID;
        status = mesh_config_entry_get(idx, &m_location_local);
        if (status == NRF_SUCCESS)
        {
            __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Load local location: 0x%04X,0x%04X,0x%04X,0x%02X,0x%04X\n",
                  m_location_local.local_north, m_location_local.local_east, m_location_local.local_altitude,
                  m_location_local.floor_number, m_location_local.uncertainty);
        }
    }

    And used the following code to set entries.

        // Save to configuration entry
        {
            mesh_config_entry_id_t entry_id = GLOBAL_LOCATION_ENTRY_ID;
            uint32_t status = mesh_config_entry_set(entry_id, &m_location_global);
            if (status == NRF_SUCCESS)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Save global location: 0x%08X,0x%08X,0x%04X\n",
                      m_location_global.global_latitude, m_location_global.global_longitude, m_location_global.global_altitude);
            }
        }
    ...
        // Save to configuration entry
        {
            mesh_config_entry_id_t entry_id = LOCAL_LOCATION_ENTRY_ID;
            uint32_t status = mesh_config_entry_set(entry_id, &m_location_local);
            if (status == NRF_SUCCESS)
            {
                __LOG(LOG_SRC_APP, LOG_LEVEL_INFO, "Save local location: 0x%04X,0x%04X,0x%04X,0x%02X,0x%04X\n",
                      m_location_local.local_north, m_location_local.local_east, m_location_local.local_altitude,
                      m_location_local.floor_number, m_location_local.uncertainty);
            }
        }
    

    I am a little bit suspicious of using getter/setter code.

    Because I just already have static module variable and try to share it between functions, no code is used inside getter/setter function.

    Can it be problem?

Children
No Data
Related