[Development skills] Goodbye, those pits of BLE!

Bluetooth, do you usually use it a lot?
Wearing bluetooth earphones to listen to music and watch videos on the way to work
Turn on bluetooth to share personal hotspots with friends
When unlocking a shared bicycle, turn on bluetooth to unlock it quickly
...

BLE—Bluetooth low energy technology, facilitates our life, However, developers have encountered many pits in the development process, especially for novice users, there are really too many pits, which are all caused by Android and iOS systems.


Today, I will share with you an experience in solving the pits of BLE, hoping to help more people.

When using the BLE module in the project, pay attention to the following issues:

❶ Using the sample code Android system to scan Bluetooth devices will not succeed, but Apple will be fine.

✓ Solution: Change serviceUUIDs: ['', ''] to serviceUUIDs: []. If one scan does not come out, you can scan several times.

❷ The device UUID of Android and Apple is different. Android is in xx:xx:xx:xx:xx:xx format, and Apple is in GUID format.

✓ Solution: Just use the UUID you scan to access the device.
❸ The service UUID and service characteristic CharacteristicsUUID of Android and Apple are different (the service UUID and service characteristic CharacteristicsUUID are parent-child relationship).
Android is GUID format, Apple is short format. The number of services scanned by the two is also different. Apple only scans the services that the user can call, and Android scans the system-level services. Generally, the third service of Android is that the user can call.
✓ Solution: Just use the service characteristics UUID of the service UUID obtained by your scan to access it.

❹ The most important point is also the question of why calling old is wrong.

✓ Solution: Regardless of whether you know the device UUID, service UUID, whether Bluetooth is turned on or not. Please be sure to call according to the steps: scan device -> connect device -> get all service UUID

-> all service characteristics UUID corresponding to service UUID. After these steps are completed, the service UUID and the corresponding service characteristic CharacteristicsUUID can be called.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326329619&siteId=291194637