Cannot stop scanning for telemetry data


#1

Hello,
I just followed the instruction on Scanning for Estimote Telemetry , it works. But there is no stop() method when I try to stop the scanner. After taking a look at the api, the start() method returns a ScanHandler and this class has a stop() method. So the code to stop scanning is like this: telemetryFullScanHandler.start().stop(), which looks quite weird to me. Did I use the wrong method? Code snippet here:

val scanner = EstimoteBluetoothScannerFactory(applicationContext).getSimpleScanner() 
val scanHandler = scanner.estimoteTelemetryFullScan()
togglebtn.setOnCheckedChangeListener(object:OnCheckedChangeListener{
            override fun onCheckedChanged(buttonView: CompoundButton, isChecked:Boolean) {
                if(isChecked){
                    scanHandler.withBalancedPowerMode()
                        .withOnPacketFoundAction {
                            textViewid.text = it.identifier
                            textViewismoving.text = it.motionState.toString()
                            textViewlight.text = "%.3f".format(it.ambientLightInLux)
                            textViewpressure.text = "%.3f".format(it.pressure)
                        }
                        .start() }
                else{
                    scanHandler.start().stop()
                }
            }
        })

#2

estimoteTelemetryFullScan() does not return scan handler, but scan launcher. You call 'start()` method on that launcher and then you get scan handler.

val scanner = EstimoteBluetoothScannerFactory(applicationContext).getSimpleScanner() 
val scanLauncher = scanner.estimoteTelemetryFullScan()
val scanHandler : ScanHandler? = null
togglebtn.setOnCheckedChangeListener(object:OnCheckedChangeListener{
            override fun onCheckedChanged(buttonView: CompoundButton, isChecked:Boolean) {
                if(isChecked){
                   scanHandler = scanLauncher.withBalancedPowerMode()
                        .withOnPacketFoundAction {
                            textViewid.text = it.identifier
                            textViewismoving.text = it.motionState.toString()
                            textViewlight.text = "%.3f".format(it.ambientLightInLux)
                            textViewpressure.text = "%.3f".format(it.pressure)
                        }
                        .start() }
                else{
                    scanHandler?.stop()
                }
            }
        })

#3

Hi pober,

Thank you for your quick response. scanHandler?.stop() gives me an error: unresolved reference
image

Maybe I imported wrong package?

import android.widget.CompoundButton
import android.widget.TextView
import com.estimote.indoorsdk_module.cloud.Location
import com.estimote.scanning_sdk.api.EstimoteBluetoothScannerFactory
import android.widget.CompoundButton.OnCheckedChangeListener
import android.widget.Switch
import com.estimote.indoorsdk_module.algorithm.ScanningIndoorLocationManager
import com.estimote.indoorsdk_module.view.IndoorLocationView


#4

I don’t see ScanHandler on your import list. You should import a class before you use it, even in Kotlin.
Android Studio should mark missing class name red and show a hint that import is missing. You just press Alt+Enter (platform dependent) and it will show you a list of actions to do. You just select Import and it should add:
import com.estimote.internal_plugins_api.scanning.ScanHandler

This option might be useful:


#5

Thank you pober, it still does not work.

Android Studio tells me
import com.estimote.internal_plugins_api.scanning.BluetoothScanner
import com.estimote.internal_plugins_api.scanning.ScanLauncher
import com.estimote.internal_plugins_api.scanning.ScanHandler

This three packages have never been used.


#6

You didn’t properly change the code. You just removed call to start() method.
Please look at the code snippet I sent you before and modify your code accordingly.


#7

Thank you pober. I didn’t look at your code carefully.
changed val scanHandler : ScanHandler? = null to var scanHandler : ScanHandler? = null and it works.

I appreciate it.