2

Bluegiga BLED 112 deviceを使用して、Android 用の BLE bluetooth (SMART) アプリケーションを開発しようとしています。Android SDKサンプルで提供されているBLEデモサンプルコードに従っています。

これが私のGattCallBackです。

// Implements callback methods for GATT events that the app cares about.
// For example,
// connection status has changed, services are discovered,etc...
private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
    // Called when device has changed connection status and appropriate
    // broadcast with device address extra is sent
    // It can be either connected or disconnected state
    @Override
    public void onConnectionStateChange(final BluetoothGatt gatt,
            int status, int newState) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            // LogUtils.LOGI("BLE_STATUS", "SUCCESS");

            Log.i("BLE service", "onConnectionStateChange - status: "
                    + status + " - new state: " + newState);
            if (gatt.discoverServices())
                LogUtils.LOGI("DISCOVER_SERVC", "STARTED");
        } else
        // LogUtils.LOGI("DISCOVER_SERVC", "NOT_STARTED");

        if (newState == BluetoothProfile.STATE_CONNECTED) {
            LogUtils.LOGI("BLE_STATUS", "CON");

        } else if (newState == BluetoothProfile.STATE_DISCONNECTED) {

        }

        Log.i("BLE service", "onConnectionStateChange - status: " + status
                + " - new state: " + newState);

    }

    // Called when services are discovered on remote device
    // If success broadcast with device address extra is sent
    @Override
    public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {
            LogUtils.LOGI("BLE_STATUS", "SUCCESS");
        }
        Log.i("BLE service", "onServicesDiscovered - status: " + status);
    }

    // Called when characteristic was read
    // Broadcast with characteristic uuid and status is sent
    @Override
    public void onCharacteristicRead(BluetoothGatt gatt,
            BluetoothGattCharacteristic characteristic, int status) {
        Log.i("BLE service", "onCharacteristicRead - status: " + status
                + "  - UUID: " + characteristic.getUuid());
    }

    // Called when characteristic was written
    // Broadcast with characteristic uuid and status is sent
    @Override
    public void onCharacteristicWrite(BluetoothGatt gatt,
            BluetoothGattCharacteristic characteristic, int status) {
        Log.i("BLE service", "onCharacteristicWrite - status: " + status
                + "  - UUID: " + characteristic.getUuid());
    }

    // Called when remote device rssi was read
    // If success broadcast with device address extra is sent
    @Override
    public void onReadRemoteRssi(BluetoothGatt gatt, int rssi, int status) {
        if (status == BluetoothGatt.GATT_SUCCESS) {

        }
        Log.i("BLE service", "onReadRemoteRssi - status: " + status);
    }

    // Called when descriptor was written
    @Override
    public void onDescriptorWrite(BluetoothGatt gatt,
            BluetoothGattDescriptor descriptor, int status) {

        Log.i("BLE service", "onDescriptorWrite - status: " + status
                + "  - UUID: " + descriptor.getUuid());
    }

    // Called when notification has been sent from remote device
    // Broadcast with characteristic uuid is sent
    @Override
    public void onCharacteristicChanged(BluetoothGatt gatt,
            BluetoothGattCharacteristic characteristic) {
        Log.i("BLE service", "onCharacteristicChanged - status: "
                + "  - UUID: " + characteristic.getUuid());
    }
};

私が何をしても、サービスもBLEデバイスの特性も得られませんonConnectionstateChangeで 受け取っているステータスコードは133です

試した回避策:サービスUUIDを既に知っているので、以下に示すように GattCallBack でサービス オブジェクトを取得しようとしました

BluetoothGattService gattService = gatt.getService(device);
if (gattService == null) {
LogUtils.LOGI("GATT SERVICE", "null :" + gattService);
} else {
LogUtils.LOGI("GATT SERVICE", "not null :" + gattService);
}

しかし、結果は常にnullを返します

Gattservices と charectrestics を取得するにはどうすればよいですか?

4

0 に答える 0