Skip to first unread message

최유승

unread,
Aug 18, 2018, 1:59:11 PM8/18/18
to MIT App Inventor Forum

안녕하세요, 저는 한국에 사는 고등학생입니다. 제가 학교 과제 연구를 하다가 App Inventor를 사용하게 되었는데요, Bluetooth와 App Inventor가 통신을 합니다. 블루투스에서 '?'로 구분한 텍스트를 App Inventor에 보내면 저는 그 값을 블루투스로부터 받고, '?'로 분할을 합니다. 그러면 자동으로 목록이 생성이 되고, 그럼 그 생성된 값을 전역변수로써 지정합니다. 그러면 저는 그 전역변수를 Index를 입력해서 그 Index에 있는 값을 사용합니다. 하지만 제가 이 값을 사용하려고 하면(필터 닫기, 필터 열기, 창문 닫기, 창문 열기 등의 버튼을 클릭함으로써) 
Runtime Error

Select list item: Attempt to get item number 4 of a list of length 1: (*empty-string*)
Note: You will not see another error reported for 5 seconds.
라는 에러가 납니다. 제가 여기 질문을 올리기 전에 인터넷에서 찾아봐서 여러 번 고쳤었는데, 그래도 오류가 없어지지 않아서 질문을 남깁니다. 혹시 이 runtime error를 사라지게 하는 방법을 알고 계신 분들께서는, 가능하시다면 저를 도와주세요. Please, help me!
app inventor Question file.hwp

최유승

unread,
Aug 18, 2018, 2:05:44 PM8/18/18
to MIT App Inventor Forum
혹시 제가 올린 사진이 잘 보이지 않을 가능성이 있기 때문에 다시 올리겠습니다 위의 사진이 잘 보이지 않았다면 이 사진으로 봐주세요.
app inventor Questions Picture.hwp

최유승

unread,
Aug 18, 2018, 2:14:33 PM8/18/18
to MIT App Inventor Forum

Hello, I am a high school student living in Korea. I used App Inventor while doing my school assignments, and Bluetooth and App Inventor communicate. When you send text separated by '?' In Bluetooth to App Inventor, I get the value from Bluetooth and divide it by '?'. Then, the list is created automatically, and the generated value is specified as a global variable. Then I enter the global variable Index and use the value in that index. However, if I try to use this value (by closing the filter, opening the filter, closing the window, opening the window, etc.) Runtime Error Select list item: Attempt to get item number 4 of a list of length 1: (* empty-string *) Note: You will not see another error reported for 5 seconds. I get an error. Before I posted the question here, I found it on the internet and fixed it several times, but it still does not go away and leaves a question. If you know how to get rid of this runtime error, please help me if you can. Please, help me!


I translate my question to English. Please help me.

Chris Ward

unread,
Aug 18, 2018, 3:40:08 PM8/18/18
to MIT App Inventor Forum
Hi  최유승

We cannot view or open your image file.

However, does your global variable look like this?

Global String Variable.png


If it does, then change it to this:


Global List Variable.png



How to insert an image of your Blocks into your Forum Post Message:

Save Blocks Image For Forum.png



최유승

unread,
Aug 18, 2018, 8:46:26 PM8/18/18
to MIT App Inventor Forum

blocks.png


Abraham Getzler

unread,
Aug 18, 2018, 9:13:51 PM8/18/18
to MIT App Inventor Forum
Your trouble is in the attached button click event.

See the BlueTooth and Arduino section of FAQ
for samples.

AI2 apps for BlueTooth use a Clock Timer to check connectivity and
data availability, not a button click.

Apps that want to receive a list of values need to send their lists and
receive their lists intact, by using a message delimiter:
Use println() to separate messages when you transmit.
Set Delimiter = 10 in BlueTooth Designer.
Check for Bytes Available > 0 in blocks,
but then request -1 bytes to get only full  messages.

Also, your test for an empty list won't work.
'()' is text, not a list.

ABG
Blue Tooth Reception blocks.png

최유승

unread,
Aug 18, 2018, 9:56:03 PM8/18/18
to MIT App Inventor Forum
답변 정말 감사드립니다. 제가 한번 알려주신 대로 해보고, 안되는 것이나 궁금한 질문이 있으면 다시 질문하겠습니다. 당신의 답변에 정말 감사드립니다. 

최유승

unread,
Aug 18, 2018, 11:35:31 PM8/18/18
to MIT App Inventor Forum
Hello. I tryed as what you advised.

But I found that there is still error in program. error looks like this:

Select list item: Attempt to get item number 1 of a list of length 0: ()

Note: You will not see another error reported for 5 seconds.
 
Maybe I didn't follow your instruction. Can you check my blocks if I am doing right?
Also, I can't clearly understand what you mean by " printlln()". 
I'm using Arduino UNO board to operate the bluetooth module. Do I have to use println() function in Arduino or there is a function in App Inventor?

I'm sending you my fixed blocks. 

blocks (1).png

Thank you for your kind advise and help.

최유승

unread,
Aug 19, 2018, 10:59:21 AM8/19/18
to MIT App Inventor Forum

blocks (2).png

제가 방금 당신이 언급해준 조언을 모두 이해한 것 같습니다.  당신이 조언한 대로 프로그램을 바꿨지만 항상
Select list item: Attempt to get item number 1 of a list of length 0: ()
참고: 5초 동안은 다른 오류가 보고되지 않습니다.
라는 오류 메시지는 계속 존재합니다. 왜 계속 이런 오류가 존재하는지 잘 모르겠습니다. 제가 혹시 프로그램을 잘못 바꾼 것일지도 모릅니다. 만약 가능하다면 당신께서 왜 아직도 저런 오류가 존재하는지 봐주실 수 있습니까?
 Wish for your help. 

Abraham Getzler

unread,
Aug 19, 2018, 1:40:55 PM8/19/18
to MIT App Inventor Forum
Can you also post the .ino file here?

We need to see if it agrees with the AI2 app.

ABG

Abraham Getzler

unread,
Aug 19, 2018, 1:55:07 PM8/19/18
to MIT App Inventor Forum
Thank you for posting English blocks.

Please see my attachment.

Once you do a BlueTooth read Text,
don't do any more of those until you have finished with the
text you just read.  Also, do not do any more 
of your reading Bytes Available, just stick to asking for complete messages.

You should also make a new global variable, call it
message_parts, to hold the list made by splitting the incoming message
at the '?' marks.  This will make it easier to debug and to trace back 
the data.  This is like a detective taking care not to step
on the murderer's footprints at the crime scene.

I don't know the translation for your Korean global variable name(s),
so I suggested English names on the diagram.

Unfortunately, neither Windows Paint nor the Blocks Editor
can translate variable names.

ABG

Capture.PNG

최유승

unread,
Aug 19, 2018, 2:54:25 PM8/19/18
to MIT App Inventor Forum
I'm so grateful that you gave me reply this quickly.
Before trying to fix program as you told, I will send you .ino files to you.
To make the functions of .ino files clear, I thought that it would be better to give you details about my projects.

I'm trying to make the window and fine dust filter open automatically according to the air quality of the inside of the building and of the outside of it. To get the information of the interior air quality, I have connected three sensors(GP2Y1010AU0F, DHT11, MQ-7) to Arduino board. And to get the information of the outer air quaility, I used NodeMCU to connect to wifi, to access the pubilic API, to get the information what I want, and to send it to Arduino through the UART communication. After all the process, Arduino finally sends all of data to smartphone through the bluetooth module(HC-06). Receiving the data, smartphone user can see the air quality through the screen. Also, the user can control the window and fine dust filter through the app(actually, not yet lol).

Really, thank you for helping me.
IDE___-______-___.ino
NodeMCU_just_getting_API.ino

Abraham Getzler

unread,
Aug 19, 2018, 3:34:03 PM8/19/18
to mitappinv...@googlegroups.com
Since you are splitting your messages at '&' and
the IDE ....ino sends messages with data between '&' marks, I will
concentrate on that program.

line 30:  bluetooth.begin(115200);
Are you sure the AI2 BlueTooth compaonent can handle that speed?
I have seen 9600 used as a safe default.
It doesn't look like your data will be quickly changing.

line 60:
String s; 
s += dustten;
line 20: float dustten = 0;
Does the Arduino compiler do automatic float to string conversion?
(I don't know, just checking.)


Line 63: bluetooth.write(dustten);
My impression of the .write command is that it differs from the .print
command in that it sends raw data without converting it to text, right?
But your AI2 app depends on receiving only text, so it can spot delimiters
at the message and field level.  
(edit: So would print() work better here? - ABG)

I suggest appending all incoming data in your app to a file or a Label.Text,
so you can see what you are getting, that it is not garbage.

line 124:   bluetooth.print(s); 
this is where you sent the string s you have been building up.
I don't see println(), so you will be lacking the trailing LF (\n)
that Ai2 needs to cut off a single message and deliver it to the AI2 app whole.

I also don't see you resetting  s  to an empty string for the next 
build and transmit cycle.

Abg


최유승

unread,
Aug 20, 2018, 11:02:58 AM8/20/18
to MIT App Inventor Forum
Hello, and thanks for your speedy response.
Accroding to your words, I fixed the IDE program and App inventor blocks , and it worked!! Without you, I could never done this. 
I'm so glad that you helped me to reach out my hand to the end of the project.

However, I still have a problem : when smartphone user push the buttons like 창문_열기, the app should send a message(1 or 2 or 3 or 4) to arduino via bluetooth module. But I think arduino board don't receives the data. It shows me the number like 53, 13, 83 , etc(number that can't exsit). So I tryed to fix the problem, but I couldn't. The one thing I know is that the data is not from app inventor because when I remove RX pin of arduino, I still receive incomprehensible numbers. But I may be wrong.

I'm sendding you fixed program of arduino and blocks of app inventor. I hope I could receive your reply and, finally, finish the project!

Always, I'm extremely grateful for your helps.
blocks.png
IDE___-______.ino

Abraham Getzler

unread,
Aug 20, 2018, 12:22:37 PM8/20/18
to MIT App Inventor Forum
Be aware that I don't know Korean, and I have never personally used an Arduino,
so I am sticking to what I know in advising you ...

You are complaining about receiving garbage from AI2 in the Arduino.

The last person with that problem on this board had reversed
the receive and transmit wires between their BlueTooth board and
their Arduino.

I advise posting your wiring diagram or a good photo here,
so some one more experienced can double check that.

Another possibility is that you are sending your messages from AI2 as text,
but you are receiving them directly into non-text numeric fields,
so you are seeing ASCII codes (48-57) in your Arduino.

if(bluetooth.available()){
int a = bluetooth.read();
//delay(4000);
Serial.println(a);
    if(a == 1)

You capture the incoming  Bluetooth message into an int variable a,
using a bluetooth.read() command and use integer comparisons from there onwards.

Here's a research problem for you ...
Just as there is a difference between the write and print commands in encoding,
is there another command like maybe bluetooth.get to do conversion from text to int instead of bluetooth.read ?
Or can you do the conversion using an extra string variable, and explicitly convert from the string to the int variable using math or string commands?

Other observations  on your blocks ...

You repeat the same blocks at least 4 times in your ai2 button Click events.
A common procedure would reduce your block count.

You are analyzing your input stream in the same button.click events that send data to the Arduino.
Because the data does not arrive instantaneously, that is an inappropriate place to look for it.
Do your analysis in the Clock.Timer routine, and if necessary leave yourself a note in a global variable
that you sent something, if that's important to know.


you open Screen1.
That's always a mistake, leading to running out of memory.
Instead, close your screen and you should return to Screen1.
Beware, switching screens breaks your connections.


ABG




sendText.png

Chris Ward

unread,
Aug 20, 2018, 12:32:26 PM8/20/18
to MIT App Inventor Forum
Hi

You might like to try the software Fritzing. You can prototype your Arduino setup in Frizing, and the Korean language is supported too! It is very easy to use.



Reply all
Reply to author
Forward
0 new messages