We were DFU-Library to upload firmware to our BLE accessory earlier. But our new set of accessories doesn't support DFU library and we need to upload the firmware to an OTA service in its respective characteristics and we does the same using following code,
func prepareChunksToTransfer(fromData: Data) -> [Data] {
var offset = 0
var bytesToSend = fromData.count
let packetSize = BoardInformationService.packetSize
var chunkArray: [Data] = []
repeat {
let chunkLength = min(bytesToSend, packetSize)
let chunk = fromData.subdata(in: Int(offset) ..< Int(offset + chunkLength))
chunkArray.append(chunk)
offset += chunkLength
bytesToSend -= chunkLength
} while bytesToSend > 0
print("BT: Total Chunk size:\(chunkArray.count)")
return chunkArray
}
func uploadNextChunk() {
if let firmwareCharacteristic = fileCharacteristic {
print("Found fileCharacteristic to upload")
if self.currentPacket < self.totalNumberOfPackets {
// Send next chunk
let nextPacket = self.fileByteChunkArray[self.currentPacket]
print("BT: current packet uploading: \(self.currentPacket)/\(self.totalNumberOfPackets) Data:\(nextPacket)")
self.currentPacket += 1
// Write to peripheral
BTDiscovery.sharedInstance().peripheralBLE.writeValue(nextPacket, for: firmwareCharacteristic, type: .withResponse)
} else {
updateCompleteCompletion!()
}
} else {
print("No fileCharacteristic to upload")
}
}
// This is a delegate method which gets called when we get response from our peripheral after sending each packet.
func ackReceivedFromPeripheral() {
uploadNextChunk()
}
But this doesn't work on iOS but the same approach working on Android. Can you please guide me what could be wrong here.
Expected behaviour: After data transfer gets completed the ble device should start the firmware update which is not occurring on iOS even though full data is transferred.
FYI: Peripheral has esp32