-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Connecting ESP32 to HC-06 module #6876
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
It seems that there is an issue with IDF 4.3+ Bluetooth layer and SPP (BluetoothSerial). Read this issue: #5053 Related issues: |
By other hand, it works perfectly fine when connecting to a PC or Smartphone.... |
Downgrading to 1.0.4 did not work, I had to go all the way down to 1.0.2 and replace the BluetoothSerial.h file with this one: And BluetoothSerial.cpp with this one: Then it worked. It would be great if there could be compatibility for this type of connection to an HC-06 module in one of your next releases that includes the more up to date content in your more recent versions. Thank you for your help! |
Thanks for checking it! |
I don't have a HC-06 here to test, but I think that the issue may be in this Line (v2.0.0+) Maybe replacing it by a non-encrypted connection parameter may make it work with the latest Core version. |
With those two files, it works under Core 1.0.2.
That is very possible, I see that the encryption is not there in 1.0.2, which is when it works. I can give it a try later. It may be as simple as replacing ESP_SPP_SEC_ENCRYPT|ESP_SPP_SEC_AUTHENTICATE with ESP_SPP_SEC_NONE. |
Seems, I found solution working for me and possible reason. I use 2.0.6 version core. On first power on ESP32 can find and connect HC-06 by Address, I never seen peer name in debug, it never resolved (dont care, have MAC). Once restart ESP32, it no longer able to re-connect HC-06 then. If you discover devices using standard example from library you probably find HC-06. However you couldn't connect it using code from example SerialToSerialBTM. Next, if you reset HC-06 by RST pin or power, and then force ESP32 to re-connect HC-06, it succeeds till next connection lose I figured out that HC-06 after lose connection stays in specific state on channel 1 and cant accept connection on any other channel untill reset. On other hand, ESP32 by default tries to re-connect using auto-channel configuration or using previously discovered data (that's not clear for me). Hence, instead
I use alternative method with explicit channel number
I implemented both solutions to my rig. Reset HC-06 by pin from host controller and use explicit connect() method on ESP32 side. And it works stable. HC-06 available from smartphone anytime, even after smartphone lose connection it re-connects successfully without HC-06 reset. So I beleive that the problem in ESP32 library logic, or HAL may be. Hope, my post will help to fix this known annoying bug p.s. sorry for my English, not my native language |
Thanks a lot @RedCatTrix for the post! |
Hello @treysblackwell Do you still need help with this one? |
Hello, I close this since this report contains the release we no longer support. Please try the new versions and in case the issue persists, feel free to reopen it. Thanks |
Board
ESP32 Dev Module
Device Description
ESP32 Dev Module
Hardware Configuration
Nothing
Version
v2.0.3
IDE Name
Arduino IDE, Visual Micro
Operating System
Windows 11
Flash frequency
80MHz
PSRAM enabled
no
Upload speed
921600
Description
I'm trying to pair and connect my ESP32 Dev Module to an HC-06. The goal is to be able to send serial commands from the ESP32 to the HC-06.
I started with the SerialToSerialBTM.ino example and cannot get the two to pair or connect. I have tried using both the name and the address as methods of connecting, and neither is working. I have verified correctness of the address and spelling of the name, as well as the PIN (I've tried running the sketch with the line both commented and not commented).
I can pair my phone with the HC-06 no problem, and can also pair my phone with the ESP32 no problem, just can't get the two to pair together.
I've been doing lots of digging online and found issue #3916, which looks like it is the same issue, and the solution was to downgrade a few versions, but at this point it was many versions ago. It was with version 1.0.4, and we are now on version 2.0.3. I tried downgrading to version 1.0.2, but was unable to get it to work (but I won't claim I did it 100% correctly).
I've copied the SerialToSerialBTM.ino in its original form and then added comments next to the things I changed to try to get it to work.
I also set core debug level to "info" in the IDE and copied some of printout. The scanned device that is shown is the MAC address of the HC-06 I am trying to pair with, so it's there and ready, but the ESP32 just can't do it for some reason.
This is my first attempt at a project with an ESP32, so I would really appreciate any suggestions that might help me get this working!
Sketch
Debug Message
Other Steps to Reproduce
No response
I have checked existing issues, online documentation and the Troubleshooting Guide
The text was updated successfully, but these errors were encountered: