capacitor-community / bluetooth-le

Capacitor plugin for Bluetooth Low Energy
MIT License
274 stars 79 forks source link

Unable to read buffer with more than 512 bytes with read function #651

Closed aitriago closed 4 months ago

aitriago commented 4 months ago

Describe the bug We read and write a JSON config file to a device using read and write functions. If the file is shorter than 512 bytes, everything runs fine. But then it is longer, in Android devices we get up to 512 bytes.

To Reproduce You will need a device that allows reading/writing capabilities/

  1. Scan and connect to the BT using your Android device.
  2. Write a string with more than 512 bytes using write function.
  3. Read the written string using read function.
  4. Compare both strings.

Plugin version:

Desktop (please complete the following information):

Smartphone (please complete the following information):

-Devices with the BUG:

Additional context The JSON file we write:

{"wifi": {"ap_pass": "password", "sta_ssid": "Entrepanoles", "sta_pass": "entrepanesq244", "ap_ssid": "tankmont3l3m0"}, "channel": [{"min_level": "10.00", "max_level": "100.00", "chan_label": 1, "type": "RS485|ADC", "name": "Mi tanque grande en el cuarto azul", "min_volt": 0, "idpin": 1, "enable": false, "min_amp": 0, "tank_capacity": "5000.00"}], "info": {"refresh_interval": 30, "model": "XXXXX-S3", "interval": 30, "mcu_id": "3030f959d194", "channels": 1, "url": "https://api.XXXXXXXXX.net/api/v1", "refresh_inerval": 30}}

The JSON file we read:

{"wifi": {"ap_pass": "password", "sta_ssid": "Entrepanoles", "sta_pass": "entrepanesq244", "ap_ssid": "tankmont3l3m0"}, "channel": [{"min_level": "10.00", "max_level": "100.00", "chan_label": 1, "type": "RS485|ADC", "name": "Mi tanque grande en el cuarto azul", "min_volt": 0, "idpin": 1, "enable": false, "min_amp": 0, "tank_capacity": "5000.00"}], "info": {"refresh_interval": 30, "model": "XXXXX-S3", "interval": 30, "mcu_id": "3030f959d194", "channels": 1, "url": "https://api.XXXXXXXXX.net/api/v1", "refresh Add any other context about the problem here.

peitschie commented 4 months ago

@aitriago this is likely an issue with your Bluetooth device.

Each read command here generally corresponds to a single BLE packet, that normally are usually between 185 up to about 512 bytes. If your payload is exceeding the MTU (maximum transmission unit) that the BLE receiver & BLE device have negotiated, it will be cut off.

You will need to change your peripheral implementation to properly support Long Attribute Reads if you are sending payloads that exceed a single packet. See https://stackoverflow.com/questions/38241986/ble-read-long-characteristics-value-using-android-ios for some discussion about this. But, there's nothing that can be fixed or handled in the plugin for this.

pwespi commented 4 months ago

You will need to change your peripheral implementation to properly support Long Attribute Reads if you are sending payloads that exceed a single packet. See https://stackoverflow.com/questions/38241986/ble-read-long-characteristics-value-using-android-ios for some discussion about this. But, there's nothing that can be fixed or handled in the plugin for this.

I agree. Thank you @peitschie!