What Magic Is Needed to Get an MIT App to Connect to HC-05?

It's asking me for permissions and I am allowing them when it asks.

I appended my simple LED On/Off code to your BTclient_test2.aia code. It's not permissions settings assigned to the app on the Android 12 phone.

Still can't connect to HC-05. Same 515 error.





I click the bluetooth icon for listpicker and then select the HC-05.

I don't get Green Connected because I am not connecting.

When I click LED On Button I get the 515 error telling me to connect to BT device.

Don't know how long we're going to blame permissions settings on my phone. I gave it all the permissions it asked for and all I can possibly give it.

Maybe I should reboot my PC or clear the cache like tech support always tells people even though that's never related to the issue or solves the problem. I've worked in IT for a very long time - reboot/clear the cache - reboot/clear the cache - reboot/clear the cache - a million bajillion times.

I was depending on the contents of that Label to tell me if the connection block returned true or false.

That would have told me that maybe the 515 happened after a disconnect, not a failed connect attempt.

No, I am not going to look up the 16 bit color code to tell me the results of the connect attempt.

Bye!

As test try the BLE extension
Taifun

The -65536 color code is red - it's not connecting. We know that. I can also tell by looking at the blinky led on the HC-05 itself.

So here's some interesting info. Note that the apk code itself (after I decompile it) is looking for Bluetooth admin permissions. Not an allowed permissions option on the phone.

Here's some other interesting security stuff for those who may be interested. That's what I do for a living - cyber security. Not exactly ideal that it has weak security and allows accessing activity and can read/write/delete files in storage and cleartext storage of sensitive info (ie email address, MIT AI account) in the code. Also weak hash codes.




Looking through the decompiled code now to see if I can figure out what's triggering the 515 error. Man, this is some big fat bloated code.


While you're in there, check the brakes.

1 Like

From the blocks you've posted, I see that you use a clock to verify whether the BT is connected , or not. If this clock is automatically started by the design page, this could lead to a problem.
If it fires before the BT connection has succeded, it creates the error. In other words: tthe connection block is a "blocking" block ( :grin:) and until the connection has been successfully obtained, or the internal timeout has elapsed, the block stays there. When it has finished its job it exits with a boolean : true if success or false if timeout.
My suggestion is therefore to remove at all the clock. On the opposite you shall activate a fast clock (typically I use a 10 milliseconds one) after a successfully connection, to poll the BT client so to catch incoming BT data in 'real time', if any.
At last, if you want to still use a clock as a watchdog (allowing in any case a long period of many seconds), you can do that, but you shall start it only after the BT has been successfully obtained.
Best wishes.

1 Like

As already suggested

And concerning

you can remove rhat check completely, because once bluetooth is connected, that property will always return true no matter if the connection will get lost later

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

Ah, ooops I didn't remember that detail, thanks @Taifun for highlighting..

So please @Gwen_Ceylon forget that suggestion (that kind of watchdog).

In effect I do my BT watchdog as follows:
every 30 seconds (or even more, with a clock) I do a handshake: i.e. the App sends one character (typically I send a '$' :smirk:) and waits for the echo from the Server (or the opposite, it is irrelevant to the scope). No echo means that the communication has ceased, therefore I popup a warning and I retry a new connection.
In @ABG 's FAQ you can find this:

The rest of my previous post (i.e. the initial clock probably too early) remains valid. Please give it a sight.

Okay thanks everyone. I'll remove the clock check, see what happens and post whether that's it or not.

A fairly common mistake is using "SoftwareSerial SerialBT(RX, TX);" instead of "SoftwareSerial SerialBT(TX, RX);"

Dear @Passos_0213 , where you've found that information ?
On the SoftwareSerial library official web site
(https://docs.arduino.cc/learn/built-in-libraries/software-serial/)
the correct syntax is:


And care shall be taken to select the pins on the Arduino boards to be capable of supporting that feature.

Merry Xmas to all. :santa: :santa: :santa:

Did you test it?

Nope.
I mean: I've always (i.e. in tenths of Arduino applications) followed the rule of the standard documentation, so why would I have used the reversed configuration (Tx instead of Rx) ?
So let me ask again where have you found that info ?

EDIT: a comon error is, instead, to forget to cross the wires (Tx to Rx) between Arduino CPU board and the BT shield, but as far as I can see in the snapshot of the wiring, this is not the case.

Don't think that is the issue since I am able to connect from my phone via a BT Terminal app and issue commands successfully.

The wires are crossed.

Yep, as I've said, according to your snapshot, they are correctly wired (and with SBT the Arduino side is working).
Have you removed the clock ?
Cheers.