How to add alarm notification in app when bluetooth connection is lost?

Hi i'm a beginner about MIT App Inventor
i want to ask how to add alarm notification feature in my app when bluetooth connection suddenly lost?

This is my app design

this is my code blocks

please tell me if there is any mistake in my code
i already tried it but the alarm notification won't trigger
thank you

Don't use the BluetoothError event. This block is obsolete and not active. Use the ErrorOccured event from the Screen1 drawer.

1 Like

ok i'll try that

See the answers in this thread



When i do this, that "call" player will automatically play even though i haven't connected my bluetooth connection. So it will automatically play when the application open.

if i do this instead, that call player is useless. Even though i turned off my bluetooth hc-05 manually (i'm not disconnecting it first at application) that "call" player never get turned on.

so how to fix this?

The DisconnectOnError block does not return whether there was an error or not...this block returns how you have the DisconnectOnError property set. If True, bluetooth will disconnect automatically, if False it will not disconnect... read the documentation of the Bluetooth component.

I wrote above in which event you will receive information about errors with bluetooth.

1 Like

i already did your advice and already read the documentation to understand better.
as you can see on that picture, am i doin it well? my codeblock for ErrorOccured event.

and i already search a tutorial or explanation about error occured event but no result about it.

when i run the program not working as i expected. The player start to play when I want connect to bluetooth while outside the range of the bluetooth network, not when the bluetooth connection is lost because of out of range of the bluetooth connection.

thank you.

it looks like you forgot to read my previous answer...
from the link I provided earlier

as the bluetooth protocol was designed, there is no way to detect, if a connection still is alive, therefore you have to send regularly (i.e. poll) some data to the device. And if you get an error, then you know, that the connection was lost…

your statement if BluetoothClient.DisconnectOnError does not make sense... as it already has been said

from my bluetooth chat example App Inventor Tutorials and Examples: Bluetooth Chat | Pura Vida Apps

there is no possibility for the chat partner to see, that the connection is gone. Therefore currently an "Error 516: Unable to write: Connection reset by peer" will be diplayed after trying to send a text without connection.

try to send something regularly (poll) and try to catch error 516 in the ErrorOccurred event... in this error case then play your sound


I think if we receive data cyclically, we can catch error 517.

Try it:

1 Like

what about i send some "fake" data from smartphone to the bluetooth and bluetooth send it back to smartphone.

And if the smartphone not receieve any data from bluetooth, so it can be interpreted as an error then the notification will appear.

so can the idea above be used?
if so, what codeblock was used?

Have you checked the above blocks?

yes i already did it, but no effect when i go away from the bluetooth connection range, something above 5 meter

remember i alredy did some modification in bluetooth hc-05 antenna, i grind those antenna with grinder so the bluetooth network range should decrease

Show your modified blocks that did not show the effect

When you tried these blocks, bluetooth was connected and received data from Arduino with a clock?

Your block of receiving data is badly built. Instead of "= 0" should be "> 0".

But in fact it may not work because when the buffer is empty then the data will not be received and so the error will not be detected. In that case, add a second clock and send in him, for example, "0" to Arduino. You don't have to send it back from Arduino. Change the error number from 517 to 516.

In fact, you don't need a second clock. Try this:

Data from Arduino send with a sign of a new line:

If Arduino is also to receive any data from your APP, you will have to add skipping this zero in the Arduino code. If Arduino does not receive any data from APP, you can add "Serial.flush ()" in the Arduino loop in the arduino loop, so as not to overflow the buffer.

Screenshot (440)
sorry, I followed the explanation from youtube about the bluetooth client

Screenshot (442)

this is the implementation about my idea above
still no functioning properly during testing :frowning:

My blocks are completely different...Before you start implementing your ideas, check if my blocks work. You can drag them to your project.