<?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 add an event handler for service?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/39112/how-to-add-an-event-handler-for-service</link><description>Hi, 
 I&amp;#39;m studying the example code of &amp;quot;ble_app_blinky_pca10040_s132 &amp;quot;. 
 What confused me is I couldn&amp;#39;t find how the &amp;quot;led_write_handler&amp;quot; is added to the service. There is a line 
 // Initialize LBS. init.led_write_handler = led_write_handler; 
 in main</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 03 Oct 2018 12:59:53 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/39112/how-to-add-an-event-handler-for-service" /><item><title>RE: How to add an event handler for service?</title><link>https://devzone.nordicsemi.com/thread/151451?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 12:59:53 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aea1349b-045d-4580-8b7d-4ac563f5ae08</guid><dc:creator>jj8431</dc:creator><description>&lt;p&gt;Thanks. I didn&amp;#39;t found that before. That helps. It could be helpful if there&amp;#39;s a list or guide about these articles on your main web site or other easy to find places.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to add an event handler for service?</title><link>https://devzone.nordicsemi.com/thread/151372?ContentTypeID=1</link><pubDate>Wed, 03 Oct 2018 09:35:44 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2c8962d7-1d2c-4de6-ac45-e257dc090566</guid><dc:creator>Marjeris Romero</dc:creator><description>&lt;p&gt;Hi!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
[quote user=""]&lt;span style="background-color:#00ffff;font-family:&amp;#39;courier new&amp;#39;, courier;"&gt;// Initialize service structure.&lt;/span&gt;&lt;br /&gt;&lt;span style="background-color:#00ffff;font-family:&amp;#39;courier new&amp;#39;, courier;"&gt; p_lbs-&amp;gt;led_write_handler = p_lbs_init-&amp;gt;led_write_handler;&lt;/span&gt;[/quote]
&lt;p&gt;Here the member called &amp;quot;led_write_handler&amp;quot; from the struct that p_lbs points to is set to the &amp;quot;led_write_handler&amp;quot; of our service init structure, and so it is added to the service. The pointer p_lbs points to m_lbs in main.c since we called: &lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;    err_code = ble_lbs_init(&amp;amp;m_lbs, &amp;amp;init);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;in line 302.&lt;/p&gt;
&lt;p&gt;Do this answer your question?&lt;/p&gt;
&lt;p&gt;If you want to add custom services and characteristics I recommend to first take a look at our Bluetooth Low Energy tutorials for how to add &lt;a href="https://devzone.nordicsemi.com/tutorials/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial"&gt;Services&lt;/a&gt; and &lt;a href="https://devzone.nordicsemi.com/tutorials/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial"&gt;Characteristics&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Best Regards,&lt;/p&gt;
&lt;p&gt;Marjeris&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>