Bluetooth Not Sending All Data

Hi Guys,

I was wondering if you could help me with a problem I am having.
I have built a project that required Bluetooth communication between a smart phone and an arduino uno.

The issue is that I am trying to send a bunch of data at the same time to the arduino and read that data into a string array for later use. But not all the data is reaching the arduino. I am not sure if I am overloading the buffer (if that's even possible) or there's something wrong with my code. The code and blocks are below. I do apologize if this is not the way to share blocks and code.
For some reason, the arduino seems to only be receiving 6 strings. For example, I will send something like,
JAMESON
JAMESON
JACK DANIELS
JACK DANIELS
AMARULA
AMARULA
J AND B
J AND B
JOHNNY WALKER
JOHNNY WALKER

But I will only receive

JAMESON
JAMESON
JACK DANIELS
JACK DANIELS
AMARULA
AMARULA

void BluetoothRead()
{

int counter = 0;
if (millis() >= timestampSend + (1000)) // sending data over BT every 500mS
{

while (bluetooth.available())
{
  delay(10);
  char data = bluetooth.read();
  readString += data;

  if(data == ' ')
  {
    DrinksFromApp[counter] = readString;
    Serial.println(DrinksFromApp[counter]);
    readString = "";
    counter++;
  }
  
}

Serial.println("Sent");
timestampSend = millis();

}
}

Hello Msindisi

There is a Bluetooth data packet size limit, and you are exceeding it :upside_down_face: Typically the payload is 20 bytes.

The way to avoid this problem is to either use representative codes instead of full names (e.g. JN = JAMESON, JD = JACK DANIELS etc), or send only one full name at a time.

Hi Chris,

I suspected as much. I am such a noob. I cannot shorten the names because a lot of the interconnecting pieces of code rely on seeing the full names to execute (rookie move I know). I am going to try sending one word at a time and see what happens. I'll let you know.

Thanks man.

That's not a problem, just needs two Block Lists, one containing the Full Names, the other containing the Abbreviated Names, in the same order so that the List indexes are identical.

Chris,

You legend you :slight_smile: .
So I tried sending the names one at a time, and I encountered a different problem. It look almost as though the Arduino code was not being given enough time time to copy all the data over. It would copy most of the data over, but the last one would be cut in half.
So I went with the painful solution of shortening the names and converting them back to the full names on the Arduino code, and it worked. My blocks and code now look like below. Thank you so much man. Simple solution to what turned out to be a more simple issue than I though.

void BluetoothRead()
{

int counter = 0;
if (millis() >= timestampSend + (1000)) // sending data over BT every 500mS
{

while (bluetooth.available())
{
  delayMicroseconds(10);
  char data = bluetooth.read();
  delayMicroseconds(10);
  readString += data;
  Serial.println(data);
  
  if(data == ' ')
  {
    delayMicroseconds(30);
    DrinksFromApp[counter] = readString;
    if(DrinksFromApp[counter] == "JN "){DrinksFromApp[counter] = "JAMESON";}
    if(DrinksFromApp[counter] == "JW "){DrinksFromApp[counter] = "JOHNNY_WALKER";}
    if(DrinksFromApp[counter] == "AM "){DrinksFromApp[counter] = "AMARULA";}
    if(DrinksFromApp[counter] == "JD "){DrinksFromApp[counter] = "JACK_DANIELS";}
    if(DrinksFromApp[counter] == "JB "){DrinksFromApp[counter] = "J_AND_B";}
    if(DrinksFromApp[counter] == "BS "){DrinksFromApp[counter] = "BELLS";}
    if(DrinksFromApp[counter] == "RM "){DrinksFromApp[counter] = "REMY_MARTIN";}
    if(DrinksFromApp[counter] == "KW "){DrinksFromApp[counter] = "KWV_SHIRAZ";}
    readString = ""; //clears variable for new input
    delayMicroseconds(10);
    Serial.println(DrinksFromApp[counter]);
    counter++;
  }
}
  if (readString.length() > 0) 
  {
    Serial.println("Received Value: " + readString);
    readString = ""; //clears variable for new input
  }

Serial.println("Sent");
timestampSend = millis();

}
}

I think you have done that nicely, if you are happy with the speed all is well. Instead of a ton of ifs, Arduino C offers 'switch':

         switch (readString)
         {

                     case 'JN':
                              DrinksFromApp[counter] = "JAMESON";
                              break;

                     case 'JW':
                              DrinksFromApp[counter] = "JOHNNY_WALKER";
                              break;

                     case 'AM':
                              DrinksFromApp[counter] = "AMARULA";
                              break;

                     case 'JD':
                              DrinksFromApp[counter] = "JACK_DANIELS";}
                              break;
         }

I'm going to to do this right now. Thanks again Chris.