HELP ... Using Bluetooth BLE HM-10 got error Index list too large

The error is simple: The list is only 4, or less, in length. Try removing the 5th set Label.Text block to see if it works, or repeat the same for the others if not.

1 Like

Yes it work if only 4 list.i tried it already before.
How can i make it work if i would add more list like 5 or more? Any advice?
Thanks in advance

1 Like

That means that your Arduino sketch is only giving 4 values, not 5.
Could you please copy-paste your sketch here?

1 Like

here is my Arduino code

#include <EEPROM.h>
int update1;
int update2;
int update3;
int update4;
int update5;

void setup() {
Serial.begin(9600);

update1 = EEPROM.read(6);
update2 = EEPROM.read(7);
update3 = EEPROM.read(8);
update4 = EEPROM.read(9);
update5 = EEPROM.read(10);

}

void loop() {
if (Serial.available() > 0) {
String buff1 = "";
buff1 = Serial.readString();

if (buff1.startsWith("wiw")) {
  Serial.print(update1);
  Serial.print("|");
  Serial.print(update2);
  Serial.print("|");
  Serial.print(update3);
  Serial.print("|");
  Serial.print(update4);
  Serial.print("|");
  Serial.print(update5);
  Serial.println();

}

}
}

1 Like

actually its working 5 list with those code of my arduino
the problem is when my update1 reach 3 digit number then it will show list index error.

i mean when update1 is equal to 99 is okay but when it becomes 100 then it show the error
same with other update2 & update3 update4 and update5 when they have value of 1 to 99 its okay but when it reach 100 then the error showing list index was too large .

hope you can help me thanks again for reply ^_^...

1 Like

Hi - that error is not specific to Bluetooth, it is just a List Index issue, as you have discovered. After your App code splits the received data into a List, always verify the List Length to avoid errors.

I think the underlying issue will be a combination of things but the main problem appears to be the time interval. If the data is sent too fast, the App cannot cope and the result is data overlap.

Your Sketch is effectively ignoring BLE and delivering Classic Bluetooth comms?

Anyway, try your Sketch with an elapsed milliseconds timer:

#include <EEPROM.h>
int update1;
int update2;
int update3;
int update4;
int update5;
unsigned long lgUpdateTime;      //Loop time interval

void setup()
{
Serial.begin(9600);

update1 = EEPROM.read(6);
update2 = EEPROM.read(7);
update3 = EEPROM.read(8);
update4 = EEPROM.read(9);
update5 = EEPROM.read(10);
lgUpdateTime = millis();
}

void loop()
{
         //Execute Comms approx every 800 milli seconds - tweak by trial and error
	     if(millis() - lgUpdateTime > 800)
         {
               lgUpdateTime = millis();

               if (Serial.available() > 0)
               {
               
                     String buff1 = "";
                     buff1 = Serial.readString();
                     
                     if (buff1.startsWith("wiw"))
                     {
                               Serial.print(update1);
                               Serial.print("|");
                               Serial.print(update2);
                               Serial.print("|");
                               Serial.print(update3);
                               Serial.print("|");
                               Serial.print(update4);
                               Serial.print("|");
                               Serial.print(update5);
                               Serial.println();
                     }
               }
         }
}

SketchModified.txt (1.4 KB)

2 Likes

thank you very much for the reply sir chistopher...

i try your sketch still not working even i try to adjust the time interval higher and lower still no luck..

i try to put 200+ all update1 to update5 still got error pop up.

but if i put only until 99 all update1 to update5 works okay but if i increase more than 99 then i got error.

again thanks for reply ...

Disable Block 'Initialize local list to'
and set a
LabelX.text = stringValues
to see what you are getting.

1 Like

Good day to you Sir Juan ,
i set my update1 to update5 = 99
and i got this in my serial monitor 99|99|99|99|99
and i run my application base to your request labelx.text = stringValues and disable my initialize list block.

and i got a result of this ["99|99|99|99|99"]

hope you can help me.. i think i getting problem of list index too large is in my block do you think?
thanks sir for reply :slight_smile:

Hello Michael

That's the result of the problem, not the cause.

  1. The value (byte) can range from 0 to 255, but you see a List failure if the value is above 99.

  2. Looking more at what you are trying to do - the EEPROM read is just a one-off? You do not need to repeat the reads as they will be the same from the same area of memory - is that right?

  3. Your experiment as requested by Juan - can you set it to:
    update1 to update5 = 255
    Serial monitor should show 255|255|255|255|255

..... but what does the App Show in the Label? Should be ["255|255|255|255|255"]

1 Like

Besides the 99 problem, the list stringvalues is being treated as a string instead of the way it should be treated, as a list of strings that need to be split at | into lists of 5 items each.

The proper handling of stringvalues is:

for each string in stringvalues
   set local list to split string at "|"
     assign items from list to 5 labels as before
end for each

That will eliminate the [" and "] wrappers and leave you with just whatever numbers arrived among the | separators.

1 Like

I just realised - the above string with a newline at the end is 21 bytes long. Typically, the default Bluetooth data packet size is 23 bytes of which the max payload is 20 bytes.

There are two ways around this:

  1. Increase the MTU (Max Transmission Unit) size - unfortunately, the HM-10 is v4.0 BLE and does not support this adjustment. (requires v4.2 and up).

  2. Send the values individually, with a short delay between them.

Yes correct in serial monitor it shows 255|255|255|255| and it show in label ["255|255|255|255|255"]

I just try to use EEPROM and i also test it with out eeprom just writing like this update1 to update5 = 255;

99 in all label at app was okay but when i make update1 to update5 = 100; then i got error.
Thanks for the reply.

Yes sir i can eliminate this [" "] by using replace text . I manage to do that.
Update1 to update 5 with a value of 99 its all working in app. But when i make update1 to update5 a value of 100 or more then i got an error index too large. Can u arrange my blocks to make it work sir? Thanks in advance. Im planning to add higher value and more list index but i dont know how to do it..
Hope you can help me Sir ABG :pray:

Sir ChrisWard
How can i do that 2nd option?
How to sketch it send the valie individually with a short delat between them.? How can i put then individually in separate label in my app?
Again thank you for reply :+1:

....

Need to know this :thinking:

I just change my sketch and remove the eeprom.
To make it better.. my target is i want to put higher value more than 99 even 1000 and add more list like 10 list index. How can i make it work? I can only make work with 5 index list with a higher value of 99. Its working but if i put 100 then i got the error.

int update1;
int update2;
int update3;
int update4;
int update5;

void setup() {
Serial.begin(9600);

update1 = 999;
update2 = 999;
update3 = 999;
update4 = 999;
update5 = 999;

}

void loop() {
if (Serial.available() > 0) {
String buff1 = "";
buff1 = Serial.readString();

if (buff1.startsWith("wiw")) {
Serial.print(update1);
Serial.print("|");
Serial.print(update2);
Serial.print("|");
Serial.print(update3);
Serial.print("|");
Serial.print(update4);
Serial.print("|");
Serial.print(update5);
Serial.println();

}
}
}

Sends a final message character, for example '#'.
Accumulate arrival information until that character arrives.
You will receive packages of up to 20 characters.
(abcdefghijklmnopqrst)
(abcdefgh #)

BTW, I prefer to separate the fields by commas instead of |

I will make an example of all this.

... We still need to know if the data is sent/read just once or multiple times over a period of time, as this affects how to code the best solution.

Because of the MTU related message size limit, you would have to break your message into multiple individual measurements, labelled to identify the data, like:

  • temp:80
  • voltage:1.2
  • humidity: 50
  • taste:delicious
  • feel:fluffy