Bluetooth HC-05 Question - Page 1
Forum section: electronics / projects

author: andybarrett1
author_rank: Regular Contributor
timestamp: September 21, 2020, 02:27:56 pm
content: HI thank you for readingI have a project involving a HC05 / 06 Bluetooth module .... All is good but for one thing.I need the thing to drop connection when the host connection goes out of rangeOnce paired it seems to stay paired, the only work around I can see is to cycle the power?But as the installation is remote not sure if feasible ?reason I need to drop connection is so different hosts can connect at different random timesIdeas as always welcomeAndy

author: DrG
author_rank: Super Contributor
timestamp: September 21, 2020, 03:42:45 pm
content: Can you explain in better detail?When the slave device is out of range, the connection has been dropped, but the master HC-5 does not know - is that the basic problem?Do you have a "state" pin that has been brought out to the connectors?If no state pin, are you comfortable modifying the board such that the connect LED line is is brought out to your master board to "hand monitor" the connection?Are you comfortable writing some kind of keep alive code (having the slave regularly sending "I'm here" info or responding to a regularly sent "are you there" info - that kind of thing).Do you know how to handle a lost connection in code when it is detected?

author: andybarrett1
author_rank: Regular Contributor
timestamp: September 21, 2020, 04:21:32 pm
content: Thank you for replyThe hc06 is the slave ...Random terminal masters will come and go ...A little like a Bluetooth speaker really ... They can pair download a little info then move on...My problem is if they don't unpair with the hc05 before they go it seems to be left paired so no one else can connect??I can mod the board ..Software not my strongest attributeAndy

author: DrG
author_rank: Super Contributor
timestamp: September 21, 2020, 04:44:23 pm
content: Quote from: andybarrett1 on September 21, 2020, 04:21:32 pmOk, I think I understand, so more questions....There is a connection LED on the HC05 which should flash differently or stay solid when connected and go back to whatever it was before connecting when it has lost the remote. Do you see that LED reflecting the change when the slave is out of range? If yes then:You want to monitor that LED in your software - e.g., using the state pin or taking the led connection out to an input pin on whatever the mc the HC05 is attached to. When you detect the change to a "not connected" state, you will explicitly disconnect the remote HC06, as far as the HC05 is concerned (using whatever the AT command(s) is (are) to do that. Then the HC05 can go back to waiting for a remote to connect.So, hardware-wise, you need to modify the board so you can use the signal that drives that LED. If a "state" pin exists, it will work similarly to the LED but it much easier to access. Software-wise, you need to be monitoring that signal at regular intervals.If you can't manage the LED way, you have to go a little further into the software. So, if the HC06 is sending commands to the HC05 (turn on the light etc..) then you have to modify the code on the HC-06 to regularly send the HC-05 a keep alive command. The keep-alive command simply tells the HC05 that it is still here and connected. The HC-05 has to regularly look for these keep-alive commands and if it hasn't received one after some period of time, assumes the remote is out of range and explicitly disconects the remote and goes back to waiting for a connection.That is what I am getting at as a strategy or approach that I would try and others may have other ways or better ways or whatever. These HC's are a PITA because you never get the firmware and they have all these vagaries about them and there are lots of different varieties to make matters worse. I do appreciate that they are cheap and appear at some level to be easy to use...until they are not.Hope this helps.