i can change the text to “connected” and background color to “green” when bluetooth is connected but when i unplug the bluetooth receiver then it doesnt change the text to “disconnected” and background color to “red”.
neither this
i dont fully understand your question but the timer is always enabled and always fires, interval is set to 100 and when i connect to the bluetooth receiver the text turns from “not connected” to “connected” and goes green
DisconnectOnError
Specifies whether BluetoothClient/BluetoothServer should be disconnected automatically when an error occurs.
I don't think so, because you forgot to poll the bluetooth device as @ABG suggested
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...
however let me suggest to set the new property DisconnectOnError to true during Screen.Initialize to disconnect automatically when an error occurs
you also can remove the DisconnectOnError statement in the Clock.Timer event…
In this particular app, I am continuously polling the the bluetooth module for temperature updates. Do you think it is possible that I could write something that looks to see how long it has been since the last update and if it has been over a certain amount of time, make the assumption that the bluetooth has disconnected and act on it?
Hello i am also having problem with the bluetooth connection checking... I have set a clock where every 3 secs it runs the blocks, but when i turn off the bluetooth device, the button keeps saying connected instead running the "else" block
read the complete thread again to understand, why this happens
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…
I have a "BT Terminal" application that can detect that the BT device is turned off without sending any data. Therefore, it must be said that there is some way, only the component in app inventor does not support it. That's why you have to deal with it in a different way.
I don't have any BLE module at home. Tested on the xm-15b module, this is a classic BT module. I do not know how the author of this application solved this problem, but it does not send anything because I would see an echo.
Unless you can send an empty string with bt? Maybe reading in the loop itself will cause an error if the device is turned off?
Thats true event headsets when are not connected are flashing fast which shows that the connection is lost.. As you said the mit appinventor needs to send something to realize that connection is lost.