<?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>Writing a custom BLE service and integrating other relevant BLE APIs into the application</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/77083/writing-a-custom-ble-service-and-integrating-other-relevant-ble-apis-into-the-application</link><description>I am looking to integrate BLE into my application (something like NUS for now). From what I&amp;#39;ve heard, you aren&amp;#39;t supposed to be making changes to the BLE stack itself, and rather just write custom services according to your needs. 
 I currently have written</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 06 Jul 2021 07:22:21 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/77083/writing-a-custom-ble-service-and-integrating-other-relevant-ble-apis-into-the-application" /><item><title>RE: Writing a custom BLE service and integrating other relevant BLE APIs into the application</title><link>https://devzone.nordicsemi.com/thread/318725?ContentTypeID=1</link><pubDate>Tue, 06 Jul 2021 07:22:21 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:33463222-3a33-423b-8de7-82fe236aa6f3</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello again,&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote user="morpho"]1) Given I have my own service, would I have to implement APIs like&amp;nbsp;ble_nus_data_send()?[/quote]
&lt;p&gt;Yes, for a custom service you have to implement every one of these functions yourself. However, if you intend to arrive at the same functionality as the BLE Nus service I recommend that you complete the tutorials to gain the understanding, and then rather modify the BLE NUS service to fit the functionality you need instead of writing it from scratch, since this work is mostly already done for you in the NUS service.&lt;br /&gt;Once you have completed the tutorial you can modify a copy of the NUS service to change the UUID, add more services/characteristics, change the type of characteristic, etc.&lt;/p&gt;
[quote user="morpho"] I&amp;#39;m solely doing this for learning purposes and to demonstrate my understanding of the BLE (even tho I am not sure if I should touch BLE stack event.[/quote]
&lt;p&gt;The BLE events that you may register for in your application are actually passed to the application by the SoftDevice (after the application register for a specific event), so by the time the event is delivered to the application the SoftDevice will already be finished with it. I.e you do not need to worry about your application layer logic for the BLE event handlers breaking the SoftDevice. The SoftDevice takes priority over any application layer thread, and will therefore do whatever processing it needs to, whenever it needs to. For your part, this means that you have to account for the fact that the SoftDevice may interrupt your application at any point in the program, but on the plus side you do not need to worry at all about messing things up for the SoftDevice. If any part of this should still be unclear, please let me know so I may try to articulate this better.&lt;/p&gt;
[quote user="morpho"]2) How is the example you linked any different than the NUS example?[/quote]
&lt;p&gt;The tutorial I linked is the tutorial leading up to the &lt;a href="https://github.com/NordicPlayground/nRF5x-custom-ble-service-tutorial"&gt;custom service example&lt;/a&gt;&amp;nbsp;you referenced in your original post. The tutorial I linked is the Beginners guide to Advertising, and next in the series is the &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-services-a-beginners-tutorial"&gt;Beginners guide to Services&lt;/a&gt; and then finally the &lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-characteristics-a-beginners-tutorial"&gt;Beginners guide to Characteristics&lt;/a&gt;&amp;nbsp;- the latter two sound like they might be demonstrating exactly what you seek to achieve - implementing a custom service and characteristics.&lt;/p&gt;
[quote user="morpho"]I see in the example you linked,&amp;nbsp;ble_advdata_manuf_data_t is used that will also contain the advertised data which I didn&amp;#39;t see in the NUS example even though the data is sent there too but to the service.[/quote]
&lt;p&gt;Yes, the first tutorial of the series - the Beginners guide to advertising - demonstrate how you can fill out the advertising payload yourself. This might not be necessary in your custom application later, but it is still beneficial to have a good understanding of the advertising as well so that you may apply filters etc. and thus only target a specific device for connection, for example.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing a custom BLE service and integrating other relevant BLE APIs into the application</title><link>https://devzone.nordicsemi.com/thread/318720?ContentTypeID=1</link><pubDate>Tue, 06 Jul 2021 06:30:57 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:661b8bb4-aec8-4e27-a287-030a0e706957</guid><dc:creator>morpho</dc:creator><description>&lt;p&gt;Basically I want to learn how to make one&amp;#39;s own custom BLE service so I initially played around with the ble_app_uart project where I could connect my phone and be able to send stuff through the NUS via the nRF Connect app and be able to receive it in a COM listener.&lt;br /&gt;I basically want to have a similar behavior integrated into my application but the thing is I have my own custom service which is fairly similar to NUS.&lt;/p&gt;
&lt;p&gt;1) Given I have my own service, would I have to implement APIs like&amp;nbsp;ble_nus_data_send()? I&amp;#39;m solely doing this for learning purposes and to demonstrate my understanding of the BLE (even tho I am not sure if I should touch BLE stack event. Perhaps the idea would be to include files like ble_advertising.h, ble_srv_common.h that has certain APIs (the ones mentioned in the original post) that I could directly invoke in my application?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;2) How is the example you linked any different than the NUS example? I see in the example you linked,&amp;nbsp;ble_advdata_manuf_data_t is used that will also contain the advertised data which I didn&amp;#39;t see in the NUS example even though the data is sent there too but to the service.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Writing a custom BLE service and integrating other relevant BLE APIs into the application</title><link>https://devzone.nordicsemi.com/thread/318699?ContentTypeID=1</link><pubDate>Mon, 05 Jul 2021 19:50:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8a3eecb3-91e7-4632-942a-a4daed01cc8a</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
[quote user=""]From what I&amp;#39;ve heard, you aren&amp;#39;t supposed to be making changes to the BLE stack itself, and rather just write custom services according to your needs.[/quote]
&lt;p&gt;Yes, the SoftDevice implements the BLE stack and handles everything &amp;#39;behind the scenes&amp;#39;, without any need for modification.&lt;/p&gt;
[quote user=""]I currently have written code particularly for initializing a service with custom UUID but then integrating the following APIs&amp;nbsp;seems like a challenge and it became a mess with inclusion of all those library files. What&amp;#39;s the preferred approach?[/quote]
&lt;p&gt;I am not sure I understand your question here - what is the preferred approach to including the different library files to your project? If this is what you are asking, you will need to add the #include at the top of your file, add the path to the header file into your&amp;nbsp;&lt;em&gt;common configuration&amp;nbsp;&lt;/em&gt;&lt;em&gt;Options-&amp;gt;Preprocessor-&amp;gt;User Included Directories,&amp;nbsp;&lt;/em&gt;and finally make sure that the module or library is enabled in the sdk_config.h file for inclusion into the project.&lt;/p&gt;
[quote user=""]This&amp;nbsp;&lt;a href="https://github.com/NordicPlayground/nRF5x-custom-ble-service-tutorial"&gt;example&lt;/a&gt;&amp;nbsp;doesn&amp;#39;t talk about integrating any of the following APIs eh?&amp;nbsp;[/quote]
&lt;p&gt;Have you gone through/followed&amp;nbsp;&lt;a href="https://devzone.nordicsemi.com/nordic/short-range-guides/b/bluetooth-low-energy/posts/ble-advertising-a-beginners-tutorial"&gt;the written tutorials made for this example&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>