Skip to first unread message
Assigned to juanan...@gmail.com by chrisw...@gmail.com

Jahangir Ziaul

unread,
May 16, 2018, 5:28:51 AM5/16/18
to MIT App Inventor Forum
Sir, I developed an app which receives four values from an Arduino via Bluetooth. Everything is working fine except that the values received are lagging behind around 3000ms and sometimes more. I kept the time interval setting to 1 ms but I still don't see any improvement. Also, there is a bluetooth socket error that notifies "BT socket closed -1" after around 50 secs.
Screen1.png
sketch_may06a.ino

Chris Ward

unread,
May 16, 2018, 7:10:06 AM5/16/18
to MIT App Inventor Forum
Hi Jahangir

While we are waiting for a reply from somebody that knows what they are talking about concerning Bluetooth and Arduino, the error message you receive is clear - either the code or the device (hardware fail) has "closed" the socket.

Is the error intermittent? If it is, that would explain the lag time. Is the Arduino well within range?


Your App Inventor blocks are very difficult to navigate. Tip: In the Blocks View workspace, right click and select "Clean up Blocks". This arranges all the blocks in one vertical column. Anytime you add or delete blocks, run "Clean up Blocks" and you are good to go.

I have asked Arduino expert Juan Antonio if he can help.


Abraham Getzler

unread,
May 16, 2018, 12:02:26 PM5/16/18
to MIT App Inventor Forum
Your blocks don't set the timer interval in your Clock component.
We can only guess, unless you include the .aia or
a screen shot of the Designer Clock attributes.

Your .ino file delays 30 ms per message.

You say you are experiencing a backlog,
and you are expecting a LF delimiter in your
.ino and blocks
(but we can't see if you set the Delimiter to 10
in the Designer BlueTooth Component attributes.;
since you are not getting list errors, you're probably okay there.)

I am guessing that you can't keep up with the data stream
from the Arduino.  

I would raise the Arduino delay to 1000,
and set the AI2 Clock delay at 500,
assuming you are not measuring quickly changing data.
That would immediately clear your backlog,
and not give either device a nervous breakdown.

ABG

Juan Antonio

unread,
May 16, 2018, 2:25:29 PM5/16/18
to MIT App Inventor Forum

As Abraham wrote, it works well and fast. This is a miminum code.
Clock.Interval = 500 Bluetooth.DelimiterByte = 10

Arduino:
delay(300);


Abraham Getzler

unread,
May 16, 2018, 2:45:08 PM5/16/18
to MIT App Inventor Forum
You will learn more about the incoming data buffer if you
display the Bytes Available value in a Label each clock cycle.

Watch it keep increasing if you don't request data
at least as often as it's arriving.

ABG

Juan Antonio

unread,
May 16, 2018, 5:11:16 PM5/16/18
to MIT App Inventor Forum

I continue with the idea of ​​Abraham...

Code Arduino, set delay(300);

Set Label2.Text = ClientBluetooth1.BytesAvailableToReceive
Set Clock1.Interval = 800

Watch Label2, increment.

When Label2, get a great number, example... 200

Disconnect Arduino (power off)(or simply disconnect BT)

Look as in Label2 decrease value, leaving buffer.
Reply all
Reply to author
Forward
0 new messages