1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 |
Direct-BT LE and BREDR LibraryGit RepositoryThis project's canonical repositories is hosted on Gothel Software. GoalsThis project aims to create a clean, modern and easy to use API for Bluetooth LE and BREDR, fully accessible through C++, Java and other languages. OverviewDirect-BT provides direct Bluetooth LE and BREDR programming, offering robust high-performance support for embedded & desktop with zero overhead via C++ and Java. Below you can find a few notes about Direct-BT Origins. You will find a detailed overview of Direct-BT (C++) and the same in the Java API. Direct-BT supports a fully event driven workflow from adapter management via device discovery to GATT programming. using its platform agnostic HCI, L2CAP, SMP and GATT client-side protocol implementation. AdapterStatusListener allows listening to adapter changes and device discovery and BTGattCharListener to GATT indications and notifications. Direct-BT may be utilized via its C++ API or via its Java API. Direct-BT is exposed via the following native libraries
Direct-BT is C++17 conform and shall upgrade towards C++20 when widely available on all target platforms. Some elaboration on the implementation details
Implementation Status
To support other platforms than Linux/BlueZ, we will have to
Supported PlatformsThe following platforms are tested and hence supported Debian 12 Bookworm (GNU/Linux)
Debian 11 Bullseye (GNU/Linux)
Debian 10 Buster (GNU/Linux)
Ubuntu 18.04 (GNU/Linux)
Tested Bluetooth Adapter
Please check the adapter list for more details. Using Direct-BT ApplicationsSystem PreparationsSince Direct-BT is not using a 3rd party Bluetooth client library or daemon/service, they should be disabled to allow operation without any interference. To disable the BlueZ D-Bus userspace daemon bluetoothd via systemd, you may use the following commands.
Required Permissions for Direct-BT ApplicationsSince Direct-BT requires root permissions to certain Bluetooth network device facilities, non-root user require to be granted such permissions. For GNU/Linux, there permissions are called capabilities. The following capabilites are required
On Debian 11 we can use package Launch as rootIn case your platform lacks support for mentioned
Launch as user using setcapTo launch your Direct-BT application as a user, you may set the
required
Launch as user via capshAlternatively one can set the required
Notable here is that capsh needs to be invoked by root to hand over the capabilities and to pass over the cap_net_raw,cap_net_admin+eip via --addamb=... it also needs cap_setpcap,cap_setuid,cap_setgid+ep beforehand. Launch ExamplesThe capsh method (default), setcap and root method is being utilized in See Examples below ... Programming with Direct-BTAPIExposed API closely follows and references the Bluetooth Specification. API DocumentationUp to date API documentation can be found:
A guide for getting started with Direct-BT on C++ and Java may follow up. Java Specificsorg.direct_bt.BTFactory provides a factory to instantiate the initial root org.direct_bt.BTManager, using the Direct-BT implementation. ExamplesDirect-BT C++ examples are available, demonstrating the event driven and multithreading workflow:
Direct-BT Java examples are availble, demonstrates the event driven and multithreading workflow:
Building Direct-BTThis project also uses the Jau Library as a git submodule, which has been extracted earlier from this project to better encapsulation and allow general use. Direct-BT does not require GLib/GIO nor shall the BlueZ userspace service bluetoothd be active for best experience. To disable the bluetoothd service using systemd:
Build Dependencies
Installing build dependencies on Debian (10 or 11):
Build ProcedureThe following is covered with a convenient build script. For a generic build use:
The install target of the last command will create the include/ and lib/ directories with a copy of the headers and library objects respectively in your build location. Note that doing an out-of-source build may cause issues when rebuilding later on. Our cmake configure has a number of options, cmake-gui or ccmake can show you all the options. The interesting ones are detailed below: Changing install path from /usr/local to /usr
Building debug build:
Disable stripping native lib even in non debug build:
Override default javac debug arguments
Building debug and instrumentation (sanitizer) build:
Using clang instead of gcc:
Cross-compiling on a different system:
To build Java bindings:
To build examples:
To build documentation run:
Cross BuildAlso provided is a cross-build script using chroot into a target system using QEMU User space emulation and Linux kernel binfmt_misc to run on other architectures than the host. You may use our pi-gen branch to produce a Raspi-arm64, Raspi-armhf or PC-amd64 target image. Build StatusWill be updated Support & SponsorshipDirect-BT is the new implementation as provided by Gothel Software and Zafena ICT. If you like to utilize Direct-BT in a commercial setting, please contact Gothel Software to setup a potential support contract. Common issuesIf you have any issues, please go through the Troubleshooting Guide. If the solution is not there, please search for an existing issue in our Bugzilla DB, please contact us for a new bugzilla account via email to Sven Gothel [email protected]. Contributing to Direct-BTYou shall agree to Developer Certificate of Origin and Sign-off your code, using a real name and e-mail address. Please check the Contribution document for more details. Historical NotesDirect-BT OriginsDirect-BT development started around April 2020, initially as an alternative TinyB Java-API implementation. The work was motivated due to strict performance, discovery- and connection timing requirements, as well as being able to handle multiple devices concurrently using a real-time event driven low-overhead architecture. Zafena's POC-Workstation was originally implemented using TinyB and hence the D-Bus layer to the BlueZ client library. Real time knowledge when devices are discovered and connected were not available and cloaked by the caching mechanism. Advertising package details were not exposed. Connections attempts often took up to 10 seconds to be completed. Detailed information from the Bluetooth layer were inaccessible including detailed error states. Fine grained control about discovery and connection parameter were not exposed by the D-Bus API and hence TinyB. In January 2020 we tried to remedy certain aspects to meet our goals, but concluded to require direct Bluetooth control via the BlueZ/Linux kernel implementation. Direct-BT was born. We then implemented data types for
Last but not least we added
Today, Direct-BT's C++ and Java API match 1:1 and shall not contain legacy API artifacts. TinyB Removal since version 2.3Heading towards feature completion for Direct-BT, we completely removed the previously refactored TinyB. Detailing full Bluetooth support in Direct-BT including the addition of GATT-Server support rendered TinyB an obstacle for the public API. However, TinyB inspired us and was a great reference implementation while developing and testing Direct-BT. We like to thank the authors of TinyB for their great work helping others and us moving forward. Thank you! TinyBTinyB was developed by the Intel Corporation and its main authors were
TinyB was licensed under the The MIT License (MIT) and the Intel Corporation holds its copyright from the year 2016. Changes3.0.0 Direct-BT Maturity (Bluetooth LE)
2.5.1
2.5.0
2.4.0
2.3.0
2.2.14
2.2.13
2.2.11
2.2.5
2.2.4
2.2.00
2.1.33
2.1.30
2.0.0
0.5.0
0.4.0
|