Skip to content

BluetoothSerial reporting "connected" even when connection fails #4081

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

Closed
vanniaz opened this issue Jun 11, 2020 · 2 comments
Closed

BluetoothSerial reporting "connected" even when connection fails #4081

vanniaz opened this issue Jun 11, 2020 · 2 comments

Comments

@vanniaz
Copy link

vanniaz commented Jun 11, 2020

Arduino core for the ESP32 v1.0.4

I have been trying the SerialToSerialBTM example to read data from a barcode scanner, and I noticed that the message "Connected Successfully" appeared even when the scanner was off.
So I took a look at the waitForConnect function:

static bool waitForConnect(int timeout) {
    TickType_t xTicksToWait = timeout / portTICK_PERIOD_MS;
    return (xEventGroupWaitBits(_spp_event_group, SPP_CONNECTED, pdFALSE, pdTRUE, xTicksToWait) != 0);
}

If I am not wrong, this function will return "true" even if other bits are set than SPP_CONNECTED (because according to the xEventGroupWaitBits description, it returns the value of the whole xEventGroup, not only the tested bits).
So in my opinion the function should be modified as follows:

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);
}

In fact, after having modified the code I see that it is working correctly.
The same change should be made to the "disconnect" and "isReady" functions.
Comments are welcome (I am not very expert in ESP-IDF so maybe that I am overlooking something).

@lbernstone
Copy link
Contributor

Go ahead and submit a PR. You may get comments there, but your change looks appropriate to me.

@vanniaz
Copy link
Author

vanniaz commented Jun 11, 2020

I see that a pull request for this bug has already been merged #3446, so I am going to close the issue.

@vanniaz vanniaz closed this as completed Jun 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants