BLE receive 20 Bytes Not possible

I used the following code to receive an hey Byte array! I only get 3 bytes although my ble device sends 20! What am I doing wrong?? // // ViewController.swift // BLECiprisExample // // Created by Johannes Loibner on 30.01.19. // Copyright © 2019 Johannes Loibner. All rights reserved. // import UIKit import CoreBluetooth let serviceID = CBUUID(string: "bc2f4cc6-aaef-4351-9034-d66268e328f0") let characteristicID = CBUUID(string: "06D1E5E7-79AD-4A71-8FAA-373789F7D93C") //818AE306-9C5B-448D-B51A-7ADD6A5D314D class CabinViewController: UIViewController { var centralManager: CBCentralManager! var cabin: CBPeripheral! override func viewDidLoad() { super.viewDidLoad() centralManager = CBCentralManager(delegate: self, queue: nil) //centralManager.scanForPeripherals(withServices: nil) } } extension CabinViewController: CBCentralManagerDelegate { public func centralManagerDidUpdateState(_ central: CBCentralManager) { switch central.state { case .unknown: print("central.state is .unknown") case .resetting: print("central.state is .resetting") case .unsupported: print("central.state is .unsupported") case .unauthorized: print("central.state is .unauthorized") case .poweredOff: print("central.state is .poweredOff") case .poweredOn: print("central.state is .poweredOn") centralManager.scanForPeripherals(withServices: [serviceID]) } } public func centralManager(_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any], rssi RSSI: NSNumber) { print(peripheral) cabin = peripheral cabin.delegate = self centralManager.stopScan() centralManager.connect(cabin) } func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) { print("Connected!") cabin.discoverServices([serviceID]) } } extension CabinViewController: CBPeripheralDelegate { func peripheral(_ peripheral: CBPeripheral, didDiscoverServices error: Error?) { guard let services = peripheral.services else { return } for service in services { peripheral.discoverCharacteristics([characteristicID], for: service) } } func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) { guard let characteristics = service.characteristics else { return } for characteristic in characteristics { print(characteristic) if characteristic.properties.contains(.read) { print("\(characteristic.uuid): properties contains .read") } if characteristic.properties.contains(.notify) { print("\(characteristic.uuid): properties contains .notify") cabin.setNotifyValue(true, for: characteristic) let pink: [UInt8] = [0x82] let writeData = Data(bytes: pink) cabin.writeValue(writeData, for: characteristic, type: .withResponse) } } } func peripheral(_ peripheral: CBPeripheral, didWriteValueFor characteristic: CBCharacteristic, error: Error?) { guard error == nil else { print("Error discovering services: error") return } print("Message sent") } func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { let characteristicData1 = characteristic.value let byteArray1 = [UInt8](characteristicData1!) print("yes: \(characteristic.value!.hexEncodedString())") } } extension Data { func hexEncodedString() -> String { return map { String(format: "%02hhx", $0) }.joined() } }

Replies

Could you first edit the code in a readable format (use code formatter <>). It is too hard to read as is.