Bluetooth library (for full only)
Functional overview
Based on the native platform Bluetooth library encapsulation, it is used to scan peripheral devices, obtain the returned device collection, display it in the list, select the device to be connected, and return the device information and whether the device is in OTA mode after successful connection. If the connection fails, there will be an error callback. The default scan signal filter parameter is 80, and the automatic scan connection timeout is 20 seconds. (Note: only for full version)
Method
addBleDelegate(api:)
Add Bluetooth agent IDOBleDelegate
addDfuDelegate(api:)
Add DFU upgrade (nordic)
bluetoothRegister(heartPingSecond:outputToConsole:)
Register, call when the program starts running
delegate agent heartPingSecond: heartbeat packet interval (ios) outputToConsole: console output log
startScan(macAddress:completion:)
Start searching macAddress (Android): Search based on Mac address Returns the specified search device, returns null if not specified
scanFilter(deviceName:deviceID:macAddress:uuid:)
Search filter conditions
deviceName: Only search for devices with deviceName
deviceID: Only search for devices with deviceID
macAddress: Only search for devices with macAddress
uuid: Only search for devices with uuid
stopScan()
Stop searching
connect(device:)
Connect device: Mac address must be passed, iOS needs to bring uuid, it is best to use the object returned by the search
autoConnect(device:)
Use this to reconnect the device
cancelConnect(macAddress:completion:)
Cancel the connection
getBluetoothState(completion:)
Get Bluetooth status
getDeviceState(device:completion:)
Get device connection status
writeData(data:device:type:completion:)
Send data
data: data
device: device sending data
type:0 BLE data, 1 SPP data
platform: 0 ido, 1 Hengxuan, 2 VC
setBtPair(device:)
bt pairing (android)
cancelPair(device:)
Cancel pairing (android)
connectSPP(btMacAddress:)
Connect SPP (android)
disconnectSPP(btMacAddress:)
Disconnect SPP (android)
startNordicDFU(config:)
Initiate dfu upgrade
exportLog(completion:)
Export ble log, return the absolute path of the compressed log zip file
Example
Register Bluetooth module
Swift:
// Register Bluetooth library
sdk.ble.addBleDelegate(api: <IDOBleDelegate>)
sdk.ble.bluetoothRegister(heartPingSecond: 5, outputToConsole: false)
sdk.ble.getBluetoothState { [weak self] stateModel in
// Status monitoring
}
Kotlin:
//Register Bluetooth library
sdk.ble.addBleDelegate(IDOBleDelegate)
sdk.ble.bluetoothRegister(false)
sdk.ble.getBluetoothState {
//Status monitoring
}
Proxy implementation
Swift:
// Implementation of proxy
extension SomeClass: IDOBleDelegate {
func scanResult(list: [IDODeviceModel]?) {
// Scan device list
print("scanResult list count:\(String(describing: list?.count))")
}
func bluetoothState(state: IDOBluetoothStateModel) {
// Bluetooth status
print("on bluetoothState callback: \(String(describing: state.scanType?.rawValue))")
}
func deviceState(state: IDODeviceStateModel) {
// Device state
print("on deviceState callback: \(String(describing: state.state))")
}
}
Kotlin:
// Implement the proxy
private val bleDelegate = object : IDOBleDelegate {
override fun scanResult(list: List<IDOBleDeviceModel>?) {
// Scan device list
}
override fun bluetoothState(state: IDOBluetoothStateModel) {
// Bluetooth state
}
override fun deviceState(state: IDODeviceStateModel) {
// Device state
}
override fun stateSPP(state: IDOSppStateModel) {
}
override fun writeSPPCompleteState(btMacAddress: String) {
}
}