Slow application with BLE

99 views
Skip to first unread message

Bastien D.

unread,
Aug 28, 2019, 8:55:38 AM8/28/19
to mitappinv...@googlegroups.com
Hello everyone, 

I have an application that connects to 3 dial indicators with Bluetooth (BLE) and which asks the value of these indicators every second. It works terribly well. 

The problem: after a certain time of display of values, the application becomes slow. 
For me, the application saves a series of useless data. How can I handle this?

 Here is the application in .png
Thank you, 
Bastien
blocks.png
Message has been deleted

Ghica

unread,
Aug 28, 2019, 9:29:46 AM8/28/19
to MIT App Inventor Forum
I think you are somehow choking the message buffers.
For starters, could you post a readable set of blocks? Like do a cleanup blocks first and then download blocks as image.

Do you have the coding of the BLE devices too? Because I would think that once you register for strings and maybe set a response interval, the BLE device would start sending messages all by itself. 
That would simplify your code quite a bit and maybe the slowing down would go away.
What do the strings received look like? Are they a list? in that case it would be more elegant to use use list to csv row. If you are sure that there is only one element, if not, select list ... index 1
Cheers, Ghica.

Bastien D.

unread,
Aug 28, 2019, 9:39:13 AM8/28/19
to mitappinv...@googlegroups.com
Hi Ghica,

Here are the blocks more readle, sorry for that !

What do you mean by the coding of the BLE devices ? I have only my application 

I just have my app that connect to the devices. Here is the link of the devices: https://www.sylvac.ch/download-en/manuals/digital-indicators/digital-indicator-s-dial-work-smart

For me, strings receive only a value that appears !

The problem probably comes from RegisterForStrings ...

Thank you !
blocks.png

ABG

unread,
Aug 28, 2019, 11:16:23 AM8/28/19
to MIT App Inventor Forum
Registering for Strings at each tick of Clock1.Timer
definitely looks suspicious.

I thought you only needed to register for strings once.

Also, what is the milliseconds setting on Clock1?
Are you nagging your device to death?

ABG

Ghica

unread,
Aug 28, 2019, 11:20:35 AM8/28/19
to MIT App Inventor Forum
Hi, I looked at the link you gave me but it did not give any specifics about the API. How did you find out the UUID's to be used?
What I mean is, that maybe you should register for strings only once (get rid of the clock) and then you maybe will start receiving data many times, until you disconnect or un-register.
Or maybe not, but then we know.
Only way to find out is to try. Make a new app using just one of the devices. In your textbox, keep a log of what you receive, not just the last value.
My remark about taking out the  ( ) in the data you receive is, that it probably a list. But if you use it as a string, you will see these parens.
When you are sure what is going on, you can update your real app.
Cheers, Ghica.

Bastien D.

unread,
Aug 28, 2019, 12:42:20 PM8/28/19
to MIT App Inventor Forum
Hi ABG,

The milliseconds setting on Clock1 is 1000. So I don't think it's the problem :)

Bastien D.

unread,
Aug 28, 2019, 12:46:28 PM8/28/19
to MIT App Inventor Forum
Hi Ghica,

I received this from the manufacturer :

UUIDS.jpg











I will try what you said !
Thank you!




Bastien D.

unread,
Aug 28, 2019, 1:04:30 PM8/28/19
to MIT App Inventor Forum
I made this ! 

When I press Value, the app displays about 14 values ​​per Click.

I have to press the button to receive something !

Was that what I had to do?

Regards,
Bastien
blocks.png
Screenshot_20190828-190002[1].jpg

gerrikoio

unread,
Aug 29, 2019, 9:46:07 AM8/29/19
to mitappinv...@googlegroups.com
@ABG is correct, you only RegisterForStrings once. You usually do this within the "when BluetoothLE#.Connected" block.

Then within the timer routine it is usually best practice to keep blocks of code short as possible. In your case, you have 3 checks for each BluetoothLE object and you are sending a Bluetooth String. So it would probably be better to first disable the timer, execute your code, then re-enable the timer within the timer block, to ensure that this block of code completes each and every time. If the periodic timing is really that critical you would need a bit of maths to work out next timer interval etc.

EDIT... another option to consider too, is to have a separate clock timer for each bluetoothLE object.

Bastien D.

unread,
Aug 29, 2019, 1:09:04 PM8/29/19
to MIT App Inventor Forum
Hi Gerrikoio,

Thank for the explanations !

I'm not sure what to do for the first option. How can I start the signal when the timer stops? 

What I think is: 
1) When the timer clock, I cut it 
2) I execute the code 
3) I restart the timer 

This is it ? 

Thank you for your reply :)

Bastien D.

unread,
Aug 30, 2019, 2:53:39 AM8/30/19
to MIT App Inventor Forum
Hi everybody !!!

I tried to register only once and it works ! The application is now fluent !

Thank you :)

Evan Patton

unread,
Aug 30, 2019, 12:24:10 PM8/30/19
to MIT App Inventor Forum
Just to explain a little bit more about how this works.

The Register methods set up the connection for BLE notifications. There's some additional bookkeeping that happens here, and there's a callback object that gets registered. If you keep calling Register, it will keep creating new callbacks, so you end up with a bunch of these things sitting around taking up memory. Once enough of them have accumulated, the app will get slower as it tries (and fails) to reclaim memory. If you wanted to do what you started off doing, it would be more memory efficient to use Read since it cleans up immediately (only one thing is read), but it isn't great from a power perspective as an explicit read request requires more energy than a BLE notification.

Cheers,
Evan

Chris Ward

unread,
Aug 30, 2019, 5:23:04 PM8/30/19
to MIT App Inventor Forum
Guys and Girls - one for the FAQ?

TimAI2

unread,
Aug 30, 2019, 5:32:49 PM8/30/19
to MIT App Inventor Forum
What is stopping you ?  :)

ABG

unread,
Aug 30, 2019, 5:42:03 PM8/30/19
to MIT App Inventor Forum
Sure
"How many times should I register BLE"?

TimAI2

unread,
Aug 30, 2019, 5:55:05 PM8/30/19
to MIT App Inventor Forum
Use this ?  :)

blocks (5).png


ABG

unread,
Aug 31, 2019, 8:23:17 PM8/31/19
to MIT App Inventor Forum
Reply all
Reply to author
Forward
0 new messages