QNBleApi
Entrance class
Method
initSdk
Initialize the SDK according to appid and verify the appid and configuration file. This method will also load the relevant configuration in the configuration file.
This method only needs to be called once, not multiple times. It is recommended that Android be called in Application.onCreate, and iOS should be called under AppDelegate didFinishLaunchingWithOptions. This method only performs lightweight operations, and the time-consuming operations are all performed asynchronously, and will not affect the startup speed of the APP.
Normally, this method sends a request to our server to update the configuration in the configuration file, such as updating the algorithm, updating the index, and adding new models. This can achieve the effect of online upgrade configuration. If you clearly do not want to have this feature, you can close this function with our business communication (that is, change the SDK to offline mode). In addition, if there is no network, after the request fails, there will be no impact, the SDK will continue to use the last configuration.
Note: The
123456789appid in the demo is the test id, which has instability and random variability. After reaching an agreement with Yolanda, the access provider can obtain an independent and stable appid. Remember to test Id can not be used in the online application market
Parameters
| Name | Type | Description |
|---|---|---|
| appId | String | The app_id provided by the company to the customer is verified by the local initialization data packet, and Android iOS shares the same appid |
| firstDataFile | String | The file path of the configuration file can be transmitted in the form of uri or the full path of the file. The file contains |
| callback | QNResultCallback | Android is the interface, IOS uses the block or closure) callback method, and returns the initialization result. Refer to the attached table for error codes. |
getCurSystemBleState
Get the current system Bluetooth status
return value
Type: int
Current System Bluetooth Status
setSysBleStateListener
Set system Bluetooth status callback
Parameters
| Name | Type | Description |
|---|---|---|
| listener | QNBleStateListener | The listener contains a method to monitor the Bluetooth status of the system. |
setBleDeviceDiscoveryListener
Set the scan callback object. When there is a scan result, it will be returned in the set monitoring method. The SDK only supports one callback object. Repeated settings will overwrite the previous results. When it is not needed, it needs to be reset to null, otherwise a memory leak may occur.
Parameters
| Name | Type | Description |
|---|---|---|
| listener | QNBleDeviceDiscoveryListener | The listener contains a method that will callback in this object when the device is scanned. |
setDataListener
Set up data transmission listener
Parameters
| Name | Type | Description |
|---|---|---|
| listener | QNScaleDataListener or QNUserScaleDataListener | Measurement data monitoring interface, all data will be called back in it |
setBleKitchenListener
Set up a Bluetooth kitchen scale listener
Parameters
| name | Types of | Explanation |
|---|---|---|
| listener | QNBleKitchenListener | Bluetooth kitchen scale listener |
setLogListener
Set the monitoring of log information
Parameters
| Name | Type | Description |
|---|---|---|
| listener | QNLogListener | Log information monitoring |
startBleDeviceDiscovery
Start scanning for Bluetooth devices and only return to Yolanda's device. It automatically stops when it encounters an error or Bluetooth is turned off.
The scan result is called back in QNBleDeviceDiscoveryListener
For some configuration behavior of scanning, please refer to getConfig-and-qnconfig
Parameters
| Name | Type | Description |
|---|---|---|
| callback | QNResultCallback | Callback object, returns whether the call to start scanning is successful |
stopBleDeviceDiscovery
To stop scanning Bluetooth devices, this method calls the system's stop scanning method. If scanning is not started, you also need to call stop scanning to ensure that there will be no more callbacks for scanning objects after calling this method.
Parameters
| Name | Type | Description |
|---|---|---|
| callback | QNResultCallback | Callback object, return whether the call to stop scanning is successful |
connectDevice
Connect the Yolanda Bluetooth device. The connection process will be called back in QNBleConnectionChangeListener, and the measurement data will be called back in QNScaleDataListener
Parameters
| Name | Type | Description |
|---|---|---|
| device | QNBleDevice | Bluetooth device to be connected. |
| user | QNUser | When connecting the device, the user model used includes userId and user information. Created by buildUser |
| callback | QNResultCallback | Returns whether the connection operation is successfully called (not the connection is successful) |
connectUserScaleDevice
Connect the Yolanda User Scale device. The connection process will be called back in QNBleConnectionChangeListener, and the measurement data will be called back in QNScaleDataListener
Parameters
| Name | Type | Description |
|---|---|---|
| device | QNBleDevice | Bluetooth device to be connected. |
| config | QNUserScaleConfig | Configuration items when connecting to the user scale device |
| callback | QNResultCallback | Returns whether the connection operation is successfully called (not the connection is successful) |
connectHeightScaleDevice
Connect to the Yolanda height-stadiometer integrated scale device. The connection process will be callback in QNBleConnectionChangeListener, and the measurement data will be callback in QNScaleDataListener.
Parameters
| Name | Type | Description |
|---|---|---|
| device | QNBleDevice | The Bluetooth device that needs to be connected. |
| config | QNHeightDeviceConfig | Configuration items when connecting the height-stadiometer integrated scale device. |
| callback | QNResultCallback | Returns whether the connection operation was called successfully (not whether the connection was successful). |
connectBleKitchenDevice
To link the Bluetooth kitchen scale, the device object must be the Bluetooth kitchen scale device object returned by the search, the link method is only valid for the Bluetooth kitchen scale
Parameters
| Name | Type | Description |
|---|---|---|
| device | QNBleKitchenDevice | Bluetooth kitchen scale equipment |
| callback | QNResultCallback | Returns whether the link operation was successful |
setBleKitchenDeviceConfig
To set the information of the Bluetooth kitchen scale, the setting is valid when the SDK and the Bluetooth kitchen scale remain linked.
Parameters
| Name | Type | Description |
|---|---|---|
| config | QNBleKitchenConfig | Bluetooth kitchen scale setting information |
disconnectDevice
Disconnect the connected Yolanda Bluetooth device. The process of disconnecting will be called back in QNBleConnectionChangeListener
Parameters
| Name | Type | Description |
|---|---|---|
| device/mac | QNBleDevice/String | Need to disconnect the Bluetooth device or mac address, these two parameters only need to wear one |
| callback | QNResultCallback | Returns whether the connection operation is successfully called (not the connection is successful) |
getConfig
Get the current settings of SDK
return value
Types of: QNConfig
SDK setting object, the setting method is also done through QNConfig
convertWeightWithTargetUnit
Convert the weight into the specified unit according to the weight provided in kg
St is not supported, if st is passed, the value of lb will be returned directly, that is, if lb or st is returned, the APP needs to directly convert the unit of British stone, 1st = 14lb, for example, 145.2lb will be displayed as 10 st 5.2 lb.
Parameters
| Name | Type | Description |
|---|---|---|
| kgWeight | double | Weight in kilograms |
| unit | int | 0 is kg, the default value 1 is lb, pound, all scales can support this unit 2 is kg. If the scale does not support it, kg will be displayed |
return value
Type: String
Returns the value in the specified unit
buildDevice
Factory method for creating SDK Bluetooth objects to help support customers
Parameters
android
| Name | Type | Description |
|---|---|---|
| device | BluetoothDevice | Call the system scan and return the Bluetooth object |
| rssi | int | Call the system scan and return the signal strength |
| scanRecord | byte[] | Call the system scan and return the Bluetooth broadcast data |
| callback | QNResultCallback | Returns whether the operation of creating a device object is successful, and if it is not successful, an error code and an error reason are returned. |
ios
| Name | Type | Description |
|---|---|---|
| peripheral | CBPeripheral | Peripheral objects |
| advertisementData | [String: Any] | Bluetooth broadcast data |
| callback | QNResultCallback | Returns whether the operation of creating a device object is successful, and if it is not successful, an error code and an error reason are returned. |
return value
Type QNBleDevice
Directly return the Yolanda device object created according to the parameters, or NULL if the creation is not successful
buildProtocolHandler
Create a Bluetooth protocol processor to help customers manage their Bluetooth connections
To manage the Bluetooth connection yourself, you need to have a certain understanding of the Bluetooth connection related APIs, and use it with caution
Parameters
| Name | Type | Description |
|---|---|---|
| device | QNBleDevice | The scale device to be connected can be created with buildDevice |
| user | QNUser | The user model used can be created with buildUser |
| delegate | QNBleProtocolDelegate | Auxiliary class of protocol processing class to assist in the operation of Bluetooth |
| callback | QNResultCallback | Returns whether the operation was successful |
return value
Type QNBleProtocolHandler
If the creation fails, null/nil will be returned. And return an error code in callback.
generateScaleData
Generate measurement data, if the parameter is abnormal, the method will return NUL
This method only supports wsp devices
Parameters
| Name | Type | Description |
|---|---|---|
| user | QNUser | The user to which the data belongs |
| modeId | String | Model identification |
| weight | Double | Weight in kg |
| resistance | int | 50 impedance value |
| secResistance | int | 500 impedance value |
| heartRate | int | Heart rate value, or 0 if none |
| measureTime | Date | measure time |
| hmac | String | Related data signature |
return value
Type: QNScaleData
On error, return NULL
physiqueCalculation
Calculate the user's physical fitness data. If the Physical fitness calculation function option is not enabled in the SDK configuration information, the method will return NUL
Parameters
| Name | Type | Description |
|---|---|---|
| user | QNUser | The user to which the data belongs |
| weight | Double | Weight in kg |
| area | Int | User's region 0: Other ; 1: Asia |
| measureTime | Date | measure time |
return value
Type: QNScaleData
On error, return NULL
switchUserScaleUser
After the user scale device is successfully connected, the linked user information will be updated, which will be called back in QNUserScaleDataListener, and the measurement data will be called back in QNScaleDataListener
Parameters
| Name | Type | Description |
|---|---|---|
| user | QNUser | User Info |
| callback | QNResultCallback | Returns whether the call to update the user information of the scale is successful (not that the user information of the scale has been updated) |
updateUserScaleIdentifyWeight
Used to update the user scale to identify the user's weight
Parameters
| Name | Type | Description |
|---|---|---|
| weight | double | weight |
| callback | QNResultCallback | Returns whether the update user scale operation is called successfully |
deleteScaleUsers
Used to delete the user information of the user scale
Parameters
| Name | Type | Description |
|---|---|---|
| indexList | [int] | user index array |
| callback | QNResultCallback | Returns whether the call to delete the user information on the scale is successful or not |
Bluetooth ruler api
setBleRulerListener
Set up a bluetooth ruler listener
Parameters
| Name | Type | Description |
|---|---|---|
| listener | QNBleRulerListener | Bluetooth ruler listener |
connectRulerDevice
connect bluetooth ruler
Parameters
| Name | Type | Description |
|---|---|---|
| device | QNBleRulerDevice | Bluetooth ruler |
| callback | QNResultCallback | Returns whether the call to the connect method was successful |
readAuthDeviceInfoList
Read the list of authorized device information
return value
Device info set
calculateScaleDataByHmac
Recalculate measurement data. If the parameters are abnormal, this method will return NULL.
Parameters
| Name | Type | Description |
|---|---|---|
| qnUser | QNUser | The target user for recalculating the data |
| hmac | String | The HMAC of the data |
| lastEightHmac | String | The HMAC of the last measurement data, specifically for eight-electrode data. When recalculating using four-electrode data HMAC, this should be passed as null. |
- If the HMAC is for four-electrode data, then lastEightHmac must be passed as null.
- If the HMAC is for eight-electrode data, lastEightHmac must not pass the four-electrode data HMAC, and can be passed as null.
- lastEightHmac must come from QNScaleData, and cannot use the hmac from QNScaleStoreData
Return Value
Type: QNScaleData
Returns NULL in case of an error.
switchHeightScaleUser
Switch the user of the height scale (dedicated for height-stadiometer integrated scales).
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| curUser | QNUser | Y | New user information for switching |
| callback | QNResultCallback | Y | Returns whether the method call to switch the height scale user succeeded |
- The gender and birthday fields of qnUser must have values.
setHeightScaleConfig
Set (update) the related configuration of the height scale
The callback when the connection is successful will be in QNScaleDataListener's OnSetHeightScaleConfigState
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
| function | QNHeightDeviceFunction | Y | Scale-related information to be set (see QNHeightDeviceFunction for attributes) |
| callback | QNResultCallback | Y | Returns whether this call was successful |
getHeightScaleConfig
Get the related configuration of the height scale
The callback for getting the height scale configuration information will be in QNScaleDataListener's OnGetHeightScaleConfig
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| callback | QNResultCallback | Y | Returns whether this call was successful |
resetHeightScale
Restore the height scale to factory settings (currently only supports CP30G)
The callback when the connection is successful will be in QNScaleDataListener's OnResetHeightScaleState
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| callback | QNResultCallback | Y | Returns whether this call was successful |
clearHeightScaleWifiConfig
Clear the WiFi configuration of the height scale (currently only supports CP30G)
The callback when the connection is successful will be in QNScaleDataListener's OnClearHeightScaleWifiConfigState
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| callback | QNResultCallback | Y | Returns whether this call was successful |
getHeightScaleWifiConfig
Get the WiFi configuration of the height scale (currently only supports CP30G)
The callback for getting WiFi configuration information will be in QNScaleDataListener's OnGetHeightScaleWifiConfig
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| callback | QNResultCallback | Y | Returns whether this call was successful |
startPairHeightScaleWifi
Start height scale WiFi pairing
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| wifiConfig | QNWifiConfig | Y | WiFi pairing information |
| callback | QNResultCallback | Y | Returns whether this call was successful |
scanHeightScaleWifiSsid
Scan available WiFi names for the height scale
The callback for scanning available WiFi names will be in QNScaleDataListener's OnScanHeightScaleWifiSsidResult
The callback for scan completion will be in QNScaleDataListener's OnScanHeightScaleWifiSsidFinish
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| callback | QNResultCallback | Y | Returns whether this call was successful |