Select list item: List index too large

I recently made an app but when i connect the item with Bluetooth, a message pops up which says "Select list item: List index too large" and "Select list item: Attempt to get item number 2 of a list of length 1: ["29"] ". I checked other posts on this topic, but they did not help. PLEASE HELP
A_C_S (2).aia.txt (3.7 MB)
this is my program converted to .aia (it was a .apk)


my coding


the error
Thank you

It means that the length of the list is 1 and you are trying to select item from list at 2nd index which is causing error.
Note: the index starts with 0.
0 for the first item and 1 for second item

Try this:
set global level to select list item list = get global ipAdress
index = 0

1 Like

Sorry, but i am new to app builder. I cant understand what you mean by

can you expain how to do that or can you give me a picture of the fode i should impliment please
P.S. @CodeNiche thank you for the quick reply :grinning: :slight_smile:

Can you provide aia
The aia you gave is is invalid
You are saying that you renamed .apk to .aix, but that will not convert the file to .aia format. Try downloading .aia from project>export aia

You are wrong, an index starts with 1 in App Inventor
Taifun

Is it so? Sorry for that

A_C_S.aia (27.2 KB)

So what should i do? :thinking: :sweat:

@Taifun please help me in this.
A_C_S.aia (27.2 KB)
here is the .aia format of the app. what should i do?

Read and understand the error message
This is the data you receive: 29°

Screenshot_20241201_112742_DuckDuckGo

This is a list, which does have one item, there is no second item... and it is not an ip address, it looks like a temperature

Taifun

yes, it is a temprature. i am using a web server to get the temprature using esp32
Can i solve it @Taifun

What exactly do you like to solve?
A temperature is not an ip address...
Just select the first item to get the temperature...

Taifun

dear @Taifun thank you for your reply
i updated it to


but still an error

:sob: :sob:


Taifun

Be sure to use println() at the end of each message to send from the sending device, to signal end of message.

Only use print() in the middle of a message.

Be sure not to println() in the middle of a message, or you will break it into two short messages and mess up the item count after you split the message in AI2.

Do not rely on timing for this, which is unreliable.

In the AI2 Designer, set the Delimiter attribute of the BlueTooth Client component to 10 to recognize the End of Line character.
BlueToothClient1_Properties
Also, return data is not immediately available after sending a request,
you have to start a Clock Timer repeating and watch for its arrival in the Clock Timer event. The repeat rate of the Clock Timer should be faster than the transmission rate in the sending device, to not flood the AI2 buffers.

In your Clock Timer, you should check

  Is the BlueTooth Client still Connected?
  Is Bytes Available > 0?
     IF Bytes Available > 0 THEN
       set message var  to BT.ReceiveText(-1) 

This takes advantage of a special case in the ReceiveText block:

ReceiveText(numberOfBytes)
Receive text from the connected Bluetooth device. If numberOfBytes is less than 0, read until a delimiter byte value is received.

If you are sending multiple data values per message separated by | or comma, have your message split into a local or global variable for inspection before trying to select list items from it. Test if (length of list(split list result) >= expected list length) before doing any select list item operations, to avoid taking a long walk on a short pier. This bulletproofing is necessary in case your sending device sneaks in some commentary messages with the data values.

Some people send temperature and humidity in separate messages with distinctive prefixes like "t:" (for temperature) and "h:" (for humidity).
(That's YAML format.)

The AI2 Charts component can recognize these and graph them. See Bluetooth Client Polling Rate - #12 by ABG

To receive YAML format messages, test if the incoming message contains ':' . If true, split it at ':' into a list variable, and find the prefix in item 1 and the value in item 2.

...

I want to make an app to show temprature (and give motion[such as forward]). I made the app and downloaded it. first it was showing one error. I posted it here hoping for help. but now another error is occuring.


please help me solve it.
P.S. i am a newbie so please tell me what to do step-by-step
p.s.s.

code which deals with bluetooth


total code

Where is the sketch sending the data to the app?

Here is a simple BlueTooth text receiver sample, for single value per line:
blocks
initialize global message to


@ABG

The part in blue give data to the ESP32( i am using it as the microontroller) and in black receives data

Who has the esp32 code?