Содержание
- 2. Bluetooth с низким энергопотреблением или Bluetooth 4. Android 5.0+ iOS 9.0+ Не нужна лицензия MFI от
- 3. Для чего нам BLE?
- 4. Два стека
- 5. Android vs iOS 3898 строк кода 60 дней отладки 1124 строк кода 10 дней отладки
- 6. BLE Device
- 7. BLE flow
- 8. Advertising and Scan
- 9. Scan private void scanLeDevice(final boolean enable) { if (enable) { ParcelUuid uuid = ParcelUuid.fromString("UUID"); ScanFilter scanFilter
- 11. Connect №1 bluetoothGatt = device.connectGatt(context, autoConnect, gattCallback);
- 12. GattCallback onConnectionStateChange(BluetoothGatt gatt, int status, int newState) onServicesDiscovered(BluetoothGatt gatt, int status) onCharacteristicRead(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, int
- 13. Особенности Android BLE #1 Необходима синхронизировать работу с GATT GATT операции должны быть выполнены в одном
- 14. Особенности Android BLE #2 ArrayBlockingQueue + Semaphore + BleDeviceThread = No GATT FAIL?
- 15. Connect №2 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { bluetoothGatt = device.connectGatt(context, autoConnect, gattCallback, BluetoothDevice.TRANSPORT_LE); } else {
- 16. OnConnected Работу с девайсом можно начать после onServicesDiscovered Если не удалось подключиться, пробуем заново Если не
- 17. Android is hardcoded
- 18. Read Characteristic characteristi = gatt.getService(...).getCharacteristic(…) gatt.readCharacteristic(characteristic) onCharacteristicRead -> characteristic.getValue()
- 19. Write Characteristic characteristic = gatt.getService(...).getCharacteristic(…) haracteristic.setValue(value) gatt.writeCharacteristic(characteristic) onCharacteristicWrite -> подтверждение (Device)
- 20. Write with no response characteristic = gatt.getService(...).getCharacteristic() haracteristic.setValue(value) characteristic.setWriteType(BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE) gatt.writeCharacteristic(characteristic) onCharacteristicWrite -> подтверждение (Android)
- 21. Notification characteristic gatt.getService(...).getCharacteristic() gatt.setCharacteristicNotification(characteristic, enable) onCharacteristicChanged -> characteristic.getValue()
- 22. Особенности Android BLE #3 If (NOT_WORK) { RETRY(); }
- 23. Disconnect с стороны Android gatt.disconnect() onConnectionStateChange -> gatt.close() НЕ вызывайте disconnect а затем сразу close. Одного
- 24. Disconnect с стороны Device status == 0 –> девайс отключится в штатном режиме -> gatt.close() status
- 25. Что там на iOS? didUpdateState didDisconnectPeripheral didDiscoverServices didUpdateValueForCharacteristic etc convenience init(delegate: CBCentralManagerDelegate?, queue: DispatchQueue?)
- 27. Скачать презентацию