Receiving incomplete Strings sent by Bluefuit LE to android

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
smartelements
 
Posts: 2
Joined: Tue May 31, 2022 9:57 am

Receiving incomplete Strings sent by Bluefuit LE to android

Post by smartelements »

Hello,

I tried a simple example to transmit strings from the adafruit bluefuit ble device to an app created with the MIT app inventor. It works fine but I noticed that about 3% of the sent strings are cutoff or incomplete.

I use following code to transmit a string within a loop. The code is executed every 500 ms.

float mvbat=5.25;
String string=String (mvbat)+"!25!23!100";

ble.print("AT+BLEUARTTX=");
ble.println(string);
ble.waitForOK;

So the string im sending should be "5.25!25!23!100"

On the App side I just register for strings and read out the data with following procedure
[img]
MIT-App.jpg
MIT-App.jpg (289.17 KiB) Viewed 148 times
[/img]

Mostly I get the full string, but 3 of 100 submitted strings arrive like "5!25!23!100" or "!23/100" etc.
I included an error counting label (Errors) and a counter (TXcount) for received strings as well as a filter to only process complete strings to avoid a crash of the app.
I tried almost everything but I have no idea why the strings sometimes are incomplete. What is going on here?

Thank you for your help.

User avatar
mikeysklar
 
Posts: 14165
Joined: Mon Aug 01, 2016 8:10 pm

Re: Receiving incomplete Strings sent by Bluefuit LE to andr

Post by mikeysklar »

Are you using HW serial or SW serial? Enabling HW flow control might be an option.

This is from the BLE FAQ:
Using CTS and RTS isn't strictly necessary when using HW serial, but they should both be used with SW serial, or any time that a lot of data is being transmitted.
The reason behind the need for CTS and RTS is that the UART block on the nRF51822 isn't very robust, and early versions of the chip had an extremely small FIFO meaning that the UART peripheral was quickly overwhelmed.
Using CTS and RTS significantly improves the reliability of the UART connection since these two pins tell the device on the other end when they need to wait while the existing buffered data is processed.
To enable CTS and RTS support, go into the BluefruitConfig.h file in your sketch folder and simply assign an appropriate pin to the macros dedicated to those functions (they may be set to -1 if they aren't currently being used).
Enabling both of these pins should solve any data reliability issues you are having with large commands, or when transmitting a number of commands in a row.
https://learn.adafruit.com/introducing- ... aq-2346704


Do you know which firmware version you are running on the Bluefruit LE Friend? 0.7.0 or higher would be a good.

User avatar
smartelements
 
Posts: 2
Joined: Tue May 31, 2022 9:57 am

Re: Receiving incomplete Strings sent by Bluefuit LE to andr

Post by smartelements »

Hi, Thank you for your help.

My device is the Feather 32u4 bluefruit LE and I am using HW SPI using the UART_CMD Mode script as basis. When I use the data mode there are even more dropped packets.
I have the actual Firmware blefriend 0.8.1 installed.
The problem only occurs when I read the strings through my android app. When I use the Adafruit BLE UART app there seem to be no errors. No idea if there are internal error checkers used.

At the moment I just check every string for correct length and correct amount of data. But this seems not to be an elegant solution.

User avatar
mikeysklar
 
Posts: 14165
Joined: Mon Aug 01, 2016 8:10 pm

Re: Receiving incomplete Strings sent by Bluefuit LE to andr

Post by mikeysklar »

@smartelements,

Thank you for the clarification and firmware version.

Have you tried to running the Adafruit Bluefruit Connect app on Android to confirm the UART side also works as it does for iOS?

In terms of the SPI in UART_CMD mode SDEP has a built-in error checking. Details in the link below.
SDEP was designed as a bus neutral protocol to handle binary commands and responses -- including error responses
https://learn.adafruit.com/adafruit-fea ... -2177408-4

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”