Persistent storage of the thread instance

I am struggling to re-attach to a known and still existing network after restarting the device. I was thinking that the openthread library would persist its structures automatically in a reserved area of the memory. 

Therefore, I assumed that after a restart a call of otDatasetIsCommissioned() would return true, if the device was actively connected to a network before restarting it. But in my case, this function always returns false.

Is my assumption wrong, is the library not automatically persisting the network data?

We are using nrf5_sdk_for_thread_and_zigbee_v4.2.0

Thanks!

Simon

Parents
  • Hi,

    A couple of questions regarding your project:

    1. Is it based on an existing nRF5 sample for OpenThread/is it a modified or pristine nRF5 sample for OpenThread?
    2. Is it custom code?
    3. Are you able to run a pristine nrf5 sample, for instance one of the coap samples and see if the persistant storage is deleted?

    From what I can see the network data should be in persistent storage and the device should rejoin a network that it knows of. When testing otDatasetIsComissioned() in one of the nrf5sdk samples, this call returns true after power cycle. This leads me to think that you might have you call the function too early or that you delete the persistant storage sometime in your code given that your project is custom code.

    From a discussion I had with a colleague we have that the persistent storage is at the end of flash, or right before the bootloader if a bootloader is present, as you can see in OpenThread memory layout and requirements, so one option is to read this area.

    Another option is to use the operational dataset. On first boot, the device will not have a valid network in the operational dataset, so otDatasetIsCommissioned() will return false. After having joined a network, otDatasetIsCommissioned() will return true, even upon reset as long as the network data is not erased.

    Here is a very simple example code snippet:

    static otInstance * p_instance;
    
    static void some_function(void) 
    {
        p_instance = thread_ot_instance_get();
        bool is_dataset_commissioned = otDatasetIsCommissioned(p_instance);
        NRF_LOG_INFO("Is dataset commissioned? %d", is_dataset_commissioned);
    };

    I recommend defining p_instance as a global variable, so outside of a function scope. You can add the call to otDatasetIsCommissioned() whereever it is most fitting in your application.

    Let me know about this and I'll get back to you if this information does not resolve your issue

    Kind regards,
    Andreas

  • Hi Andreas, 

    thank you very much for your detailed answer!

    I will verify all those points and try to find the issue on our side. Now as I know that the stack should handle all those parts correctly I can examine our code in detail. 

    Kind regards, 

    Simon

Reply Children
No Data
Related