我试图实现简单的sdk与健身跟踪器小米米带工作。目前,我可以跟踪步骤,驱动振动,处理传感器触摸,但我有一个问题的心率测量。基于https://github.com/pangliang/miband-sdk-android的My。为了测量心率,需要将描述符写入适当的特征,以便在改变该特征的值时处理回调,然后将适当的数据写入心率控制点特征,以直接启动心率测量过程。问题是心率测量过程在数据启动后还没有启动,这一过程是成功地写入了的特征(当米波段开始测量心率时,底层传感器闪烁绿色)。这可能是由健身跟踪器的新固件(固件版本: 4.15.12.10;HeartRate版本: 1.3.74.64)造成的,或者我的代码中有一些缺陷:
/-------- MiBandProfile --------/
public static final UUID UUID_SERVICE_HEARTRATE = UUID.fromString("0000180d-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_NOTIFICATION_HEARTRATE = UUID.fromString("00002a37-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_CHAR_HEARTRATE = UUID.fromString("00002a39-0000-1000-8000-00805f9b34fb");
public static final UUID UUID_DESCRIPTOR_UPDATE_NOTIFICATION = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
/-------- MiBandProtocol --------/
public static final byte[] START_HEART_RATE_SCAN = {21, 1, 1};
/-------- BleProvider --------/
public class BleProvider extends BluetoothGattCallback {
public interface NotifyListener {
void onNotify(byte[] data);
}
private HashMap<UUID, NotifyListener> mNotifyListeners = new HashMap<UUID, NotifyListener>();
.
.
.
public void setNotifyListener(UUID serviceUUID, UUID charaUUID, NotifyListener listener) {
//enable chara notofication
if (this.mGatt == null || !this.mIsServicesDiscovered) {
if (DBG) Log.d(Debug.TAG, "Device is not connected or services are not discovered");
return;
}
BluetoothGattCharacteristic chara = this.mGatt.getService(serviceUUID).getCharacteristic(charaUUID);
if (DBG) Log.d(Debug.TAG, "setCharacteristicNotification: " + this.mGatt.setCharacteristicNotification(chara, true));
BluetoothGattDescriptor descriptor = chara.getDescriptor(MiBandProfile.UUID_DESCRIPTOR_UPDATE_NOTIFICATION);
if (DBG) Log.d(Debug.TAG, "setValue: " + descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE));
if (DBG) Log.d(Debug.TAG, "writeDescriptor: " + this.mGatt.writeDescriptor(descriptor));
this.mNotifyListeners.put(charaUUID, listener);
}
@Override
public void onCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic) {
//this method must be called when the characteristic value was changed but nothing happened :(
super.onCharacteristicChanged(gatt, characteristic);
if (this.mNotifyListeners.containsKey(characteristic.getUuid())) {
this.mNotifyListeners.get(characteristic.getUuid()).onNotify(characteristic.getValue());
}
}
} //end BleProvider
.
.
.
setNotifyListener(MiBandProfile.UUID_SERVICE_HEARTRATE, MiBandProfile.UUID_NOTIFICATION_HEARTRATE, new BleProvider.NotifyListener(){...});
//waiting few seconds
writeCharacteristic(MiBandProfile.UUID_SERVICE_HEARTRATE, MiBandProfile.UUID_CHAR_HEARTRATE, MiBandProtocol.START_HEART_RATE_SCAN);也许这个协议被废弃了,有些人可以和我分享一个新的协议。我会很高兴的)谢谢。
发布于 2016-04-01 12:37:28
我解决了问题!在调用setNotifyListener跟踪脉冲值的变化之前,必须将用户信息(年龄、体重)写到适当的特性上,因为没有这个Mi波段就无法开始测量。
https://stackoverflow.com/questions/36311874
复制相似问题