OnServicesDiscovered () не называется if requestMtu () и deciplyServices (), объединенные при подключении к периферийнымAndroid

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 OnServicesDiscovered () не называется if requestMtu () и deciplyServices (), объединенные при подключении к периферийным

Сообщение Anonymous »

Я сталкиваюсь с проблемой взаимодействия BLE между Android Central/Client (CompilesDK = 35), подключенной к периферическому/серверу, который инициирует его собственное переговоры о MTU: обнаружение услуг, по -видимому, застряло, а OnservicesDiscovered () никогда не называется. Bluetoothgatt.requestmtu () после подключения устройства. В случае этого конкретного устройства BLE, даже когда он номинально настроен в качестве периферического/сервера, оно также выступает в качестве центрального/клиента и инициирует согласование MTU. override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// initiate MTU negotiation and service discovery
gatt.requestMtu(512)
gatt.discoverServices()
}
BluetoothProfile.STATE_DISCONNECTED -> {
// Disconnected from device
}
}
}
}

override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// Services discovered, enable notifications if needed
.
.
.
}
}
< /code>
Если я удалю вызов в Bluetoothgatt.requestmtu (), то без проблем, но, очевидно, это не будет работать с другими устройствами BLE, которые не инициируют переговоры MTU. Если я отключаю переговоры MTU, инициированное периферическим, то без проблем. />
date /time < /th>
pid-tid < /th>
Tag < /th>
Level < /th>
message < /th>
< /tr>
< /thead>


< /tr>
< /thead>


< /tr>
< /thead>

/>2025-07-11 17:47:49.116
8165-8165
BluetoothAdapter
D
getBleEnabledArray(): ON


2025-07-11 17: 47: 49.118 < /td>
8165-8165 < /td>
bluetoothgatt < /td>
d < /td>
Xx: xx: xx: xx: 77: 30, Auto: false < /td>
< /tr>

2025-07-11 17: 47: 49.118 < /td>
8165-8165 < /td>
blootlegtgggggggggggggt> ald> < /td>
bloothgggggggggggG /> d < /td>
registerApp () < /td>
< /tr>

2025-07-11 17: 47: 49.119 < /td>
8165-8165 < /td>
8165-8165 < /td>
8165-8165 < /td> /> d < /td>
RegisterApp ()-uuid = a616f277-dd9b-4d9c-87c9-199cafe1cfc8 < /td>
< /tr>

2025-07-11 17: 49.11 < />
2025-07-11: 49.1 < />
2025-07-11: 49.11 < />
2025-07-11: 49. /> 8165-9333 < /td>
Bluetoothgatt < /td>
d < /td>
onclientRegistered ()-Состояние = 0 Clientif = 12 < /td>
< /tr>

201111111. 17: 47: 49.126 < /td>
8165-9333 < /td>
bluetoothAdapter < /td>
d < /td>
getbleenabledarray (): On < /td>
< /br />

/> 2025-07-11 17: 47: 50.596 < /td>
8165-9333 < /td>
bluetoothgatt < /td>
d < /td>
onclientConc Device = xx: xx: xx: xx: 77: 30 < /td>
< /tr>

2025-07-11 17: 47: 50.600 < /td>
8165-9333 < /td>
bluetOthGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTOOTHGGGT />D
configureMTU() - device: XX:XX:XX:XX:77:30 mtu: 512


2025-07-11 17:47:50.603
8165-9333 < /td>
bluetoothgatt < /td>
d < /td>
DiscoverServices () - XX: xx: xx: xx: 77: 30 < /td>
< /tr>

/> 2025-07-11 17: 47: 51.120 < /td>
8165-9333 < /td>
bluetoothgatt < /td>
d < /td>
OnConnectionUpdated ()- Device = XX: XX: XX: XX: 77: 30 Интервал = 6 Latency = 0 Timeout = 500 Status = 0 < /td>
< /tr>

2025-07-11 17: 47: 51.494 < /td>
8165-933333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333. /> Bluetoothgatt < /td>
d < /td>
OnConfigUreMtu ()-Device = xx: xx: xx: xx: 77: 30 mtu = 247 status = 0 < /td>
< /tr>

2011111111111111 17: 47: 51.569 < /td>
8165-9333 < /td>
Bluetoothgatt < /td>
d < /td>
onConnectionUpdated () - device = xx: xx: xx: xx: 77: 77: 77: 77: 307: 307: 307: 307: 307: 77: 307: 77: 307: 77: 307: 307: 77: 307: 77: 307: 77: 307: 307: 77: 77: 307: 307: 77: 307: 30: 77: 307: 77: 307: 77: 77: 307: 307: 77: 77: 30: 77: 307: 77: 77: 307: 77: 77: 77: 77: 307: 30 timeout=500 status=0



And the same thing but with the peripheral initiated MTU negotiation disabled:



date /time < /th>
pid-tid < /th>
Tag < /th>
Level < /th>
message < /th>
< /tr>
< /thead>


< /tr>
< /thead>


< /tr>
< /thead>

/> 2025-07-11 17: 52: 18.055 < /td>
8165-8165 < /td>
bluetoothAdapter < /td>
d < /td>
getbleenArdabled () < /td>
getbleenarray (): на < /td>
getbleenarray (): On < /td>
/>
2025-07-11 17: 52: 18.058 < /td>
8165-8165 < /td>
bluetoothgatt < /td>
d < /td>
Xx: xx: xx: xx: 77: 30, Auto: false < /td>
< /tr>

2025-07-11 17: 52: 18.058 < /td>
8165-8165 < /td>
blid> blTOTHGGGT> BlTOTHGG> < /td>
blid> alt att> br /td> alt att> 8165-8165 < /td> /> d < /td>
registerApp () < /td>
< /tr>

2025-07-11 17: 52: 18.058 < /td>
8165-8165 < /td>




. /> d < /td>
RegisterApp ()-uuid = c055ae54-e1d1-4f45-a276-9281537e3e2f < /td>
< /tr>

2025-07-11 17: 52: 18.063. /> 8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
onclientRegistered ()-Состояние = 0 Clientif = 13 < /td>
< /tr>

20111111111 < /td>
< /tr>
2011 < /td>
< /tr>
201 < /td>
< /tr>
201 < /td>
< /tr>

8165-8181 < /td>
bluetoothAdapter < /td>
d < /td>
getbleenabledarray (): On < /td>
< /br />

/> 2025-07-11 17: 52: 18.480 < /td>
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
onclientConc Device = xx: xx: xx: xx: 77: 30 < /td>
< /tr>

2025-07-11 17: 52: 18,482 < /td>
8165-8181 < /td>
bluetOthGGGGGT> Bl />D
configureMTU() - device: XX:XX:XX:XX:77:30 mtu: 512


2025-07-11 17:52:18.484
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
DiscoverServices () - устройство: xx: xx: xx: xx: 77: 30 < /td>
< /tr>

/> 2025-07-11 17: 52: 19.001 < /td>
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>
OnConnectionUpdated () Device=XX:XX:XX:XX:77:30 interval=6 latency=0 timeout=500 status=0


2025-07-11 17:52:19.423
8165-8181
Bluetoothgatt < /td>
d < /td>
OnConfigUreMtu ()-Device = xx: xx: xx: xx: 77: 30 mtu = 247 status = 0 < /td>
< /tr>

2011111111111111 17: 52: 19.425
8165-8181
bluetoothgatt
d
onsearchcomplete () = xx: xx: xx: xx: 77: 30: 30: 30: 30: 0. /> < /tr>

2025-07-11 17: 52: 19.425 < /td>
8165-8181 < /td>
bluetoothgatt < /td>
d < /td>

d < /td> UUID: 85FC567E-31D9-4185-87C6-339924D1C5BE Включение: true < /td>
< /tr>

2025-07-11 17: 52: 19.496 < /td>
816666661818: 19.496 < /td>
8166: 19.496 < /td>
8166: 19.496 < /td> /> Bluetoothgatt < /td>
d < /td>
onConnectionUpdated () - Device = xx: xx: xx: xx: 77: 30 Интервал = 36 Latency = 0 Timeout = 500 Статус = 0 < /td>
< /tr>
< /tbody>
/> < /table> < /div>
После захвата этих трассов я узнал, что если я ставлю вызов requestmtu () из onservicesdiscovered (), то нет проблем: < /p>
override fun onConnectionStateChange(gatt: BluetoothGatt, status: Int, newState: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
when (newState) {
BluetoothProfile.STATE_CONNECTED -> {
// initiate service discovery
gatt.discoverServices()
}
BluetoothProfile.STATE_DISCONNECTED -> {
// Disconnected from device
}
}
}
}
override fun onServicesDiscovered(gatt: BluetoothGatt, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// now initiate MTU negotiation
gatt.requestMtu(512)
}
}
override fun onMtuChanged(gatt: BluetoothGatt, mtu: Int, status: Int) {
if (status == BluetoothGatt.GATT_SUCCESS) {
// services discovered and MTU negotiated, enable notifications if needed
.
.
.
}
}
< /code>
Это ошибка? Я ничего не вижу в документах Bluetoothgatt, которые говорят, что requestmtu () и discoverservices () не могут быть вызваны вместе.

Подробнее здесь: https://stackoverflow.com/questions/796 ... ces-called
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»