Home > Net >  Bluetooth LE - How do i get Advertisement Interval in milliseconds?
Bluetooth LE - How do i get Advertisement Interval in milliseconds?

Time:10-12

I have to get the Advertisement Interval in milliseconds. I used result.periodicAdvertisingInterval but this returns 0. I have to implement something like this:

enter image description here

private val scanCallback = object : ScanCallback(){
    @RequiresApi(Build.VERSION_CODES.N)
    @SuppressLint("MissingPermission", "NotifyDataSetChanged")

    override fun onScanResult(callbackType: Int, result: ScanResult) {

       val scanJob = CoroutineScope(Dispatchers.Main).launch {
            val tag = deviceMap.computeIfAbsent(result.device.address) {
                val newTag = BleTag(result.device.name ?: "Unbekannt", result.device.address, result.rssi , result.scanRecord?.bytes, "")
                deviceList.add(newTag)
                newTag
            }
            tag.name = result.device.name ?: "Unbekannt"
            tag.rssi = result.rssi
            tag.advertisementData = result.scanRecord?.bytes
        }

        deviceList.sortBy {result.rssi }

        recyclerView.adapter?.notifyDataSetChanged()
        menu.findItem(R.id.count).title = "Geräte: "   deviceList.size

        super.onScanResult(callbackType, result)
    }

    override fun onScanFailed(errorCode: Int) {
        super.onScanFailed(errorCode)
        Log.e("Scan failed","")
    }
}

CodePudding user response:

This result is obtained by subtracting the timestamps of two consecutive advertisements of the same device.

  • Related