Get error Invalid input class: 'float' when trying to read temperature - code is in kotlin

I'm trying to read the temperature data from my MetaMotionR, but i get and error that says:
2020-10-08 12:18:37.290 31070-1610/com.example.afgangsprojektet W/BluetoothGatt: Unhandled exception in callback
java.lang.ClassCastException: Invalid input class: 'float'
at com.mbientlab.metawear.impl.DataPrivate.value(DataPrivate.java:72)
at com.mbientlab.metawear.impl.SFloatData$1.value(SFloatData.java:94)

I have tried reading acceleration data, and that works fine, can anyone help?

This is the part of my code where i try to read temperature:

override fun onServiceConnected(componentName: ComponentName?, iBinder: IBinder) {
    serviceBinder = iBinder as LocalBinder
    Log.d(SENSOR_LOG, "Sensor connected")
    retrieveBoard(sensorResId)
}

private fun retrieveBoard(macAddress: String) {
    val btManager =
        getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
    val remoteDevice: BluetoothDevice = btManager.adapter.getRemoteDevice(macAddress)

    // Create a MetaWear board object for the Bluetooth Device
    board = serviceBinder.getMetaWearBoard(remoteDevice)

    board.connectAsync().onSuccessTask {

            Log.d(SENSOR_LOG, "Sensor connection succeeded, connected to: $macAddress")

            setUpTemperatureSensor()

    }.continueWith { task ->
        if (task.isFaulted) {
            Log.d(SENSOR_LOG, "Sensor connection is faulted error: ${task.error} ")
        } else {
            Log.d(SENSOR_LOG, "Sensor is configured")
            temperatureSensor.read()
        }
        null
    }
}

private fun setUpTemperatureSensor(): Task<Route>{
    temperature = board.getModule(Temperature::class.java)
    temperatureSensor =
        temperature.findSensors(Temperature.SensorType.PRESET_THERMISTOR)[0]

    return temperatureSensor.addRouteAsync { source ->
        source.stream { data, _ ->
            Log.d(SENSOR_LOG, "temperature data ${data.value(Float::class.java)}")
        }
    }
}
Sign In or Register to comment.