Change Text when Bluetooth disconnected

according to the documentation Connectivity

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.

1 Like

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

Hi

Error 516 is not the only error that suggests the connection has been lost, so you may need to test for more of them:

501, 502, 507, 508, 509, 515, 516 and 517.

See my site for a list of all error codes:
https://www.professorcad.co.uk/appinventorerrormsgs

1 Like

But what does it have more than the classic BT module. Specification, specification but it's a classic bt module, using the classic component in app inventor. It also connects classically to the bt terminal as there is another terminal application under ble. Your answer does not explain anything about the feature mentioned in this topic. I still think there is some android feature that is not supported by app inventor. Someone who knows Java could look at the code and you would know what's going on. As for the AT mode, every BT module has it. Respectfully, this answer says nothing. I also have HC-05, I will test with this module.

How can you expect a BT module to signal to the device it is paired with that it is disconnected? If it is disconnected, there is no signal. Your App has to test for this, which means if it is primarily required to send data, it must also have a function to receive a confirmation of receipt by the microcontroller. If that confirmation is not received, it can be assumed that there is a disconnection, but it can only be an assumption since it could just as easily be temporary signal loss due to interference or catastrophic failure of the electronics (physical damage caused by a blow or overheating).

As you can see from the XM-15B spec, it is designed to give a higher level of reliability, and so if there is a failure, it is a bit more likely to be a disconnection.

I tested with the hc05 module. The operation is the same, so the module version has nothing to do with it. The classic module is the classic module. As mentioned above, the BT Terminal does not send any data to the BT module in order to test error 516. However, after turning off the bt hc05 module, the application reports "disconect". So there is something you just don't know, and it is contained in the open java code of this terminal. Someone who knows java would have to look there and maybe build an extension based on that code.

The report of disconnection occurs after about 4s from turning off the BT module.

If you don't believe me and you have any classic BT module at home, you can install the BT Terminal on your phone and test that it works.

Patryk - error 516 only indicates there might be a disconnection. It actually reports "Unable to write", which of course is only going to be reported if a data send is attempted.

The 516 error could be caused by momentary signal loss, not a disconnection. If you keep sending data and keep getting a 516 (or other error numbers I listed) from the App, then it is reasonable to assume that there is a disconnection. Like I said, that can be decided by the App with the Blocks provided and no doubt that is what other Apps (written in a different language) do.

Since you believe that the java code of the BT Terminal App can detect a disconnection without any attempt to send or receive (ping), I will pass this topic on to Evan Patton.