Change Text when Bluetooth disconnected

The when.clock1.timer run when the timer as gone off…it has triggered?

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

This went into AI2 last night in nb183:

  • Add DisconnectOnError property to BluetoothClient

See the release notes at http://appinventor.mit.edu/ai2/ReleaseNotes.html

It might be just what you need, if combined with polling the BlueTooth connection by trying to send regularly.

seems to work fine, thanks :slight_smile:

(added to FAQ)

according to the documentation http://ai2.appinventor.mit.edu/reference/components/connectivity.html#BluetoothClient

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…

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun.

ErrorNumber is 516

@Juan_Antonio the screenshot looks pretty good…

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…

Taifun

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?

When the app gets error 516, it writes a text indicating: connection failure at hh:mm

Here an example:

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

Thank you in advance Panagiotis

See Change Text when Bluetooth disconnected

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…

Taifun

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.

his might be BLE then...
the old bluetooth 3 specification is not able to do it...

Taifun

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.

Thank you all regards

I also tried this..... and althought the notifier appears, the button doesnt return to the blocks i have below the notifier.... any thoughts ?

This module is more than just a Bluetooth (2.1 + EDR) module, it has other features beyond the spec:

XM-15B Bluetooth Serial Port Module Master Slave all in one, compatible with Arduino/HC-05/06 and Anti-reverse 3.3 / 5V

XM-15B Bluetooth module (hereinafter referred to as module) meet Bluetooth SPP specification, compliant with the Bluetooth 2.1 + EDR standard, has two operating modes: command mode and data mode. Under data mode, divided into Master,Slave and loopback three operating roles. When the module is in command mode can perform all of the following AT commands, the user can send a variety of AT commands to the module, set parameters or send control commands. When the module is not connected to any device (blue light flash) in command mode, it is ready to receive AT commands. in command mode, the module can be connected or connect to other Bluetooth devices actively based on settings role. After the module is connected with other Bluetooth devices (blue indicator light), automatically enter data mode.
XM-15B core module is XM-05, base board built in power management chip with 5V and 3.3V TTL signal conversion circuitry, compatible with 3 / 3.3 / 5V several different voltage signal, the module TXD output pin high level is VCC-0.3V

Module XM-15B Features:
• Using compatible with CSR mainstream Bluetooth chip, Bluetooth V2.1 + EDR protocol standard, pass Bluetooth BQB certification.
• Quick Start, only 0.3 seconds to complete the entire module (including Bluetooth protocol stack) initialization.
• Built-in hardware watchdog, never crash.
• Better compatibility, compatible with the stack Windows comes, IVT, Widcomm (Broadcom), android systems, compatible with almost android phones in the markets.
• Built-in RC reset circuit, POR, Brown-Out, LVR power supply voltage monitoring circuit, the reset is stable and reliable, no external reset circuitry.
• Built-in power anti-reverse protection circuit.
• Built-in power management chip, power supply voltage range: 3.0V ~ 6V
• Built-in TTL signal level converting circuit, compatible with 3 / 3.3 / 5V signal, TXD high output voltage VCC
• Default parameters: 9600 baud, pairing code 1234, the mode slave.
• Module size: 37.5mm x 15.5 mm x 4.0mm (excluding pins).
• Current: pairing: 4 ~ 12mA pairing has not been completed communication: 4 ~ 12Ma Communication: 12mA no sleep.
• Maximum transmit power: + 10db (higher than the general CSR Bluetooth module)
• Communication distance: open conditions under 30M (farthest reach of 60 meters, but is not guaranteed), the normal environment is around 15M
• Applications: GPS navigation system, utility meter reading systems, industrial control systems mining site. Able to connect with mobile phones, bluetooth laptop, computer with bluetooth adapter, PDA devices seamlessly

Steps to set module to Master
• Under command mode, make sure blue indicator flashing all the time
• Use serial communication tool(such as our company CommPro), set correct serial parameter(Default baud rate 9600, 8 data bits, 1 stop bit, no parity, no flow control)
• Serial port send characters "AT + ROW = 1 \ r \ n", successful return "OK \ r \ n", and \ r \ n is carriage return (it is ASCII’s 0x0D, 0x0A)
• Serial port send characters ““AT+CLASS=000000\r\n”, successful return “OK\r\n” (This step accordingly to device to be connected slave category code optional use)
• Re-power, module is master, automatically search slave module to establish connection