<?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>Zephyr Bluetooth peripheral  callbacks</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/89446/zephyr-bluetooth-peripheral-callbacks</link><description>We currently have a nRF52840 central device written with the Bluetooth Nordic SoftDevice API. From what I have read, the Zephyr RTOS is the best way going forward. I started creating a peripheral Bluetooth sensor that would connect to our central using</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 30 Jun 2022 12:59:22 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/89446/zephyr-bluetooth-peripheral-callbacks" /><item><title>RE: Zephyr Bluetooth peripheral  callbacks</title><link>https://devzone.nordicsemi.com/thread/374913?ContentTypeID=1</link><pubDate>Thu, 30 Jun 2022 12:59:22 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:bb05e90c-c153-4360-a924-4039bf236cf2</guid><dc:creator>DavidKaplan</dc:creator><description>&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;David&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Zephyr Bluetooth peripheral  callbacks</title><link>https://devzone.nordicsemi.com/thread/374793?ContentTypeID=1</link><pubDate>Wed, 29 Jun 2022 15:57:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:36fa687c-c4c5-4f90-86a0-7b4e98cb8cea</guid><dc:creator>Simon</dc:creator><description>&lt;p&gt;I think you can achieve this by using the &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/include/zephyr/bluetooth/gatt.h#L150"&gt;user data field&lt;/a&gt; of the&amp;nbsp;&lt;span&gt;bt_gatt_attr&lt;/span&gt;&lt;span&gt;&amp;nbsp;struct, it is the last input of &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/include/zephyr/bluetooth/gatt.h#L675-L681"&gt;BT_GATT_CHARACTERISTIC()&lt;/a&gt;. Then when you set up&amp;nbsp;BT_UUID_AMI_LOG_TYPE_CHR you can&amp;nbsp;point user data to X and when setting up&amp;nbsp;BT_UUID_AMI_LOG_INTERVAL_CHR you can&amp;nbsp;point it to Y. Then in the on_write callback, you can check if the user data (accessed through&amp;nbsp;&lt;/span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L62"&gt;&lt;span&gt;attr&lt;/span&gt;&lt;span&gt;-&amp;gt;&lt;/span&gt;&lt;span&gt;user_data&lt;/span&gt;&lt;/a&gt;&lt;span&gt;) is X (log type chr) or Y (interval chr) and then take the appropriate action.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;The sample&amp;nbsp;\zephyr\samples\bluetooth\peripheral\src\main.c is also using the user data field to achive this, with a slightly different approach, it&amp;nbsp;simply points the user data to the array storing the char value and then simply writes the value to that field. Check it out yourself:&lt;/span&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;Setting up vnd &amp;quot;enc. characteristic&amp;quot; with user value=&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L45"&gt;&lt;code&gt;vnd_value&lt;/code&gt;&lt;/a&gt;&amp;nbsp;and write function =&amp;nbsp;&lt;code&gt;write_vnd&lt;/code&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;span&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L196"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L196&lt;/a&gt;&lt;/span&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;span&gt;Setting up &amp;quot;vnd auth characteristic&amp;quot; with user value=&lt;code&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L46"&gt;vnd_auth_value&lt;/a&gt;&amp;nbsp;&lt;/code&gt;and write function =&amp;nbsp;&lt;code&gt;write_vnd&lt;/code&gt;&lt;/span&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L203"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L203&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;If write_vnd() function is triggered after a write to the&amp;nbsp;&lt;span&gt;&amp;quot;enc. characteristics&amp;quot;, the following will happen&lt;/span&gt;&amp;nbsp;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Gets the user data, which will be &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L45"&gt;vnd_value&lt;/a&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L62"&gt;https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L62&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Writes the received value (buf) to &lt;a href="https://github.com/nrfconnect/sdk-zephyr/blob/v3.0.99-ncs1/samples/bluetooth/peripheral/src/main.c#L45"&gt;vnd_value&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Simon&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>