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(
at com.mbientlab.metawear.impl.SFloatData$1.value(

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")

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")


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

private fun setUpTemperatureSensor(): Task<Route>{
    temperature = board.getModule(
    temperatureSensor =

    return temperatureSensor.addRouteAsync { source -> { data, _ ->
            Log.d(SENSOR_LOG, "temperature data ${data.value(}")


  • Have you been able to get this working?

  • I ran into this issue as well. It seems that for whatever reason the type is cast into a primitive float type (so not Float with a capital F) on the Java side in the mbientlab API. I've tried quite a few things but have not been able to solve this. Any progress on your side?

  • I should have waited just a little before sending the question above. I now have the answer:

    return temperatureSensor.addRouteAsync { source -> { data, _ -> Log.d(SENSOR_LOG, "temperature data ${data.value(Float::class.javaObjectType)}") } }

  • Nice!, thanks for the update @renev

Sign In or Register to comment.