Select list item: Attempt to get item number 2 of a list of length 1:[“[]"]

Hi. I am trying to develop an irrigation automation system for my doctoral thesis. I obtain the climate data via bluetooth. Afterwards, my aim is to find the amount of irrigation with some calculations, and send the average and some cumulative climate values of that day to Google Sheets. But I get this notification. select list item: Attempt to get item number 2 of a list of length 1:["[]] .I tried TIMAI2 solution alternatives but no result. If you help me I would be greatful.
PROJE (1).aia (914.7 KB)

The error message have told you every thing:
check all your "Select list item" blocks, at least one of them the list is contaning only 1 item '[]', but you are trying to get second.

If you are asking for help, I recommend you to make it as easy for others to be able to help you ...
You probably will get more feedback then...

which means in your case post a screenshot of your relevant blocks...

To download the aia file, upload it to App Inventor, open it, do some bug hunting for you, etc... this takes time, and most people will not do that...
Thank you.

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

Sorry Taifun.



The error seems to occur here


Check the length of the list before trying to select the 2nd item
Taifun

Please see the Delimiter article in FAQ

Be sure to use println() at the end of each message to send from the sending device, to signal end of message. 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.

1 Like

You need to show us your .ino file too.

You are misusing the text SPLIT block against lists.
Your format procedure returns a list from column 12 of your downloaded table.

Here are some offending blocks:
blocks (2)