Pregunta

Al intentar leer el valor de una característica del GATT de baja energía Bluetooth en la API de Android 18, encontré el siguiente dilema: ¿cuál es la forma correcta de recuperar el valor almacenado en una característica?¿Y en qué nivel de la pila debe tener lugar esta acción?

Al realizar mi propia investigación, me topé con lo que entiendo son dos métodos posibles:

  • bluetoothgatt . rascaracteristic (Bluetoothgattcharacteristic caracteristic)
  • bluetoothgattcharacteristic .getvalue ()

    public void onClick(View v){        
        byteValue = mBTValueCharacteristic.getValue();
        if ((byteValue[0] & 0x01) == 1)
            byteValue[0] = 0x00;
        else
            byteValue[0] = 0x01;
    
        mBTValueCharacteristic.setValue(byteValue);
        mBTGatt.writeCharacteristic(mBTValueCharacteristic);
    }
    

arriba es el código original que me llevó a este problema.En él, intento leer el valor de una característica, y simplemente alternar su estado usando un botón.

¿Fue útil?

Solución

BluetoothGatt.readCharacteristic(BluetoothGattCharacteristic characteristic)

Esta función está actualizando su objeto BluetoothgatchSaracteristic (en su dispositivo Android) utilizando el valor característico del Bluetooth.

BluetoothGattCharacteristic.getValue()

Esta función es solo una función de Getter del objeto Bluetoothgatcharacteristic.No hay ninguna transacción entre Android y el dispositivo Bluetooth.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top