Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // MARK: - CBPeripheralDelegate
- extension BluetoothManager {
- func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {
- guard let services = peripheral.services else { return }
- for service in services {
- print(service)
- peripheral.discoverCharacteristics(nil, for: service)
- }
- }
- func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
- guard let characteristics = service.characteristics else { return }
- for characteristic in characteristics {
- if characteristic.properties.contains(.read) {
- // check for .read type characteristics
- print("\(characteristic.uuid): properties contains .read")
- peripheral.readValue(for: characteristic)
- }
- if characteristic.properties.contains(.notify) {
- // check for .notify type characteristics
- print("\(characteristic.uuid): properties contains .notify")
- }
- }
- }
- func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {
- switch characteristic.uuid {
- case bluetoothHM10ServiceCBUUID:
- guard let safeData = characteristic.value else { return }
- characteristicsData = safeData
- print(characteristicsData) // I HAVE 6 bytes of Data but I don't know how to decode that
- print([UInt8](characteristicsData)) // ???
- default:
- print("Unhandled Characteristic UUID: \(characteristic.uuid)")
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement