Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
aitriago opened this issue Apr 25, 2024 · 2 comments
Closed

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

aitriago opened this issue Apr 25, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@aitriago
Copy link

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:

  • @capacitor-community/bluetooth-le: [e.g. 0.4.0]

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Browser [e.g. chrome, safari]
  • Version [e.g. 22]

Smartphone (please complete the following information):

  • Devices where there is no error:
  • iPhone (Latest iOS version)
  • Samsung S7 with Android Oreo (8.1)

-Devices with the BUG:

  • Samsung S23 ultra - Android 14
  • Xiaomi Redmi 9 - Android 12
  • Samsung Galaxy Tab A8 - Android 14

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.

@aitriago aitriago added the bug Something isn't working label Apr 25, 2024
@peitschie
Copy link
Collaborator

@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
Copy link
Member

pwespi commented May 4, 2024

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!

@pwespi pwespi closed this as completed May 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants