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

NRA connection on NON-esp device (NRF81522) #708

Open
VincentGijsen opened this issue Aug 11, 2024 · 6 comments
Open

NRA connection on NON-esp device (NRF81522) #708

VincentGijsen opened this issue Aug 11, 2024 · 6 comments

Comments

@VincentGijsen
Copy link

VincentGijsen commented Aug 11, 2024

hi,

i'm trying to connect as client to my hometrainer, alas so far i've not managed to do so.
presently using an NRF58122, where it seems this function() is non-existing: void NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA) . however i'm not entirely sure its even the right function in the first place.

While testing on an ESP32S3, i have this function, but after exhausting most combinations of that function also failed to connect to the service, i just get (in both cases) a connection back, but then getting a REF to a BLE-service, fails

using the the ANOTHER libary (#include "BLEDevice.h"), i was able to connect to this hometrainer, using this call:

    bool _connected = pClient->connect(*myBike, BLE_ADDR_TYPE_RANDOM); //, BLE_ADDR_TYPE_PUBLIC);
    // the RANDOm bit is important, else it will not connect!

do note the explicit need to make clear the connect requires the BLE_ADDR_TYPE_RANDOM const, which is fed into the GATT object of the ESP-libary underlying.

hence I'm not entirely sure if the connect-argument of the stock-library, is 'similar' as the NimBLEDevice::setOwnAddrType(uint8_t own_addr_type, bool useNRPA)

Any pointers how how i could get the connection going?
ideally I stick to the NRF with the great https://github.com/h2zero/platform-n-able.git@^1.1.0 library. as these chips are soo dirt cheap, and i'm really charmed by the full open-source setup possible here (no softdevice) :)

ultimate goal would be to have the NRF/ESP as client+server to rewrite some calls between trainer and application on the pc albeit challenging given the very limited ram/flash on the NRF.
Debugging with the NRF is quite a bit faster/more pleasant compared to the ESP, with my Segger probe.

edit 1
after enabling debugging, and adding in this line (as per ESP32 implementation) NimBLEDevice::setSecurityInitKey(BLE_SM_PAIR_KEY_DIST_ENC | BLE_SM_PAIR_KEY_DIST_ID);
I see the following extra info:

starting
D NimBLEClient: >> connect(d0:33:36:33:1b:5b)
D NimBLEClient: Got Client event 
E NimBLEClient: Connection failed; status=13
Failed to connect

Thanks for the awesome work already; regardless of a solution for this one!

@h2zero
Copy link
Owner

h2zero commented Aug 29, 2024

Hi, I'm not sure what the issue is in this case as the nRF chips naturally have a random static address, so I would think it should work. That said the device you're connecting to might be expecting only a phone to connect which will have a random resovlable address, requiring bonding. In this case there would need to be some changes to the library to support this as it's not currently implemented. I will flag this to investigate further.

@VincentGijsen
Copy link
Author

VincentGijsen commented Aug 30, 2024 via email

@h2zero
Copy link
Owner

h2zero commented Sep 15, 2024

Try this:

ble_addr_t addr;
ble_hs_id_gen_rnd(0, &addr);
ble_hs_id_set_rnd(addr.val);

@VincentGijsen
Copy link
Author

i tried it,

in my init function, around the init of nimbestack, and (seperately just before the connect function to the scanned/found MAC, for my trainer:

btw, the trainer reports: - Resolvable Private Address Only [R] (0x2AC9) (NRFconnect); attached the full log; perhaps it tells you more then it tells mine.
Tunturi E35 log NRFconnect.txt

    ble_addr_t addr;
    ble_hs_id_gen_rnd(0, &addr);
    ble_hs_id_set_rnd(addr.val);

    this->_pClient = NimBLEDevice::createClient();
    this->_pClient->setClientCallbacks(&clientCB, false);

//ble_addr_t addr;
    ble_hs_id_gen_rnd(0, &addr);
    ble_hs_id_set_rnd(addr.val);
<<<<LOG BELOW>>>
D NimBLEClient: Got Client event 
E NimBLEClient: Connection failed; status=13
Failed to connect
..

like so:

..
bool BikeClient::connectToTrainer()
{
    log_i("starting");
  
    
    ble_addr_t addr;
    ble_hs_id_gen_rnd(0, &addr);
    ble_hs_id_set_rnd(addr.val);

    doConnect = false;

        if (!_pClient->isConnected())
        {
            if (!_pClient->connect(advDevice,true))
            {
                Serial.println("Failed to connect");
                return false;

...

not sure if these are the right place to call those functions, irrespectively both flavors compile fine.

@h2zero
Copy link
Owner

h2zero commented Sep 21, 2024

As long as you set the address after init it should be fine. What is the error code when the connection fails?

@VincentGijsen
Copy link
Author

VincentGijsen commented Sep 22, 2024 via email

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