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

Mesh set TTL per message.

As in another post, I was looking for a way to change the TTL per message. Is there a reason that it can only be changed per model? I can imagine the TTL being part of the access_message_tx_t, or as optional arg in access_model_publish(), as at some point, the TTL is added to the message anyway.

In any case: is it safe to access_model_publish_ttl_set() just before sending a message (and does it set the TTL of that message)?

Using Mesh SDK 3.2.

  • Hello,

    Yes. You can set the TTL for a model by using access_model_publish_ttl_set(). Remember that this will set it for all messages in this model, so if you just want to send one message with a specific TTL, then you need to set it back after this.

     

    Is there a reason that it can only be changed per model?

     The reason is that packet_tx() uses TTL fetched from the model handle, if it is not set to ACCESS_TTL_USE_DEFAULT. If the TTL is set to ACCES_TTL_USE_DEFAULT, it uses the m_default_ttl, which is set to ACCESS_DEFAULT_TTL. You can set this to something else than 4 if you want to. Or if you want to change the TTL of all models, then you can implement some API that changes m_default_ttl. 

    Best regards,

    Edvin

  • Thanks.

    Went a bit through the code, and indeed noticed the TTL is added pretty far from the access_model_publish() call.

    So calling access_model_publish_ttl_set() a lot doesn't hurt? It looks like it invalidates some cache or so.

  • Just check what access_model_publish_ttl_set() returns. You can see what the return values mean here.

    It looks like it does store these changes using the ACCESS_INTERNAL_STATE_IS_OUTDATED() and element_store() in access_flash_config_store().

    This means that every time you change this, it will store this in flash. If you do this many (!) times, it will wear out the flash. The number of guaranteed flash write cycles is 10000, which you can see here(nRF52832) or here(nRF52840).

    Note that one write is not one cycle. The Mesh SDK uses the flash manager which will write to a free space in the flash, and when it is full, it will erase all outdated entries, and this counts as one cycle.

    If you want to change the TTL temporary without saving this setting in flash, you may look into implementing a function that changes m_default_ttl, and doesn't save this to flash. Note that changing m_default_ttl will change the ttl for all models that uses ttl = ACCESS_TTL_USE_DEFAULT.

    BR,
    Edvin

  • Aha, didn't know that the ACCESS_INTERNAL_STATE_IS_OUTDATED() means it gets stored to flash.

    Thanks for the tip, will give it a try :)

  • Another way I to implement, is by overiding the nrf_mesh_relay_check_cb_t and stop relaying before TTL reaches 0, for certain message types. Does that have any downsides?

Related