polarofficial / polar-ble-sdk

Repository includes SDK and code examples. More info https://polar.com/en/developers
Other
485 stars 153 forks source link

Scan Device #175

Closed kumarankit-fujitsu closed 3 years ago

kumarankit-fujitsu commented 3 years ago

Platform your question concerns:

Device:

Description: I am using below code in my application to search polar device api.searchDevice().observeOn(AndroidSchedulers.mainThread()).subscribe( polarDeviceInfo -> Log.d(TAG, "polar device found id: " + " isConnectable: " +polarDeviceInfo.isConnectable), throwable -> Log.d(TAG, "" + throwable.getLocalizedMessage()), () -> Log.d(TAG, "complete") );

Case 1: When I am using Verity Sense In this case, I get the result and polar device details

Case 2: When I use another device like polar unite I don't get anything in the result. Basically, I want to handle the scenario where no compatible device was found after scanning.

Need help.

JOikarinen commented 3 years ago

Hi @kumarankit-fujitsu,

I think the problem in the Case 2 is that Polar Unite is not doing BLE advertisement and for that reason the api.searchDevice() is not finding your Polar Unite. The Polar wrist units, like Polar Unite, have a bit different logic than the sensor category devices, like Polar Verity Sense. The Polar Unite is not advertising all the time and that is for battery saving.

Your code snippet above looks similar what is found in Polar SDK android example app. With these steps api.searchDevice() finds the Polar Unite: 1) When the Polar Unite is on watch mode (i.e. time of the day is shown on the screen), then do the long button press to get the Polar Unite to sync mode. 2) When Polar Unite is on sync mode it starts to do BLE advertisement to make it self available 3) In Polar SDK example app when pressing "SCAN DEVICES" I got to following log output:

2021-07-23 16:56:52.957 20532-20532/com.polar.androidblesdk D/MainActivity: polar device found id: 7338782C address: A0:9E:1A:73:38:78 rssi: -85 name: Polar Unite 7338782C isConnectable: true

Basically, I want to handle the scenario where no compatible device was found after scanning.

  • is the above explanation helping you with this?
kumarankit-fujitsu commented 3 years ago

Hi, @JOikarinen Thanks for the help. Need one more help. I am getting error whenever I start GYRO Streaming JavaBinder: *** Uncaught remote exception! (Exceptions are not yet supported across processes.) java.lang.AssertionError: GYRO setting not stored

Can you please let me know the reason?

Thanks in Advance

JOikarinen commented 3 years ago

java.lang.AssertionError: GYRO setting not stored

@kumarankit-fujitsu by looking the SDK code I can see that assertion highlighted by you is possible. However, I am not able figure out the exact reason for getting the assert. I would be interested of what is the PolarSensorSetting parameter you pass for the startGyroStreaming method.

kumarankit-fujitsu commented 3 years ago

@JOikarinen I am using the same code as it is in the given sample. The only difference is that I am using that code in the Service class and providing direct value for PolarSensorSetting parameters. Please look into my Service class code below.

class HRForegroundService : Service() {

    private val polarApi: PolarBleApi by lazy {
        PolarBleApiDefaultImpl.defaultImplementation(
            this, PolarBleApi.ALL_FEATURES
        )
    }
    private lateinit var notificationLayout: RemoteViews
    private var gyrDisposable: Disposable? = null

    companion object {
        private const val CHANNEL_ID = "HeartRate"
        private const val NOTIFICATION_ID = 101
        private const val ACTION_STOP = "STOP_ACTION"
        private const val ACTION_START = "START_ACTION"
        private var isServiceRunning: Boolean = false
        private lateinit var DEVICE_ID: String

        fun startHRService(mContext: Context, deviceID: String) {
            val serviceIntent = Intent(mContext, HRForegroundService::class.java)
            serviceIntent.action = ACTION_START
            isServiceRunning = true
            DEVICE_ID = deviceID
            ContextCompat.startForegroundService(mContext, serviceIntent)
        }

        fun stopHRService(mContext: Context) {
            val stopServiceIntent = Intent(mContext, HRForegroundService::class.java)
            stopServiceIntent.action = ACTION_STOP
            isServiceRunning = false
            mContext.stopService(stopServiceIntent)

        }
    }

    override fun onCreate() {
        super.onCreate()
        createNotificationChannel()
    }

    override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
        when (intent?.action) {
            ACTION_START -> {
                val notification = getNotification()
                startForeground(NOTIFICATION_ID, notification)
                polarHeartRateSetup()
            }
            ACTION_STOP -> {
                stopForeground(true)
                stopSelf()
                if (DEVICE_ID.isNotEmpty()){
                    polarApi.disconnectFromDevice(DEVICE_ID)
                }
                gyrDisposable?.dispose()
                polarApi.shutDown()
            }
        }

        return START_NOT_STICKY
    }

    override fun onBind(intent: Intent?): IBinder? {
        return null
    }

    private fun getNotification(): Notification {
        val notificationIntent = Intent(this, SplashActivity::class.java)
        val pendingIntent = PendingIntent.getActivity(
            this,
            0, notificationIntent, 0
        )

        // Get the layouts to use in the custom notification
        notificationLayout = RemoteViews(packageName, R.layout.hr_notification_small)

        // Apply the layouts to the notification
        return NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.mipmap.ic_stat_ic_notification_icon)
            .setStyle(NotificationCompat.DecoratedCustomViewStyle())
            .setDefaults(Notification.DEFAULT_LIGHTS)
            .setVibrate(longArrayOf(0L))
            .setSound(null)
            .setSilent(true)
            .setCustomContentView(notificationLayout)
            .build()
    }

    private fun createNotificationChannel() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            val serviceChannel = NotificationChannel(
                CHANNEL_ID, "Heart Rate Channel",
                NotificationManager.IMPORTANCE_MIN
            )
            serviceChannel.enableLights(false)
            serviceChannel.vibrationPattern = longArrayOf(0L)
            serviceChannel.enableVibration(false)
            serviceChannel.setSound(null, null)
            val manager = getSystemService(NotificationManager::class.java)
            manager!!.createNotificationChannel(serviceChannel)
        }
    }

    private fun updateNotification(hrValue: String) {
        val updatedNotification = getNotification()
        notificationLayout.setTextViewText(R.id.tv_notify_hr, hrValue)
        val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
        manager.notify(NOTIFICATION_ID, updatedNotification)
    }

    private fun polarHeartRateSetup() {
        polarApi.setPolarFilter(false)
        // call polar api
        polarApi.setApiCallback(object : PolarBleApiCallback() {

            override fun deviceConnected(polarDeviceInfo: PolarDeviceInfo) {
                DEVICE_ID = polarDeviceInfo.deviceId
            }

            override fun deviceConnecting(polarDeviceInfo: PolarDeviceInfo) {
                super.deviceConnecting(polarDeviceInfo)
            }

            override fun deviceDisconnected(polarDeviceInfo: PolarDeviceInfo) {
                super.deviceDisconnected(polarDeviceInfo)
            }

            override fun streamingFeaturesReady(
                identifier: String,
                features: MutableSet<PolarBleApi.DeviceStreamingFeature>
            ) {
                for (feature in features) {
                    when (feature) {
                        PolarBleApi.DeviceStreamingFeature.GYRO -> {
                            if (DEVICE_ID.isNotEmpty()) {
                                startGyroStreaming()
                            }
                        }
                        PolarBleApi.DeviceStreamingFeature.PPI -> {
//                            if (deviceId.isNotEmpty()) {
//                                startHRPPIStreaming(deviceId)
//                            }
                        }
                        else -> {
                            //do nothing
                        }
                    }
                }

            }

            override fun hrFeatureReady(identifier: String) {
                super.hrFeatureReady(identifier)
            }

            override fun hrNotificationReceived(identifier: String, data: PolarHrData) {

                Log.d("HeartRate", "Foreground Heart Rate =====> " + data.hr)
//                heartRateCollapse.text = data.hr.toString()
                if (isServiceRunning)
                    updateNotification(data.hr.toString())

            }
        })
        try {
            polarApi.autoConnectToDevice(-50, "180D", null)?.subscribe()
        } catch (a: PolarInvalidArgument) {
            a.printStackTrace()
        }

    }

    private fun startGyroStreaming() {
        val isDisposed = gyrDisposable?.isDisposed ?: true
        if (isDisposed) {
            requestStreamSettings(PolarBleApi.DeviceStreamingFeature.GYRO)
                .flatMap { settings: PolarSensorSetting ->
                    polarApi.startGyroStreaming(DEVICE_ID, settings)
                }
                ?.observeOn(AndroidSchedulers.mainThread())
                ?.subscribe(
                    { polarGyroData: PolarGyroData ->
                        for (data in polarGyroData.samples) {
                            Log.d(
                                "HRForegroundService",
                                "GYR    x: ${data.x} y:  ${data.y} z: ${data.z}"
                            )
                        }
                    },
                    { error: Throwable ->
                        Log.e("HRForegroundService", "GYR stream failed. Reason $error")
                    },
                    { Log.d("HRForegroundService", "GYR stream complete") }
                )

        } else {
// NOTE dispose will stop streaming if it is "running"
            gyrDisposable?.dispose()
        }
    }

    private fun requestStreamSettings(feature: PolarBleApi.DeviceStreamingFeature): Flowable<PolarSensorSetting> {

        val availableSettings = polarApi.requestStreamSettings(DEVICE_ID, feature)
            .observeOn(AndroidSchedulers.mainThread())
            ?.onErrorReturn { error: Throwable ->
                PolarSensorSetting(emptyMap())
            }
        val allSettings = polarApi.requestFullStreamSettings(DEVICE_ID, feature)
            .onErrorReturn { error: Throwable ->
                PolarSensorSetting(emptyMap())
            }
        return Single.zip(
            availableSettings,
            allSettings,
            { available: PolarSensorSetting, all: PolarSensorSetting ->
                if (available.settings.isEmpty()) {
                    throw Throwable("Settings are not available")
                } else {
                    return@zip android.util.Pair(available, all)
                }
            }
        )
            .observeOn(AndroidSchedulers.mainThread())
            .toFlowable()
            .flatMap(
                Function { sensorSettings: android.util.Pair<PolarSensorSetting, PolarSensorSetting> ->
                    gyroSetting(
                        sensorSettings.first.settings,
                        sensorSettings.second.settings
                    ).toFlowable()
                } as Function<Pair<PolarSensorSetting, PolarSensorSetting>, Flowable<PolarSensorSetting>>
            )
    }

    private fun gyroSetting(
        available: Map<PolarSensorSetting.SettingType, Set<Int>>,
        all: Map<PolarSensorSetting.SettingType, Set<Int>>
    ): Single<PolarSensorSetting?> {

        return Single.create { e: SingleEmitter<PolarSensorSetting?> ->
            val selected: MutableMap<PolarSensorSetting.SettingType, Int> = EnumMap(
                PolarSensorSetting.SettingType::class.java
            )

            selected[PolarSensorSetting.SettingType.SAMPLE_RATE] = 52
            selected[PolarSensorSetting.SettingType.RESOLUTION] = 16
            selected[PolarSensorSetting.SettingType.RANGE] = 2000
            selected[PolarSensorSetting.SettingType.CHANNELS] = 3
            e.onSuccess(PolarSensorSetting(selected))
        }
    }

}

NOTE: When I use the same code inside a fragment or activity, then it is working fine as expected.

JOikarinen commented 3 years ago

Hi @kumarankit-fujitsu, for now I don't spot the possible problem in your code, I continue investigating what could be the issue when using the SDK from android service.

JOikarinen commented 3 years ago

@kumarankit-fujitsu one thing to double check is the restriction by Android OS related to services requiring location. Polar SDK requires the location for any Bluetooth operation. Here is the Google's guide: https://developer.android.com/guide/components/foreground-services#types

If your app targets Android 10 (API level 29) or higher and accesses location information in a foreground service, declare the location foreground service type as an attribute of your <service> component.

kumarankit-fujitsu commented 3 years ago

Thanks, @JOikarinen I will check and get back to you.

kumarankit-fujitsu commented 3 years ago

@JOikarinen Same error after applying location foreground service type as an attribute of component. <service android:name=".ui.views.service.HRForegroundService" android:enabled="true" android:foregroundServiceType="location"/>

kumarankit-fujitsu commented 3 years ago

Hi @JOikarinen I have tried with Android 8 (API level 27). Found same error. Only for few seconds I got gyro data and then app get crashed. Below are the logs, I am sharing with you. It might help you to understand the reason for this issue.

2021-08-12 18:10:32.214 8038-8038/com.fujitsu.dev D/Service: GYR    x: 1.05 y:  1.89 z: -1.4
2021-08-12 18:10:32.215 8038-8038/com.fujitsu.dev D/Service: GYR    x: 0.98 y:  1.47 z: -1.26
2021-08-12 18:10:32.215 8038-8038/com.fujitsu.dev D/Service: GYR    x: 0.91 y:  1.26 z: -1.19
2021-08-12 18:10:32.215 8038-8038/com.fujitsu.dev D/Service: GYR    x: 0.7 y:  1.4 z: -1.26
2021-08-12 18:10:32.216 8038-8038/com.fujitsu.dev D/Service: GYR    x: 0.63 y:  1.4 z: -1.33
2021-08-12 18:10:32.216 8038-8038/com.fujitsu.dev D/Service: GYR    x: 0.91 y:  1.05 z: -1.19
2021-08-12 18:10:32.217 8038-8038/com.fujitsu.dev D/Service: GYR    x: 1.19 y:  0.91 z: -1.19
2021-08-12 18:10:32.217 8038-8038/com.fujitsu.dev D/Service: GYR    x: 1.05 y:  0.42000002 z: -1.19
2021-08-12 18:10:32.226 8038-8055/com.fujitsu.dev E/JavaBinder: *** Uncaught remote exception!  (Exceptions are not yet supported across processes.)
    java.lang.AssertionError: GYRO setting not stored
        at com.polar.androidcommunications.common.ble.BleUtils.validate(BleUtils.java:110)
        at com.polar.androidcommunications.api.ble.model.gatt.client.BlePMDClient.fetchFactor(BlePMDClient.java:871)
        at com.polar.androidcommunications.api.ble.model.gatt.client.BlePMDClient.processServiceData(BlePMDClient.java:992)
        at com.polar.androidcommunications.enpoints.ble.bluedroid.host.BDDeviceSessionImpl.handleCharacteristicValueUpdated(BDDeviceSessionImpl.java:559)
        at com.polar.androidcommunications.enpoints.ble.bluedroid.host.BDGattCallback.onCharacteristicChanged(BDGattCallback.java:133)
        at android.bluetooth.BluetoothGatt$1$8.run(BluetoothGatt.java:443)
        at android.bluetooth.BluetoothGatt.runOrQueueCallback(BluetoothGatt.java:725)
        at android.bluetooth.BluetoothGatt.-wrap0(Unknown Source:0)
        at android.bluetooth.BluetoothGatt$1.onNotify(BluetoothGatt.java:437)
        at android.bluetooth.IBluetoothGattCallback$Stub.onTransact(IBluetoothGattCallback.java:184)
        at android.os.Binder.execTransact(Binder.java:697)
JOikarinen commented 3 years ago

Hi @kumarankit-fujitsu, I have replicated your service setup as close as I can by copying your HRForegroundService code found in your previous comment. In my experiment the code is working perfectly and gyro stream data is received. I get stream of gyro data and produced log messages are looks like this: D/HRForegroundService: GYR x: -1.61 y: 0.56 z: 0.98.

So there is some aspect which is different in our setups. I would be interested of what kind of logs are produced by Polar BLE SDK once you run your code. Is it possible you setup the logging for Polar BLE SDK and provide logs? You may enable the logging by placing polarApi.setApiLogger { s: String? -> Log.d("API_LOGGER", s!!) } to your service onStartCommand function

JOikarinen commented 3 years ago

Another thing which we could double check is the used device and its firmware. May you override the disInformationReceived for PolarBleApiCallback

override fun disInformationReceived(identifier: String, uuid: UUID, value: String) {
     Log.d("DisInformation", "DIS information $value")
}
kumarankit-fujitsu commented 3 years ago

@JOikarinen Here are the logs that I got using polarApi.setApiLogger { s: String? -> Log.d("API_LOGGER", s!!) } in onStartCommand() function of Service Class.

`2021-08-13 11:19:06.535 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: CLIENT_START_SCAN
2021-08-13 11:19:06.536 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: EXIT
2021-08-13 11:19:06.536 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:SCANNING action: ENTRY
2021-08-13 11:19:06.536 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/timestamps left: 0
2021-08-13 11:19:06.536 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/Scan started -->
2021-08-13 11:19:06.561 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/Scan started <--
2021-08-13 11:19:06.786 13147-13644/com.fujitsu.dev D/API_LOGGER: BDGattCallback/ phy updated tx: 2 rx: 2 status: 0
2021-08-13 11:19:07.076 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for fb005c51-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:07.077 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for fb005c52-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:07.078 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for fb005c81-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:07.079 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for fb005c82-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:07.080 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for 00002a19-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.081 13147-13147/com.fujitsu.dev D/API_LOGGER: BDDeviceListenerImpl/new device allocated name: Polar Sense 923EE226
2021-08-13 11:19:07.081 13147-13147/com.fujitsu.dev D/API_LOGGER: BDDeviceList/new session added: Polar Sense 923EE226
2021-08-13 11:19:07.716 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 00001800-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.716 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: 00001800-0000-1000-8000-00805f9b34fb chrs: 4
2021-08-13 11:19:07.717 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 00001801-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.717 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: 00001801-0000-1000-8000-00805f9b34fb chrs: 1
2021-08-13 11:19:07.718 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000180a-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.718 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a29-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.720 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a24-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.721 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a25-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.722 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a27-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.723 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a26-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.723 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a28-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.724 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a23-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:07.725 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000feee-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.725 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c51-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 28
2021-08-13 11:19:07.725 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c52-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 16
2021-08-13 11:19:07.726 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c53-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 12
2021-08-13 11:19:07.726 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000180d-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.727 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a37-0000-1000-8000-00805f9b34fb PROPERTIES: 16
2021-08-13 11:19:07.727 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000180f-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.728 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a19-0000-1000-8000-00805f9b34fb PROPERTIES: 18
2021-08-13 11:19:07.728 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: fb005c20-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:07.729 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: fb005c20-02e7-f387-1cad-8acd2d8df0c8 chrs: 3
2021-08-13 11:19:07.729 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 6217ff4b-fb31-1140-ad5a-a45545d7ecf3
2021-08-13 11:19:07.729 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: 6217ff4b-fb31-1140-ad5a-a45545d7ecf3 chrs: 2
2021-08-13 11:19:07.730 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: fb005c80-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:07.730 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c81-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 42
2021-08-13 11:19:07.731 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c82-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 16
2021-08-13 11:19:07.746 13147-13147/com.fujitsu.dev D/API_LOGGER: BleHrClient/Start observing HR
2021-08-13 11:19:07.746 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for 00002a37-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:07.763 13147-13644/com.fujitsu.dev D/API_LOGGER: BDGattCallback/onMtuChanged status: 0
2021-08-13 11:19:07.764 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/handleMtuChanged status: 0 mtu: 232
2021-08-13 11:19:07.765 13147-13644/com.fujitsu.dev D/API_LOGGER: BDGattCallback/Services discovered authentication is not needed
2021-08-13 11:19:07.823 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c51-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:08.003 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c52-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:08.187 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: 00002a19-0000-1000-8000-00805f9b34fb status: 0
2021-08-13 11:19:08.273 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c81-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:08.410 13147-13644/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c82-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:09.213 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:SCANNING action: CLIENT_REMOVED
2021-08-13 11:19:09.213 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:SCANNING action: EXIT
2021-08-13 11:19:09.214 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/Stop scanning
2021-08-13 11:19:09.234 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: ENTRY
2021-08-13 11:19:09.236 13147-13147/com.fujitsu.dev D/API_LOGGER: ConnectionHandler/state: CONNECTING action: ENTRY
2021-08-13 11:19:09.236 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: ADMIN_STOP_SCAN
2021-08-13 11:19:09.237 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: EXIT
2021-08-13 11:19:09.237 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: ENTRY
2021-08-13 11:19:09.238 13147-13147/com.fujitsu.dev D/API_LOGGER: ConnectionHandler/ Session update from: SESSION_CLOSED to: SESSION_OPENING
2021-08-13 11:19:09.239 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: CLIENT_REMOVED
2021-08-13 11:19:09.256 13147-13147/com.fujitsu.dev D/API_LOGGER: auto connect search complete
2021-08-13 11:19:09.284 13147-13939/com.fujitsu.dev D/API_LOGGER: BDGattCallback/GATT state changed device newState: 2 status: 0
2021-08-13 11:19:09.285 13147-13147/com.fujitsu.dev D/API_LOGGER: ConnectionHandler/state: CONNECTING action: DEVICE_CONNECTED
2021-08-13 11:19:09.285 13147-13147/com.fujitsu.dev D/API_LOGGER: ConnectionHandler/ Session update from: SESSION_OPENING to: SESSION_OPEN
2021-08-13 11:19:09.285 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: CLIENT_REMOVED
2021-08-13 11:19:09.287 13147-13147/com.fujitsu.dev D/API_LOGGER: ConnectionHandler/state: CONNECTING action: EXIT
2021-08-13 11:19:09.287 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: ADMIN_START_SCAN
2021-08-13 11:19:09.287 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: EXIT
2021-08-13 11:19:09.287 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: ENTRY
2021-08-13 11:19:09.293 13147-13939/com.fujitsu.dev D/API_LOGGER: BDGattCallback/onMtuChanged status: 0
2021-08-13 11:19:09.293 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/handleMtuChanged status: 0 mtu: 232
2021-08-13 11:19:09.293 13147-13939/com.fujitsu.dev D/API_LOGGER: BDGattCallback/Services discovered authentication is not needed
2021-08-13 11:19:09.300 13147-13644/com.fujitsu.dev D/API_LOGGER: BDGattCallback/ phy updated tx: 2 rx: 2 status: 0
2021-08-13 11:19:09.303 13147-13939/com.fujitsu.dev D/API_LOGGER: BDGattCallback/ phy updated tx: 2 rx: 2 status: 0
2021-08-13 11:19:09.532 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: 00002a37-0000-1000-8000-00805f9b34fb status: 0
2021-08-13 11:19:09.910 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 00001800-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:09.910 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: 00001800-0000-1000-8000-00805f9b34fb chrs: 4
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 00001801-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: 00001801-0000-1000-8000-00805f9b34fb chrs: 1
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000180a-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a29-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a24-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a25-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.911 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a27-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a26-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a28-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a23-0000-1000-8000-00805f9b34fb PROPERTIES: 2
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000feee-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c51-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 28
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c52-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 16
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c53-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 12
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000180d-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:09.912 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a37-0000-1000-8000-00805f9b34fb PROPERTIES: 16
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 0000180f-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: 00002a19-0000-1000-8000-00805f9b34fb PROPERTIES: 18
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: fb005c20-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: fb005c20-02e7-f387-1cad-8acd2d8df0c8 chrs: 3
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: 6217ff4b-fb31-1140-ad5a-a45545d7ecf3
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/No client found for SERVICE: 6217ff4b-fb31-1140-ad5a-a45545d7ecf3 chrs: 2
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/ SERVICE: fb005c80-02e7-f387-1cad-8acd2d8df0c8
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c81-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 42
2021-08-13 11:19:09.913 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/     CHARACTERISTIC: fb005c82-02e7-f387-1cad-8acd2d8df0c8 PROPERTIES: 16
2021-08-13 11:19:09.917 13147-13147/com.fujitsu.dev D/API_LOGGER: BleHrClient/Start observing HR
2021-08-13 11:19:09.917 13147-13147/com.fujitsu.dev D/API_LOGGER: BleGattBase/Added notification characteristic for 00002a37-0000-1000-8000-00805f9b34fb
2021-08-13 11:19:10.027 13147-15439/com.fujitsu.dev D/API_LOGGER: BDGattCallback/onMtuChanged status: 4
2021-08-13 11:19:10.028 13147-15439/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/handleMtuChanged status: 4 mtu: 232
2021-08-13 11:19:10.028 13147-15439/com.fujitsu.dev D/API_LOGGER: BDGattCallback/Services discovered authentication is not needed
2021-08-13 11:19:10.117 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c51-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:10.178 13147-13939/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:10.267 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c52-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:10.326 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: 00002a19-0000-1000-8000-00805f9b34fb status: 0
2021-08-13 11:19:10.387 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c81-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:10.447 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: fb005c82-02e7-f387-1cad-8acd2d8df0c8 status: 0
2021-08-13 11:19:11.147 13147-13147/com.fujitsu.dev D/API_LOGGER: complete
2021-08-13 11:19:11.168 13147-15439/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:11.168 13147-13939/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:11.257 13147-13939/com.fujitsu.dev D/API_LOGGER: BDDeviceSessionImpl/onDescriptorWrite uuid: 00002a37-0000-1000-8000-00805f9b34fb status: 0
2021-08-13 11:19:12.189 13147-15439/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:12.192 13147-13939/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:13.148 13147-13939/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:13.148 13147-15439/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:14.196 13147-15439/com.fujitsu.dev D/API_LOGGER: BlePMDClient/pmd data:  HEX: 05 E5 CE 02 5F E5 8C 77 09 80 0E 00 0D 00 EB FF 06 13 06 E2 03 09 11 08 C5 DF 03 F4 0F D8 01 70 F0 3E B1 F3 05 FF FF 3D 1F F8 7F 90 08 C2 71 04 42 E1 07 41 DF 0B C1 0E 0C 3D CF F3 3C 04 14 31 1E F4 1D 10 2D 1F C2 10 05 00 F1 31 F0 11 B1 DE F9 D0 FE F2 31 41 05 EF D1 1C 02 EF 11 06 3B 41 01 F8 02 40 FC C0 0F 00 80 DF 0F C1 0F 08 43 20 08 3E F0 E3 01 60 FF 3F B1 FF 06 FF 13 FD 3F F8 BE 60 F8 42 32 04 44 F1 0B 43 2F 08 80 2F 14 7D 2F EC 40 2F F8 82 DF F7 40 EF FB 01 E0 FF 7F 0F 08 08 31 04 BF 9F F7 7C CF F7 39 A0 D3 FF 7D F7 7B 00 1C 0B 42 48 49 80 1C 02 82 00 C5 51 0C C6 41 F4 86 A0 13 3C 2E D4 37 5F D7 FF 7E 0F FE 1E 18 FF 4F 18 3E 80 DC 46 61 0B C3 FF 0B 81 3E 0C 77 00 F4 3C 
2021-08-13 11:19:14.235 13147-13939/com.fujitsu.dev D/API_LOGGER: BlePMDClient/pmd data:  HEX: 05 E5 CE 02 5F E5 8C 77 09 80 0E 00 0D 00 EB FF 06 13 06 E2 03 09 11 08 C5 DF 03 F4 0F D8 01 70 F0 3E B1 F3 05 FF FF 3D 1F F8 7F 90 08 C2 71 04 42 E1 07 41 DF 0B C1 0E 0C 3D CF F3 3C 04 14 31 1E F4 1D 10 2D 1F C2 10 05 00 F1 31 F0 11 B1 DE F9 D0 FE F2 31 41 05 EF D1 1C 02 EF 11 06 3B 41 01 F8 02 40 FC C0 0F 00 80 DF 0F C1 0F 08 43 20 08 3E F0 E3 01 60 FF 3F B1 FF 06 FF 13 FD 3F F8 BE 60 F8 42 32 04 44 F1 0B 43 2F 08 80 2F 14 7D 2F EC 40 2F F8 82 DF F7 40 EF FB 01 E0 FF 7F 0F 08 08 31 04 BF 9F F7 7C CF F7 39 A0 D3 FF 7D F7 7B 00 1C 0B 42 48 49 80 1C 02 82 00 C5 51 0C C6 41 F4 86 A0 13 3C 2E D4 37 5F D7 FF 7E 0F FE 1E 18 FF 4F 18 3E 80 DC 46 61 0B C3 FF 0B 81 3E 0C 77 00 F4 3C 
2021-08-13 11:19:14.243 13147-13939/com.fujitsu.dev D/API_LOGGER: BleHrClient/Processing service data. Status: 0.  Data length: 2
2021-08-13 11:19:14.254 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: ADMIN_STOP_SCAN
2021-08-13 11:19:14.254 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: EXIT
2021-08-13 11:19:14.255 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: ENTRY
2021-08-13 11:19:14.255 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: ADMIN_START_SCAN
2021-08-13 11:19:14.255 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:STOPPED action: EXIT
2021-08-13 11:19:14.255 13147-13147/com.fujitsu.dev D/API_LOGGER: BDScanCallback/commandState state:IDLE action: ENTRY
`

And Below are the information I got after using override fun disInformationReceived(identifier: String, uuid: UUID, value: String) { Log.d("DisInformation", "DIS information $value") }

`2021-08-13 11:19:10.662 13147-13147/com.fujitsu.dev D/DisInformation: DIS information �>�����
2021-08-13 11:19:10.751 13147-13147/com.fujitsu.dev D/DisInformation: DIS information 1.1.5
2021-08-13 11:19:10.838 13147-13147/com.fujitsu.dev D/DisInformation: DIS information 0.1.5
2021-08-13 11:19:10.898 13147-13147/com.fujitsu.dev D/DisInformation: DIS information 00784292.02
2021-08-13 11:19:10.959 13147-13147/com.fujitsu.dev D/DisInformation: DIS information 923EE226��
2021-08-13 11:19:11.084 13147-13147/com.fujitsu.dev D/DisInformation: DIS information INW4J
2021-08-13 11:19:11.146 13147-13147/com.fujitsu.dev D/DisInformation: DIS information Polar Electro Oy��`
kumarankit-fujitsu commented 3 years ago

@JOikarinen May I know, are you using any other permission other than I am using:

  1. In Fragment

    private fun requestForBluetoothAndLocation() {
        val mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter()
        if (mBluetoothAdapter != null && !mBluetoothAdapter.isEnabled) {
            val enableBtIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
            startActivityForResult(enableBtIntent, 2)
        }
    
        //requestPermissions() method needs to be called when the build SDK version is 23 or above
        if (Build.VERSION.SDK_INT >= 23) {
            requestPermissions(
                arrayOf(
                    Manifest.permission.ACCESS_COARSE_LOCATION,
                    Manifest.permission.ACCESS_FINE_LOCATION
                ), 1
            )
        }
    }
  2. In Manifest
<uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
 <service
            android:name=".ui.views.service.HRForegroundService"
            android:enabled="true"
            android:foregroundServiceType="location"/>

If I am missing any permission, then please let me know. Many thanks.

kumarankit-fujitsu commented 3 years ago

Hi, @JOikarinen As you said, "In my experiment, the code is working perfectly and gyro stream data is received". Can you please share that working experimented code on Github with me. So that I can compare my code with yours and try to figure out the exact reason for crashing. It will be a great help. Thank You.

JOikarinen commented 3 years ago

@kumarankit-fujitsu thank you for the logs. I think the logs reveals the cause but maybe not reason yet. From the logs I can see there is two sessions created for the one device. Both of the sessions do operations for the device and as a consequence there is assert on other session.

But why there are two sessions, is now a bit of mystery. Here are the first thoughts you could double check:

kumarankit-fujitsu commented 3 years ago

@JOikarinen Yes, there are two sessions purposely. Both sessions started on two different objects of PolarBleApi. One In the fragment when the user using the application and the other when the user closes the application, not using directly( in the Service)

JOikarinen commented 3 years ago

@kumarankit-fujitsu I suppose that's the reason for the problem. The two instances of the PolarBleApi are now interfering each others. You shall refactor your code so that you have only one instance of PolarBleApi. I will have a look on documentation where would is the best place for highlighting that there shall be on instance created of PolarBleApi.

JOikarinen commented 3 years ago

@kumarankit-fujitsu after some thinking I couldn't think of the situation that multiple instances of the PolarBleApi would be needed by client application. For the future proof, in #175 the singleton pattern is taken into use to prevent the multiple instantiation of PolarBleApi.

kumarankit-fujitsu commented 3 years ago

@JOikarinen Thanks a lot for the help. As you said, I refactor my code and now keeping only one instance of the PolarBleApi. Now it is working fine. Two questions I would like to ask you.

  1. I am using PPIStreaming and GyroStreaming both in service. Sometimes I get the GYRO setting is not available error. Below is the code snippet

    ` override fun streamingFeaturesReady(
                identifier: String,
                features: MutableSet<PolarBleApi.DeviceStreamingFeature>
            ) {
                for (feature in features) {
                    when (feature) {
                        PolarBleApi.DeviceStreamingFeature.GYRO -> {
                            if (DEVICE_ID.isNotEmpty()) {
                                startGyroStreaming()
                            }
                        }
                        PolarBleApi.DeviceStreamingFeature.PPI -> {
                            if (DEVICE_ID.isNotEmpty()) {
                                startHRPPIStreaming()
                            }
                        }
                        else -> {
                            //do nothing
                        }
                    }
                }
    
            }`

    The reason may be both calls get started simultaneously?

  2. I am converting the HR value that I get from PPIStreaming into BPM and the formula I am using is 60*1000/PpiMs. Is it the correct way to convert because sometimes I get a 21 bpm converted value?

Thank You

JOikarinen commented 3 years ago
  1. I am using PPIStreaming and GyroStreaming both in service. Sometimes I get the GYRO setting is not available error. Below is the code snippet

    • interesting problem. It sounds pretty much of timing issue. If you comment out the startHRPPIStreaming() do you still get the " GYRO setting is not available error" sometimes?
  2. I am converting the HR value that I get from PPIStreaming into BPM and the formula I am using is 60*1000/PpiMs. Is it the correct way to convert because sometimes I get a 21 bpm converted value?

    • there is HR value provided in PolarOhrPPISample. However if you want to calculate it yourself the formula 60*1000/PpiMs is correct
kumarankit-fujitsu commented 3 years ago

@JOikarinen

So to draw the HR graph how do I rely on PolarHrData or PolarOhrPPIData?

JOikarinen commented 3 years ago

So to draw the HR graph how do I rely on PolarHrData or PolarOhrPPIData?

kumarankit-fujitsu commented 3 years ago

Thanks a lot @JOikarinen for your patience and helping me out.