'Transmit binary file to device using BLE

I am working on an app which can read device information via bluetooth BLE. So far I've been able to connect to the device and read certain properties like state of charge and firmware version number on iOS, Android, and within Chrome. However, now I'm at the point where I need to update the firmware and I am confused how to do so.

Little back story, the app is written in Ionic + Vue + Capacitor so everything is JavaScript/TypeScript. So the BLE plugin I'm using is the Capacitor Community Bluetooth LE. Within the documentation it has a write method which wants deviceId, service, characteristic, and value. I know what I need to use for the first 3, but value is suppose to be DataView. Somehow I need to take a binary bin file and transmit it via this write command. I noticed that DataView is an ArrayBuffer with byteLength and byteOffset. I don't really know how to get my file into this format.

Assuming I have deviceId, service, characteristic, how can I grab this file and transmit a DataView using this write method?

Thanks in advance.



Solution 1:[1]

The native SDKs offer a "Socked"-based communication directly over the L2CAP protocol. (GATT uses L2CAP internaly)

Android

iOS

When a L2CAP Channel is registered an PSM (the "Port") is allocated by the device. This number must be communicated to the other peers. This could be done by including the number in the BLE advertisement or by exposing it over a GATT Characteristic

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 wiomoc