2020. 2. 17. 16:22ㆍ카테고리 없음
Android is leading market share in the mobile phone space and with the rapid growing of IoT/connected devices, we are seeing more and more innovative applications using Bluetooth technology show up in Google Play. With even more teams building Bluetooth apps on Android, some basic knowledge about the Bluetooth stack and APIs will be essential to developers. Understanding the SDK and the StackWith just a few lines of high-level API calls, you can quickly scan around and connect to the target device using Bluetooth (If you want to understand where to start using Bluetooth with low energy in your app or simply want a boilerplate skeleton code, you can always get those from our ).To move your app’s performance to the next level, a good understanding of Bluetooth APIs will be helpful. From the first introduction of Bluetooth with low energy features in version 4.3 API Level: 18, the SDK and the Bluetooth Stack on Android have evolveda lot. A new package of android.bluetooth.le was added from API Level: 21. For some Bluetooth operations you may have more than one way of doing it. With that, you always want to check the user’s OS version/API level to better understand the capabilities from the Bluetooth SDK.
![Bluetooth low energy peripheral adapter Bluetooth low energy peripheral adapter](https://binary-studio.com/wp-content/uploads/2015/07/2.png)
The feature set on different physical handsets may also vary. One example is BluetoothLeAdvertiser class. It is one of the “HAL-enabled features” not available on all Android phones. You need to specifically call BluetoothAdapter.isMultipleAdvertisementSupported to determine its availability on that very device.
Enable the Bluetooth HCI log on the device via Developer Options—also from the SDK, there is a helpful tool called the “Bluetooth HCI snoop log” (available after version 4.4). It works like a hook in the stack to capture all the HCI packets in a file. For most Android devices, the log file is at /sdcard/btsnoophci.log. This details the steps on how to set up the tool and retrieve the information. Third party tools on Android—similar to the popular Bluetooth GATT/GAP tool “Lightblue” on iOS, a very useful tool called “nRF Master Control Panel” by Nordic Semiconductor is a powerful Android tool. This tool can get you a lot of information as a GAP/GATT client.
It can also emulate an Android GATT server. Even better, it can show you the real-time RSSI graph of the advertisers in the range. You can find the tool on Google Play.Understanding Connection IntervalsConnection intervals for Bluetooth are a group of important parameters for your app. To balance power efficiency and performance, you need to fine-tune those parameters for your specific use case.At the GAP (Generic Access Profile) layer, the peripheral advertises and the central listens. Then the central device initiates the connection and the peripheral accepts the connection request. When initiating the Bluetooth connection, the central device sends out a connection request (connectreq) which contains a set of connection parameters:.
Connection interval. Slave latency. Management TimeoutIn the initial request, the connection interval should be set to initialconn-interval and slave latency should be set to zero. On Android devices, the initialconninterval (the initial value for connection interval when the connection is set up) is set to 7.5ms, which is the minimum that the spec allows. With the 7.5ms interval, we can get the highest throughput but it’s very power hungry (the smaller interval means more frequent connection event, which will result in more data being transmitted, at the cost of more power).
Once the connection is set up and all the initial actions on the central side are complete, either the central or peripheral can request a connection parameter update. This request is a new proposal of the parameters for the counterpart to consider. Once the proposal is accepted, the central will start the connection parameter update procedure. On Android, this procedure is implemented in the BluetoothGatt class.
A method called will be called to update the connection parameters. As of now in API Level: 23, the update method supports three sets of parameters:. CONNECTIONPRIORITYBALANCED.
CONNECTIONPRIORITYHIGH. CONNECTIONPRIORITYLOWYou can see the process here:The target device may also send requests to Android in the hope of changing the intervals to its preference. But it’s always the decision of the master role (the device who initiate the connection at the link layer level) on the intervals they will be settled on. Understanding the Packet and ProcedureAnother powerful tool for a Bluetooth developer is the protocol analyzer (“the sniffer”).
I used the ComProbe BPA Low Energy Bluetooth Protocol Analyzer for this article. It can easily tell me how the wireless communication works or what went wrong.When I am unsure if the Android stack and the API passed me the correct data, I will start the analyzer and check the details from different levels. The following capture shows the details of “Read by type” operation. I can go to the “Handle value pair” and debug step-by-step on that very handle. Debugging an Invisible Activity or a Background ServiceIt’s not always guaranteed that your app will be running in the foreground. Any higher priority tasks can move activity into invisible mode.
Sometimes Bluetooth operations are implemented in a service running in the background. Most of the time, Bluetooth may operate differently when not in the foreground. The scenario of running in the background or a service needs to be tested and verified.
Almost all Android debuggers support the feature of attaching to a specific process. All you need to do is to find out the process ID of your app and attach your debugger to this specific process.
The now-defunct Wibree logoIn 2001, researchers at determined various scenarios that contemporary wireless technologies did not address. The company began developing a wireless technology adapted from the Bluetooth standard which would provide lower power usage and cost while minimizing its differences from Bluetooth technology. The results were published in 2004 using the name Bluetooth Low End Extension.After further development with partners, in particular and within the European project MIMOSA, and actively promoted and supported by since its early stage, the technology was released to the public in October 2006 with the brand name Wibree.
After negotiations with Bluetooth SIG members, an agreement was reached in June 2007 to include Wibree in a future Bluetooth specification as a Bluetooth ultra low power technology.The technology was marketed as Bluetooth Smart and integration into version 4.0 of the Core Specification was completed in early 2010. The first smartphone to implement the 4.0 specification was the, released in October 2011. A number of other manufacturers released Bluetooth Low Energy Ready devices in 2012.The Bluetooth SIG officially unveiled Bluetooth 5 on 16 June 2016 during a media event in London.
One change on the marketing side is that they dropped the point number, so it now just called Bluetooth 5 (and not Bluetooth 5.0 or 5.0 LE like for Bluetooth 4.0). This decision was made allegedly to 'simplifying marketing, and communicating user benefits more effectively'. On the technical side, Bluetooth 5 will quadruple the range by using increased transmit power or coded physical layer, double the speed by using optional half of the symbol time compared to Bluetooth 4.x, and provide an eight-fold increase in data broadcasting capacity by increasing the advertising data length of low energy Bluetooth transmissions compared to Bluetooth 4.x, which could be important for applications where nodes are connected throughout a whole house.The Bluetooth SIG released Mesh Profile and Mesh Model specifications officially on 18 July 2017. Enables using Bluetooth Low Energy for many-to-many device communications for home automation, sensor networks and other applications. Applications Borrowing from the original Bluetooth specification, the Bluetooth SIG defines several — specifications for how a device works in a particular application — for low energy devices. Manufacturers are expected to implement the appropriate specifications for their device in order to ensure compatibility. A device may contain implementations of multiple profiles.The majority of current low energy application profiles are based on the Generic Attribute Profile (GATT), a general specification for sending and receiving short pieces of data, known as attributes, over a low energy link.
The profile is an exception to this rule, being based on the General Access Profile (GAP). Mesh profiles Bluetooth mesh profiles use Bluetooth Low Energy to communicate with other Bluetooth Low Energy devices in the network.
Each device can pass the information forward to other Bluetooth Low Energy devices creating a 'mesh' effect. For example, switching off an entire building of lights from a single smartphone.
Android Bluetooth Low Energy Peripheral Mode
MESH (Mesh Profile) — for base mesh networking. MMDL — for application layer definitions. Term 'model' is used in mesh specifications instead of 'profile' to avoid ambiguities.Health care profiles There are many profiles for Bluetooth Low Energy devices in healthcare applications. Bluetooth Low Energy chipset power consumption profiles with different configuration parameters, as per The Hitchhikers Guide to iBeacon Hardware by Aislelabs.Bluetooth Low Energy is designed to enable devices with low power consumption. Several chipmakers including, and have introduced their Bluetooth Low Energy optimized chipsets over the last few years. Devices with peripheral and central roles have different power requirements. A study by beacon software company, reported that peripherals, such as proximity beacons, usually function for 1–2 years with a 1,000mAh coin cell battery.
This is possible because of power efficiency of Bluetooth Low Energy protocol which only transmits small packets as compared to Bluetooth Classic which is also suitable for audio and high bandwidth data.In contrast, a continuous scan for the same beacons in central role can consume 1,000 mAh in a few hours. Android and iOS devices also have very different battery impact depending on type of scans and number of Bluetooth Low Energy devices in the vicinity. With the newer chipsets and advances in software, both Android and iOS phones now have negligible power consumption in real-life Bluetooth Low Energy use scenarios. See also. /. (IPS).
(UWB).Notes. Archived from on 10 March 2017. Archived from on 24 October 2014. Retrieved 21 November 2014. Bluetooth.com. (Press release).
24 October 2011. Archived from on 3 February 2015. Retrieved 31 January 2016.
Archived from on 24 July 2015. Retrieved 31 January 2016. Www.bluetooth.com. Genuth, Iddo (16 November 2006).
The Future of Things. Archived from on 8 November 2012. Honkanen, M.; Lappetelainen, A.; Kivekas, K. 2004 IEEE Radio and Wireless Conference 19–22 September 2004. Retrieved 27 April 2018.
MIMOSA FP6 project. Archived from on 4 August 2016. Retrieved 18 August 2016.
Retrieved 18 August 2016. 4 October 2006.
Retrieved 27 April 2018. (PDF) (Press release). 12 June 2007. Archived from (PDF) on 16 June 2007.
Reynolds, Melanie (12 June 2007). Reed Business Information Limited. Archived from on 7 September 2008. Retrieved 9 September 2008.
Pollicino, Joe (25 October 2011). Retrieved 17 April 2018. O'Brien, Terrence (12 October 2011). Retrieved 9 February 2014. 10 June 2016.
Retrieved 8 November 2017. Archived from on 9 December 2018. Retrieved 8 November 2017. Archived from on 8 September 2017.
Retrieved 20 July 2017. Bluetooth SIG. bluetooth. M2M / IoT hints and tips. 7 March 2011. Retrieved 8 November 2017.
Retrieved 8 November 2017. Retrieved 2 June 2018. Brynte (4 May 2014). Retrieved 18 May 2014. wdg-dev-content. Android Developers.
Press.blackberry.com. Gustavo Padovan (22 February 2013). As the MGMT interface is the only one to support the new Bluetooth Low Energy devices, BlueZ developers decided to drop support for the old interface once MGMT was completed.
As a result, you need to be running Linux Kernel 3.4 or newer to use BlueZ 5. Rowebots.com. Bluetooth Special Interest Group, April 2011. Bluetooth 5 & BLE: Achieving maximum throughput. Bluetooth SIG.
Archived from on 14 February 2014. Kindt, Philipp H. CodeOcean. Kindt, P. H.; Saur, M.; Balszun, M.; Chakraborty, S.
'Neighbor Discovery Latency in BLE-Like Protocols'. IEEE Transactions on Mobile Computing. PP (99): 617–631.:. See for example Apple's framework.
See sec 2.5.1 of the Bluetooth 4.0 Core Specification. 3 October 2014. Retrieved 7 October 2014. 4 October 2014. Retrieved 11 October 2014.
Bluetooth Low Energy Android Devices
14 August 2014. Retrieved 7 October 2014. 14 August 2014.
Retrieved 18 August 2014.Further reading. 'Bluetooth 4.0 Core Specification' – GATT is described in full in Volume 3, Part GExternal links. Gomez, Carles; Oller, Joaquim; Paradells, Josep (29 August 2012). 12 (9): 3.