-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Support for Master mode, Pin and SSP #3219
Conversation
Looks like build #2408.4 errored out due to inability to access main repo, please advise. fatal: unable to access 'https://github.com/espressif/arduino-esp32.git/': Failed to connect to github.com port 443: Connection timed out |
All checks are passed, what is the next step, please forgive me - it is first time for me on github. |
Just wait - review will be done with some feedback ^_^ |
Very nice :) this is really useful! |
Sure, let me push the latest iteration that uses resolved address as preference on connect() and get rid of redundant _remote_address, and more of technique in example. all done on my side. I see [Event Group API] is used for signaling in existing code. |
…e now redundant _remote_address
Pushed pin logic re-work |
I made some effort to address some of the issues you noted. I was not sure you have time to work on it, as you could be quite busy. Hopefully, you need to spend less time refactoring the code. |
… for disconnect event. + timeout for disconnect()
…s during scan in info mode as it is very difficult to find out sometimes. Fixed get_name_from_eir() not resetting the name when called.
At this point my only concerns are with delegation to user to set timeouts to keep it from any unexpected crash due to concurrency. I timed the ops and have pretty good idea how to set timeouts in connect() and disconnect() operations appropriately, so the result code would reflect the true state, not just async API call return value. |
…currency and more authoritative status returned back to caller. Automatic disconnect in connect() methods
I think I found the issue and I don't see at all how it ever could have worked correctly for you, but maybe something else had initialized the variables different for you @IonicEV :) static bool waitForConnect(int timeout) {
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED, pdFALSE, pdTRUE, xTicksToWait) != 0);
} That code is pretty wrong, it's returning whether any of the bits is non-zero. It should be like this instead: static bool waitForConnect(int timeout) {
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_CONNECTED) != 0;
} |
You can try it at will - just rebuild your sketch with local updated code in waitForConnect(). I do not think it makes any difference though as only SPP_CONNECTED bit is analyzed, so no other bits are relevant. It does not even need !=0 (was added for better compliance). The ESP32 BT core library triggers event on successful connection. The code in BluetoothSerial.* is just an enabler to expose this functionality. |
I did, and it does make a difference which is why I said it was broken :) When printing the output for |
Submit the fix. If you need any assistance with it let me know. Also, look at other calls to xEventGroupWaitBits, as those need to be protected as well. |
I just checked my sources and I have:
Not sure at what point it deviated from repo. Possibly, last minute changes before merge to add != 0 to make the whole expression a "true" bool as it was done on different laptop. |
That would explain the difference. I'll submit a pull request with a few
minor adjustments to fix these.
For what it's worth, it's still not pairing with my device unfortunately :(
…On Sun, 3 Nov 2019, 16:33 IonicEV, ***@***.***> wrote:
I just checked my sources and I have:
static bool waitForConnect(int timeout) {
TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
return (xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED, pdFALSE, pdTRUE, xTicksToWait) & SPP_CONNECTED);
}
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3219?email_source=notifications&email_token=AACCB25HZ7VPFW5KK6GILFLQR3OL3A5CNFSM4IXJGNAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEC5VOXA#issuecomment-549148508>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACCB22CQHXKEL4CGNKE3X3QR3OL3ANCNFSM4IXJGNAA>
.
|
Thank you very much. Looking forward to trying it out here. |
Look for the BluetoothSerial.cpp file on your system and replace that with this file: https://github.com/espressif/arduino-esp32/blob/f0e2e2a62fe98ec9657f3935c41c88a0fd0e7acd/libraries/BluetoothSerial/src/BluetoothSerial.cpp |
Thank you Rick, It works a treat. With your new BluetoothSerial.cpp, it connects and more importantly, does not connect (and correctly reporting this fact) when it shouldn't. I still have questions regarding this library. I this the correct forum to ask? Or is it reserved for you experts? Many regards, ~Martin |
Hello, |
@wolph I replaced my local BluetoothSerial.cpp file with the one you linked on Nov 5th. My code went from falsely showing that it connected every time to giving me a "Stack smashing protect failure!". This thread covers a long time span so I'm not clear if I need to roll the ESP32 library back also, or do something else to get it working. Edit: I'm on 1.11.1 currently |
@jsodeman: while my patch fixes that bug, that doesn't mean it properly works. I've personally given up and I'm using a HC-05 now. Alternatively the bluestacks implementation works better as well. |
Thanks, I was wondering if using a HC-05 was a better direction as well. Or alternately if I was going to have to dig into the lower levels in IDF. Since you've got more experience with this, maybe you can point me in the right direction. What I'm trying to achieve is to manually pair the esp32 with a phone once, and then have the esp32 be able to check to see if it can connect to the phone later via bluetooth or ble without having to run an app on the phone. I don't really care about any exchange of data, just a test connection - somewhat like unlocking a device by having your phone with you. My hope was that with classic bluetooth I could just call .connect() with the MAC address of the previously paired phone, which is what led me to this post. My impression was that BLE wasn't an option. |
I think BLE is perfect for that application actually. The esphomelib library has an example doing just that: https://esphome.io/components/esp32_ble_tracker.html |
Thanks for the link. The problem I'd run into with BLE is that phones randomize their mac address and don't otherwise seem to broadcast anything detectable without running something like a beacon simulator app. Generally it seems like working with a phone really requires the phone to be the initiating device or for it to be running an app. So for now I think BLE with a beacon app running in the phone background is the easiest. I was able to wifi sniff a phone but the interval is inconsistent. |
@jsodeman If you initially connect with smartphone and create bond connection then esp32 should recognize that smartphone anytime, because smartphones are using resolvable address. |
@chegewara with BT classic? I think I ran into problems trying that which is what led me to trying Master mode and this post. But honestly I've tried so many different things in the last week I've lost track of why I rules things out. I need to start taking notes on my attempts :-P |
No, im saying about BLE now. |
No worries. I'll give that a shot with BLE. For some reason last time I tried it I couldn't get the phone to connect and bond with the ESP32 running the server example. |
Hello, Tryed @IonicEV master 1.0.4 but there is no connection, even if there is a success in the log: "The device started in master mode, make sure remote BT device is on! Tried both connection by name and by address, I have double checked the used infos. Please, I really need it for a school project |
@j0r9e74 open a new issue |
Hello,
I really a solution until the end of net week. Please help me guys. |
@j0r9e74 I think they're willing to help but want you to open a new issue on that as your question isn't related to this topic directly. |
@jsodeman my question belong to this topic. if they wants to help and a new issue is required they can request this. thank you |
They did, look 2 posts back.
…On Sun, Apr 19, 2020 at 1:41 PM j0r9e74 ***@***.***> wrote:
@jsodeman <https://github.com/jsodeman> my question belong to this topic.
if they wants to help and a new issue is required they can request this.
thank you
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#3219 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AASHG2XPYMEHNJWL45R5CQDRNMZS5ANCNFSM4IXJGNAA>
.
|
#3916 issue opened |
@IonicEV , at the moment, ESP32 not possible to connect OBDII bluetooth dongle such as OBDLink LX that always generate random pin at the moment? |
Does the The example has the |
I witnessed a lot of folks struggling with master mode on ESP32 (initiating connection to other slave devices). Some examples were available(example_spp_initiator_demo.c), but they lacked support for IO, congestions and other aspects covered nicely in original BluetoothSerial class. I took a step forward and combined code provided in example_spp_initiator_demo.c and BluetoothSerial class to enable Master mode, Pin and SSP for legacy BT in BluetoothSerial class. Hopefully, you would find it useful.