Ordinary Bluetooth scale-independent management of Bluetooth
This chapter is for users who have a certain understanding of Bluetooth and have their own Bluetooth framework in the APP.
If you are not familiar with Bluetooth, or do not have your own Bluetooth framework, it is not recommended to use this method to access, otherwise it will increase the cost of access
One、Start Bluetooth Scan
The customer starts and stops the Bluetooth scan by himself, and passes the scanned device information to our SDK (call QNBleApi.buildDevice),-if-it-belongs-to-our-device,-the-sdk-qnbledevice will be built, if it is not our device, it will return null/nil.
Usually the bluetooth name of our device is QN-Scale or QN-Scale1, and we can also filter our products by this bluetooth name After obtaining the target device, it is up to the APP to decide whether to stop scanning. We usually recommend that you stop Bluetooth scanning before connecting.
2. Create Bluetooth protocol proxy class
Create your own Bluetooth protocol proxy class QNBleProtocolDelegate and implement all its methods. The specific way of implementation can be Demo
three、Create Bluetooth protocol processing class
Use QNBleApi.buildProtocolHandler-to-create-protocol-handler-class-qnbleprotocolhandler
Four、Connect Bluetooth yourself
Connected devices using system API or own Bluetooth framework.
The logic of this part is handled by the APP itself
Fives、Discovery Service、Enable eigenvalue
Our scale uses two sets of services, and one device will only contain one set. The APP needs to traverse all services to find one set of service IDs. If one set is found, the feature values that need to be called back are enabled according to the feature values in the following table.
After enabling the feature value, call QNBleProtocolHandler 's prepare and pass the UUID of the service used
The first set
The service ID is: FFE0
Several characteristic values are used below them, as follows:
UUID | Attributes | Explanation |
---|---|---|
FFE1 | Notify | Main data callback feature values |
FFE3 | Write | The main data is written to the characteristic value |
FFE2 | Indicate | The secondary data callback feature value. Note that the attribute of this is Indicate. The Android enable may be a little different. |
FFE4 | Write | Minor data callback feature value |
2A19 | Read | Charging scale electric quantity characteristic value |
The UUID of the characteristic value here is only provided in the form of 32-bit, Android needs to use 128-bit, then splice it by itself
For example, the 128 bits of FFE0 are: 0000ffe0-0000-1000-8000-00805f9b34fb
The second set
The service ID is: FFF0
There are only two characteristic values below it, one for data callback and one for writing data
UUID | Attributes | Explanation |
---|---|---|
FFF1 | Notify | Data callback feature value |
FFF2 | Write | Data write characteristic value |
2A19 | Read | Charging scale electric quantity characteristic value |
Data interaction
After the feature value is enabled, you can receive the data uploaded by the scale.
After receiving the callback data from the scale, the APP sends it to the SDK for analysis through the method QNBleProtocolHandler.onGetBleData,-and-the-parsed-data-will-pass-qnscaledatalistener callback.
In addition, if you need to write data, you will use QNBleProtocolDelegate.writeCharacteristicValue to let the APP write for you.
Measurement completed
After the measurement is completed, the complete data will be called back through QNScaleDataListener, after which the scale will actively disconnect.
The next time you connect, you need to recreate QNBleProtocolDelegate and QNBleProtocolHandler