Skip to content
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

I want to get rssi #42

Open
potaka001 opened this issue Aug 31, 2023 · 12 comments
Open

I want to get rssi #42

potaka001 opened this issue Aug 31, 2023 · 12 comments

Comments

@potaka001
Copy link

Is it possible to get rssi?

@ricardoquesada
Copy link
Owner

could you be more specific ? which platform ? use case ? etc ( https://tinyurl.com/bluepad32-help )

@potaka001
Copy link
Author

I'm using an ESP32 Dev kit and an Android TV Game controller.
BTstack can get the RSSI value, but how do I get the RSSI value when using Bluepad32?
I would like to check the Bluetooth signal quality by checking the Received Signal Strength Indicator.

@ricardoquesada
Copy link
Owner

I guess are you using Arduino, correct ?

I guess I can put that info in uni_bt_conn... and you should be able to get that info.

But I'd like to understand the use case a bit more.... what do you plan to do with the RSSI ? close the connection if not strong enough ? inform the user ?... the more details you add, easier for me to implement a feature that would be useful for you

@potaka001
Copy link
Author

I would like to record the rssi when input lag is measured.

@apoll2000
Copy link

Hi, this feature would also be really helpful for me. I am using a PS5 controller as a remote controller with an ESP32 running the bluepad32 arduino library, and reading out the RSSI would be useful as a safety feature so that a drop in signal strength can be detected.
Is it possible to access the RSSI somehow? Thank you very much in advance!

@ricardoquesada
Copy link
Owner

@apoll2000 as a safety measure you can do something similar to what I described here:
#45 (comment)

Regarding RSSI, the entire BTstack API is avaiable for Arduino users... you can call any API.
Wondering what is the API that returns the RSSI... I know the RSSI appears for BR/EDR connections when they advertise...

Not sure how to get it runtime... but if BTstack has that API, then you should be able to call it.
You might need the connection handle, which is not available to the Arduino API, but I can expose it so you can use.... if you can tell me which BTstack API you need to call, I can provide the needed arguments for that API

@apoll2000
Copy link

Thank you very much for your quick response, I had to read into everything a bit to understand.

The RSSI readout is implemented in the BTStack GAP API, with the function int gap_read_rssi(hci_con_handle_t con_handle), and it indeed requires the connection handle (function listed here in the documentation).

It would be great if you could help me access that from within Arduino.

Also just wanted to say thank you for this great library, it's already helping me a lot!

@ricardoquesada
Copy link
Owner

@apoll2000 good finding. It seems to be an async functions, so I need listen to the RSSI event, and then update the value internally, so that Arduino can read it.

Not a trivial change, but I'll think what's the best way to integrrate it into BP32

ricardoquesada added a commit that referenced this issue Jan 30, 2024
Untested

Part of:
#42
ricardoquesada added a commit that referenced this issue Feb 4, 2024
Untested

Part of:
#42
ricardoquesada added a commit to ricardoquesada/esp-idf-arduino-bluepad32-template that referenced this issue Feb 8, 2024
@ricardoquesada
Copy link
Owner

ricardoquesada commented Feb 8, 2024

I've just added some changes so that this issue can be mitigated:

  • BP32.update() returns whether data has been received in any of the controllers.
  • Controller.hasData() returns whether data has been received since BP32.update() was called.

Sketch updated:
https://github.com/ricardoquesada/esp-idf-arduino-bluepad32-template/blob/develop/main/sketch.cpp#L274

and here:
https://github.com/ricardoquesada/esp-idf-arduino-bluepad32-template/blob/develop/main/sketch.cpp#L229

@apoll2000
Copy link

Thank you for this, the update() method seems to solve exactly the issue I was having when data did not come through.

@TheRob87
Copy link

I've just added some changes so that this issue can be mitigated:

  • BP32.update() returns whether data has been received in any of the controllers.
  • Controller.hasData() returns whether data has been received since BP32.update() was called.

Sketch updated: https://github.com/ricardoquesada/esp-idf-arduino-bluepad32-template/blob/develop/main/sketch.cpp#L274

and here: https://github.com/ricardoquesada/esp-idf-arduino-bluepad32-template/blob/develop/main/sketch.cpp#L229

Hi,

it seems .update() and .hasData() has the same State so the ELSE condition will never be called.

I tried that like the FAQ says, but the print output (2 and 3) come never.

My Code (connected with XBox Controller)


void processControllers() {
    for (auto myController : myControllers) {
        //Serial.printf("Call Update %d\n",(millis() - lastUpdate));
        if (myController && myController->isConnected() ){
        Serial.printf("Call Update  1 %d\n",(millis() - lastUpdate));
          if( myController->hasData()) {
            lastUpdate = millis();
            if (myController->isGamepad()) {
              processGamepad(myController);
            } 
          }
          else {
            Serial.printf("Call Update 2 %d\n",(millis() - lastUpdate));
            if(speed != 0){
              
              if((millis() - lastUpdate) > maxUpdate ){
                maxUpdate = (millis() - lastUpdate);
                Serial.printf("Call Update 3 %d\n",maxUpdate);
              }
            }
          }
        }
    }
}

@ricardoquesada
Copy link
Owner

it seems .update() and .hasData() has the same State so the ELSE condition will never be called.

What update() does is to fetch data from Bluepad32 process to the Arduino process.
Data might be available, or not.
So, hasData() is exactly for that

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

4 participants