<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>How to change advertising packet in Mesh many time ?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/41300/how-to-change-advertising-packet-in-mesh-many-time</link><description>Hi all, 
 Now, I have a troube. In Mesh 3.0, I want to advertising data. This is my function : 
 #define ADVERTISER_BUFFER_SIZE (128) 
 
 And whenever the data changes, I call adv_start function for advertising it. But I only do this 4 times, and from</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 02 Jan 2019 09:45:32 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/41300/how-to-change-advertising-packet-in-mesh-many-time" /><item><title>RE: How to change advertising packet in Mesh many time ?</title><link>https://devzone.nordicsemi.com/thread/163380?ContentTypeID=1</link><pubDate>Wed, 02 Jan 2019 09:45:32 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0fb7ae44-87b3-4229-b537-938e75c0f4d6</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;HI Giang,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I do not think commenting out&amp;nbsp;&lt;span&gt;NRF_MESH_ASSERT&amp;nbsp;in packet_buffer_free&amp;nbsp; is a very good idea. As stated in the comment, you cannot call&amp;nbsp;packet_buffer_free&amp;nbsp;&amp;nbsp;on packets that are not Popped or Reserved.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change advertising packet in Mesh many time ?</title><link>https://devzone.nordicsemi.com/thread/162893?ContentTypeID=1</link><pubDate>Sat, 22 Dec 2018 03:14:41 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0b8fa76d-42a3-47e8-aacf-a229960c1e41</guid><dc:creator>Giang</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I changed code to :&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static void tx_commplete(advertiser_t * p_adv, nrf_mesh_tx_token_t token, timestamp_t timestamp)
{ 
    // free p_packet pointer for alloc next
    if(p_adv-&amp;gt;p_packet!=NULL)
    {
        advertiser_packet_discard(p_adv,p_adv-&amp;gt;p_packet);
    }
}

static void adv_init(void)
{
    advertiser_instance_init(&amp;amp;m_advertiser, tx_commplete, m_adv_buffer, ADVERTISER_BUFFER_SIZE);
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I get HardFault:&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1545448454614v1.png" /&gt;&lt;img alt=" " src="https://devzone.nordicsemi.com/resized-image/__size/320x240/__key/communityserver-discussions-components-files/4/pastedimage1545448475079v2.png" /&gt;&lt;/p&gt;
&lt;p&gt;And&amp;nbsp;p_packet-&amp;gt;packet_state =&amp;nbsp;PACKET_BUFFER_MEM_STATE_FREE&lt;/p&gt;
&lt;p&gt;If I comment NRF_MESH_ASSERT , everything work fine. I can change many time&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change advertising packet in Mesh many time ?</title><link>https://devzone.nordicsemi.com/thread/161463?ContentTypeID=1</link><pubDate>Wed, 12 Dec 2018 13:42:54 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:daeb5b95-811f-430c-ac91-690e3c4f682b</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;It could be that you need to wait for the&amp;nbsp;&lt;span&gt;advertiser_tx_complete_cb_t&lt;/span&gt;&lt;span&gt; tx_complete_cb callback, that is registered&amp;nbsp;when calling&amp;nbsp;&lt;/span&gt;advertiser_instance_init(), and then&amp;nbsp;&lt;span&gt;free the memory allocated.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;
&lt;div&gt;&lt;span&gt;&lt;span&gt;After&amp;nbsp;&lt;/span&gt;&lt;/span&gt;&lt;span&gt;advertiser_packet_send() is called&amp;nbsp;&lt;/span&gt;and&amp;nbsp;the packet is sent successfully, the @c tx_complete_callback in the @c p_adv&amp;nbsp;&lt;span style="font-family:inherit;"&gt;* will be called with @c p_packet and @c p_adv as parameters to the callback.&lt;/span&gt;&lt;/div&gt;
&lt;p&gt;&lt;span&gt;Use the parameters as input to&amp;nbsp;&lt;/span&gt;&lt;span&gt;advertiser_packet_discard&lt;/span&gt;&lt;span&gt;(&lt;/span&gt;&lt;span&gt;advertiser_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; p_adv, &lt;/span&gt;&lt;span&gt;adv_packet_t&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;*&lt;/span&gt;&lt;span&gt; p_packet) to free the memory allocated.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change advertising packet in Mesh many time ?</title><link>https://devzone.nordicsemi.com/thread/161452?ContentTypeID=1</link><pubDate>Wed, 12 Dec 2018 13:13:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f88cb182-874d-446b-9b01-010168e869ad</guid><dc:creator>Giang</dc:creator><description>&lt;p&gt;Yes, default set&amp;nbsp;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span&gt;ADVERTISER_BUFFER_SIZE&lt;/span&gt;&lt;span&gt;&amp;nbsp;(&lt;/span&gt;&lt;span&gt;64&lt;/span&gt;&lt;span&gt;) and I only change data 2 times, from 3th data not change, I change it to&amp;nbsp;#define&amp;nbsp;ADVERTISER_BUFFER_SIZE&amp;nbsp;(128) and I can change data 4 times, but I can not increase it forever. Seem it not good solution. I try SDK 2.0 , 2.2 ,3.0 , It&amp;nbsp;&lt;/span&gt;&lt;span lang="en"&gt;encounters the same problem. And SDK 1.0 no problem.So I looking for another solution . Thanks.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to change advertising packet in Mesh many time ?</title><link>https://devzone.nordicsemi.com/thread/161382?ContentTypeID=1</link><pubDate>Wed, 12 Dec 2018 09:44:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1d6fcdc4-dc51-47a5-82be-3337a25a40db</guid><dc:creator>bjorn-spockeli</dc:creator><description>&lt;p&gt;looking at the implementation of&amp;nbsp;advertiser_packet_alloc() we see that it will return&amp;nbsp;packet_buffer_reserve() return status ==&amp;nbsp;NRF_ERROR_NO_MEM&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;adv_packet_t * advertiser_packet_alloc(advertiser_t * p_adv, uint32_t adv_payload_size)
{
    NRF_MESH_ASSERT(p_adv != NULL);
    NRF_MESH_ASSERT(adv_payload_size &amp;lt;= BLE_ADV_PACKET_PAYLOAD_MAX_LENGTH);

    packet_buffer_packet_t * p_buf_packet;
    uint32_t status = packet_buffer_reserve(&amp;amp;p_adv-&amp;gt;buf, &amp;amp;p_buf_packet, sizeof(adv_packet_t) - BLE_ADV_PACKET_PAYLOAD_MAX_LENGTH + adv_payload_size);
    if (NRF_SUCCESS == status)
    {
        adv_packet_t * p_adv_packet  = (adv_packet_t *) p_buf_packet-&amp;gt;packet;
        packet_payload_size_set(&amp;amp;p_adv_packet-&amp;gt;packet, adv_payload_size);
        p_adv_packet-&amp;gt;packet.header.type = BLE_PACKET_TYPE_ADV_NONCONN_IND;
        set_adv_address(p_adv, &amp;amp;p_adv_packet-&amp;gt;packet);
        p_adv_packet-&amp;gt;token = NRF_MESH_INITIAL_TOKEN;
        return p_adv_packet;
    }
    else
    {
        NRF_MESH_ASSERT(status == NRF_ERROR_NO_MEM);
        return NULL;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Looking at the documentation of&amp;nbsp;&lt;span&gt;packet_buffer_reserve&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;/**
 * Reserves a packet in the given packet buffer.
 *
 * @param[in, out] p_buffer A packet buffer instance to reserve a packet on.
 * @param[out] pp_packet Reference to the reserved packet.
 * @param[in] length Number of bytes of payload to reserve, not including the
 * static header fields of the packet.
 *
 * @warning This function requires that:
 *               - Pointers supplied are not NULL
 *
 * @retval NRF_SUCCESS The packet is reserved successfully, and pp_packet points to
 * a valid packet pointer instance.
 * @retval NRF_ERROR_NO_MEM The packet buffer does not have enough available memory.
 * @retval NRF_ERROR_INVALID_LENGTH The length of the packet requested cannot be 0 or greater
 * than the maximum available packet size in the given packet buffer. Use @ref
 * packet_buffer_max_packet_len_get to determine the max packet length possible.
 */
uint32_t packet_buffer_reserve(packet_buffer_t * const p_buffer, packet_buffer_packet_t ** pp_packet, uint16_t length);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;we see that it will return&amp;nbsp;NRF_ERROR_NO_MEM if the packet buffer does not have enough available memory. So you need to look at the size of the buffer that you pass to&amp;nbsp;advertiser_instance_init(), I think defined as &lt;span&gt;ADVERTISER_BUFFER_SIZE&lt;/span&gt;&lt;span&gt;&amp;nbsp; and&amp;nbsp;&lt;/span&gt;its set to&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;#define&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span&gt;ADVERTISER_BUFFER_SIZE&lt;/span&gt;&lt;span&gt; (&lt;/span&gt;&lt;span&gt;64&lt;/span&gt;&lt;span&gt;)&lt;/span&gt;&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>