Is it normal for a bluetooth device to drop data/packages?

Hi,

I have a question, when transferring data over a Bluetooth UART connection is it normal to loose some packets every now and then? Maybe my programming is wrong but i want to know this because i am reading a file line by line from an SD card and sending it to my phone via Bluetooth Low Energy. Everything sends fine with the occasional error trigger prompting me that a packet was not sent. I noticed this only happens randomly and is not consistent. The error is triggered when i call:

if (!ble.waitForOK()) {
        Serial.println("Failed to send");
      }

Please see code attached below, everything is in there including my components make and model:

AirQuality.ino (8.24 KB)

I am not familiar with using that BLE device but I would not expect problems unless perhaps they are caused by interference from other equipment using 2.4GHz.

It would be wise to design your program to be able to deal with failed messages.

It is not a good idea to use the String (capital S) class on an Arduino as it can cause memory corruption in the small memory on an Arduino. Just use cstrings - char arrays terminated with 0.

...R

Thank you for your reply. My best programming language is Java and i hardly used any characters only String and its functions. I read here Arduino String Object that you can use the String Object if you have sufficient memory. So far my Sketch is 90% done and uses 13% storage space and 21% dynamic memory since its an Arduino Mega 2560 R3. That's also generous since I'm including the printing to the serial for debugging purposes. If you saw, i only have one String global variable and the other two are just temporarily used for buffer contents. If you really think this is an issue with my program, i will follow your advice and try to use the other non familiar techniques you described. By doing that, i would have to restructure the program, but i am willing to do so if you believe it is what must be done.

Regarding the Bluetooth problem with dealing with failed messages and given your experience with bluetooth, could it be that i am iterating through the loop too fast and the call ble.WaitForOK() doesnt have enough time to respond. For example it may still be sending the last message so it will throw that error? What do you think about implementing a timer and only send line by line each x amount of time? Also if the above must be done could you provide an example of how you would read line by line and send its contents in c.String or char * :confused: you dont have to do this last bit i would have to research but i have looked at it in the past, i guess we have to face the monsters sooner or later hehe.

xxcanizeusxx:
If you saw, i only have one String global variable and the other two are just temporarily used for buffer contents. If you really think this is an issue with my program,

The problem is not the amount of Arduino memory the IDE says is used when compiling but the way the String class dynamically allocates memory while the program is running. IMHO there is not enough spare SRAM to be sure that the class will never conflict with some other use of a memory location. It's up to you to decide whether you want to live with the risk of a crash.

When making the switch from Java (or any other language) on a PC keep in mind that the PC probably has 4,000,000 kilobytes of SRAM whereas an Arduino Mega has 8 and an Uno has 2

Regarding the Bluetooth problem with dealing with failed messages and given your experience with bluetooth, could it be that i am iterating through the loop too fast and the call ble.WaitForOK() doesnt have enough time to respond.

As I said I have no knowledge of the SPI BLE bluetooth module you are using so I can't comment. The only bluetooth module I have used is a HC06 (which is not BLE) and which connects to a serial port. You could query one of those as fast as you like.

I do have experience with nRF24L01+ transceivers that use SPI and, again, you can call them as often as you want to.

...R