Terms
- BLE: Bluetooth Low Energy (=Bluetooth LE)
- RFCOMM: 블루투스 프로토콜
- RFCOMM (TCP 사용), Radio Frequency Communications
- 하위에서 L2CAP을 사용, TCP/IP 서비스
- L2CAP (UDP 비슷), Logical Link Control and Adaption Protocol
- Profiles: Defined BLE devices specification, how a device works, A device could contain more than one profile.
- GATT (Generic Attribute Profile): General specification for send/receive attributes(short pieces of data) over BLE link.
- All BLE application profiles are based on GATT.
- ATT (Attribute protocol)
- GATT is built on top of the Attribute Protocol (ATT).
- (=
GATT/ATT) - Each attribute is uniquely identified by a UUID
- The attributes transported by ATT are formatted as
characteristicsandservices.
- Characteristic(type)
- single value: value itself
- 0-n descriptors: metadata of single value
- Service: a collection of characteristics
- e.g., Heart Rate Monitor
상호작용
Central vs peripheral
- 중앙: 스캔하여 advertise를 찾음
- 주변(peripheral): advertise
peripheral role만 있는 두 기기, 또는 central role만 있는 두 기기 끼리는 talk 불가.
GATT server <-> GATT client
Establish 이후, 어떻게 talk할지 결정.
- client: sends request
- server: return
상호작용 예시
- 휴대폰(central), BLE device를 스캔한다. BLE device는 advertise하고 있다.
- 휴대폰과 BLE device가 establish conn
- start transferring GATT metadata each other
- 이때 phone이 request를 보내니, GATT client, BLE device가 GATT server.
Basic
- 페어링 및 결합 프로세스
- 기기 검색
- 블루투스 요청 수락
- 보안키 교환 (결합 프로세스)
- 보안 키 캐시
- 통신 채널 형성
- 세션 완료 시, 요청 시작한 기기가 검색 가능한 기기에 연결한 채널을 해제
- 이 경우(두 기기 모두 연결을 삭제하지 않은 경우) 향후 세션 중에 자동으로 다시 연결할 수 있습니다.
BLE
android.bluetooth.le API
Usecase
- 근처 기기 사이에서 소량의 데이터를 전송합니다.
- 근접 센서와 상호작용하여 현재 위치에 따라 사용자에게 맞춤설정된 환경을 제공합니다.
! 사용자가 BLE를 통해 기기를 다른기기와 페어링하면, 두 기기 간에 교환된 데이터에 사용자 기기의 모든 앱이 액세스 가능. 민감 데이터는 앱 레이어에 보안 구현하여 보호해야 함.
Find BLE devices
startScan(ScanCallback)
- find하면 반드시 asap stop scanning
- Never scan on a loop, set a time limit on scan
handler: worker thread -> handler -> Main Thread(or worker thread)에 메시지 전달, Message Queue (FIFO)
Top comments (0)