I've gone through A LOT of forums. Tried A LOT of Suggestions. I can't get the app to connect to HC-05. I can connect through BT Terminal and my simple Turn LED on and off Arduino code works just as it should. No go with the MIT App. Yes, I checked my Rx/Tx wires. First tried pins TX1 and RX0 on a Nano (also tried Uno). Then I used SoftwareSerial and used pins D2 and D3 (SoftwareSerial SerialBT(2,3); // RX, TX). Still no go. And yes, you'll see in my code I set the baud rate to 9600. Using a HiLetgo HC-05 module with product description specifying "Master and Slave 2-IN-1 HC 05 Module:Working Voltage 3.6V to 6V , Default baud rate:9600,Default pin:1234". I can send all the screenshots and photos you could possibly want to see to show all of this. And I am using the BT Blocks someone else suggested as a fix on another post with someone else having this exact same issue. BTW, I have CompSci degrees and I just retired after working in IT for 35+ years. There's something not right here that so many people have problems with this.
BTTest.ino (1.2 KB)
BLUETOOTH_LED.aia (85.8 KB)
BTW, I am trying to get this RC Tank running with a Android app I already built in App Inventor, but same 515 error not connecting to Bluetooth Device. Doesn't matter if it's a simple LED on/off Arduino code or the the code that will run this Tank - cannot connect with an MIT App Inventor app, no matter what I've tried from multiple suggestions I've found here and elsewhere. I can totally control the tank, all it's functions with a Bluetooth Terminal so it's not my Arduino code. I might try putting an apk code scanner on the builds and see if I can troubleshoot MIT's build of the apk's that way. There's got to be something seriously wrong in their build. Maybe I have to abandon MIT App Inventor and use something else.
See that -65536(?) on your run time screen shot?
That's a color value dropped into the connection label text value, instead of the label background color attribute.
Also, please add some on screen logging of permissions granted or rejected events. Screen1 has events to catch those.
We only get 515 errors yearly, so that's a good board search parameter.
P.S. I don't see Bluetooth Scan on your permission requests list.
How to correctly ask for Bluetooth permissions see here
Taifun
Maybe your HC05 is a BLE ? (recently there are many "HC05" that are actually BLE)
The -65536 is rather immaterial to the issue. Who cares if I am not getting the Connected/Not Connected label looking right if I am getting the 515 Not Connected error and not getting connected at all to the HC-05?
Bluetooth Scan permission must be granted if I can see the HC-05 BT device when I click on the listpicker to select it.
Will add some permissions granted and rejected and get back if I see anything.
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.
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 (
) 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.
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 '$'
) 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.
























