Files
esp-nimble-cpp/md__usage__tips.html
2025-12-27 15:37:12 +00:00

169 lines
10 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.9.8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>esp-nimble-cpp: Usage Tips</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtreedata.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectalign">
<div id="projectname">esp-nimble-cpp<span id="projectnumber">&#160;2.3.3</span>
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.9.8 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "search/",'.html');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(document).ready(function(){initNavTree('md__usage__tips.html',''); initResizable(); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div><div class="header">
<div class="headertitle"><div class="title">Usage Tips</div></div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p><a class="anchor" id="usage-tips"></a> </p>
<h1><a class="anchor" id="threadsafety"></a>
Threadsafety</h1>
<p>This library is threadsafe. Attribues can be manipulated freely.</p>
<h1><a class="anchor" id="do-not-delete-client-instances-unless-necessary-or-unused"></a>
Do not delete client instances unless necessary or unused</h1>
<p>When a client instance has been created and has connected to a peer device and it has retrieved service/characteristic information it will store that data for the life of the client instance. <br />
If you are periodically connecting to the same devices and you have deleted the client instance or the services when connecting again it will cause a retrieval of that information from the peer again. <br />
This results in significant energy drain on the battery of the devices, fragments heap, and reduces connection performance. <br />
</p>
<p>Client instances in this library use approximately 20% of the original bluedroid library, deleting them will provide much less gain than it did before. <br />
</p>
<p>It is recommended to retain the client instance in cases where the time between connecting to the same device is less than 5 minutes. <br />
<br />
<br />
</p>
<h1><a class="anchor" id="only-retrieve-the-services-and-characteristics-needed"></a>
Only retrieve the services and characteristics needed</h1>
<p>As a client the use of <code>NimBLEClient::getServices</code> or <code>NimBLERemoteService::getCharacteristics</code> and using <code>true</code> for the parameter should be limited to devices that are not known. <br />
Instead <code>NimBLEClient::getService(NimBLEUUID)</code> or <code>NimBLERemoteService::getCharacteristic(NimBLEUUID)</code> should be used to access certain attributes that are useful to the application. <br />
This reduces energy consumed, heap allocated, connection time and improves overall efficiency. <br />
<br />
<br />
</p>
<h1><a class="anchor" id="check-return-values"></a>
Check return values</h1>
<p>Many user issues can be avoided by checking if a function returned successfully, by either testing for true/false such as when calling <code>NimBLEClient::connect</code>, <br />
or nullptr such as when calling <code>NimBLEClient::getService</code>. The latter being a must, as calling a method on a nullptr will surely result in a crash. <br />
Most of the functions in this library return something that should be checked before proceeding. <br />
<br />
<br />
</p>
<h1><a class="anchor" id="persisted-bonds-can-be-lost-due-to-low-max_cccds"></a>
Persisted bonds can be lost due to low MAX_CCCDS</h1>
<p>The symptom: CONFIG_BT_NIMBLE_MAX_BONDS is set to N, but a smaller number of bonds is preserved, perhaps even a single bond. The limitation of persisted bonds can be observed via NimBLEDevice::getNumBonds(). The number may not reach CONFIG_BT_NIMBLE_MAX_BONDS.</p>
<p>Cause: For each bond, NimBLE persists each of the CCCD (client characteristic configuration descriptor) values that have been subscribed to by the client. If CONFIG_BT_NIMBLE_MAX_CCCDS is too low, the older CCCD values are overwritten by the newer ones. The loss of the older CCCDs values results in those bonds being lost.</p>
<p>Fix: Increase CONFIG_BT_NIMBLE_MAX_CCCDS. These take approximately 40 bytes in NVS, 2 bytes for the CCCD value and the NVS metadata overhead. The value of CONFIG_BT_NIMBLE_MAX_CCCDS should conservatively be no less than (CONFIG_BT_NIMBLE_MAX_BONDS * {maximum number of characteristics that can be subscribed to}).</p>
<h1><a class="anchor" id="device-local-name"></a>
Device 'Local Name'</h1>
<p>'Local name' refers to how the device is seen and displayed.</p>
<p>A devices 'Local name' can be thought of as coming from two places, the <em>Advertising "Local name"</em> and the <em>the GATT Device Name</em>.</p>
<h2><a class="anchor" id="advertising-local-name"></a>
Advertising "Local name"</h2>
<p>Field found in the advertising data payload. Value is set via <a class="el" href="class_nim_b_l_e_advertising.html#a7fb4b74eb7acb1f46e57ff772baccd88" title="Set the advertised name of the device.">NimBLEAdvertising::setName()</a>.</p>
<h2><a class="anchor" id="gatt-device-name"></a>
GATT Device Name</h2>
<p>Characteristic UUID 0x2A00 in the Generic Access service. Set via <a class="el" href="class_nim_b_l_e_device.html#a2e8bb71daabbffd9eab8787493a45ce7" title="Initialize the BLE environment.">NimBLEDevice::init()</a> or <a class="el" href="class_nim_b_l_e_device.html#aaa64b6baff54c010eb8b4d0ba338cc01" title="Set the BLEDevice name.">NimBLEDevice::setDeviceName()</a>.</p>
<p>This characteristic is read <b>after</b> connecting to the device.</p>
<h2><a class="anchor" id="important-considerations"></a>
Important considerations</h2>
<ul>
<li>OSes cache the <em>'GATT Device Name'</em>.</li>
<li>OSes update the device name based on the <em>'GATT Device Name'</em> after connecting to a device. This means that if you set the <em>Advertising 'Local name'</em> to "ABCD" but the <em>'GATT Device Name'</em> to "12345", the device will be seen as "ABCD" until connecting to the device, at which time the devices name will change to "12345".</li>
<li>If no <em>'Advertising "Local name"'</em> is set, OSes, such as iOS, may display the devices name as 'Unnamed' until the device is connected to, at which time the <em>'GATT Device Name'</em> is read and used instead.</li>
</ul>
<p>It is recommended that both <em>'Advertising "Local name"'</em> <b>and</b> <em>'GATT Device Name'</em> be set appropriately, after considering the above described behavior.</p>
<h1><a class="anchor" id="there-will-be-bugs---please-report-them"></a>
There will be bugs - please report them</h1>
<p>No code is bug free and unit testing will not find them all on it's own. If you encounter a bug, please report it along with any logs and decoded backtrace if applicable. <br />
Best efforts will be made to correct any errors ASAP. <br />
</p>
<p>Bug reports can be made at <a href="https://github.com/h2zero/NimBLE-Arduino/issues">https://github.com/h2zero/NimBLE-Arduino/issues</a> or <a href="https://github.com/h2zero/esp-nimble-cpp/issues">https://github.com/h2zero/esp-nimble-cpp/issues</a>. <br />
Questions and suggestions will be happily accepted there as well. </p>
</div></div><!-- contents -->
</div><!-- PageDoc -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.9.8 </li>
</ul>
</div>
</body>
</html>