Change Text when Bluetooth disconnected

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.

I know the method of detecting the disconnection of the bt module you are writing about. I used this method some time ago with error 516 in my application. However, I am writing about this BT Terminal as a curiosity because I was also surprised that somehow it is possible without cyclical sending of data. I guess this is related to the "socked" catchphrase in classic BT methods.

Hello you are saying that....

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

But why to test for other errors since the app showed me the exact code....?
Also very intresting conversation and i look forward to see how it will continue...

So as far as i can understand, the only way to check for bluetooth connectivity in mit appinventor is by sending something to the bluetooth module ,so that can see (mit appinventor) that there was a communication problem with the bluetooth module... Am i correct?

Closing has anyone any idea why my block is not executed when error516 occurs? Have i written something wrong?

Insert your AIA it will be easiest to see what's wrong.

I dont know why but when i try to export it in my computer is in zip format instead of aia .... Few days ago was saved as aia .... What have i done?

Then share what you have. I will adapt.

the forum does not accept zip files can i send it to you by my e-mail? or there is any other way to tranform it to aia ?? I go to projects > export selected project (.aia) to my computer > and saves it as zip !!! i can't understand why...!!!

Change the file extension from .zip to .aia

1 Like

Here is the project... Thank you very much for your interest !!!!!
Sup_Sub_Monitor.aia (340.6 KB)

Hi

When you get a "cannot write" error, apart from the obvious things like your phone being too far away from the device or an obstacle like a wall reducing signal strength, it's possible that something on the device, like a motor or even the processor itself, is creating interference.

I don't know how you can get a write error - your App is reading isn't it?

I can understand what you are saying and the correct thing to do is to check for errors and not for error. I just did an experiment... After a connection that was established i turn off the power of the hc-05 to see what will do... and it didn't run the whole erroroccured code of my block only the notifier don't knowing why...

Sup_Sub_Monitor (1).aia (340.5 KB)

Logical errors in programming. Even though you set up "disconect" before the clock turned off, he set the parameters to "connected".

1 Like

You are awesome i tested it out and it works as supposed to...!!!!! THANK YOU very much!!!

You actually should not have been able to upload the .aia because of the extensions it contains.

  1. Screen 'Main' has an out of date BLE Extension - but you are not using BLE?
  2. Sunny Gupta's BT extension is also present but unused. I do not know about this version, but Sunny's extensions were generally failing with App Inventor (having been designed for Kodular).

I suggest you delete extensions that are not being used.

I think your BT error could be caused by your use of the variable "CONNECTION_ADDRESS". Firstly, your code does not check it is valid before attempting to use it. Secondly, what you are storing, the address, it may not be 100% correct. If you want to automate the connection without the User selecting from a List of addresses, have your code check that the required address is in the List - and use that List item to connect with.

Is this App going to be distribute or is it only for your own use? If the former, you need to build-in things such as a bit of time for all available addresses to be found and a bit of time for the connection to be made.

Ah - I see now. You have a seperate Screen for Scan_Devices and you are using the BT extension. Why?

I see Patryk has found your bugs and the App now works, which is very good news. Still needs a good clean up though!