Code Monkey home page Code Monkey logo

Comments (13)

Jeroen88 avatar Jeroen88 commented on May 13, 2024 1

Adding a 200 ms delay between createClient() and connect() solves the problem, 100 ms is too short. Still I think disconnect() should wait for the event.

from nimble-arduino.

Staars avatar Staars commented on May 13, 2024

This reminds of my last weekend, where I finally was "sure" that my ESP32 was broken.

For me the solution was to erase the flash , which seemed to have solved it. In the end I erased it basically before every upload.

What IDE are you using? If you are using some kind of caching mechanism, you might need to delete the compiler cache too.

from nimble-arduino.

Jeroen88 avatar Jeroen88 commented on May 13, 2024

I had a "broken" ESP32 too a few days ago, put it apart, I have not thrown it away yet. I'll try to erase the flash to see if that brings it back to life.

But this is another issue. I can reset to run the sketch again. I can re-flash and start the program over again. But is won't get passed the second connect(). As you can see in the logging, while connecting the first time it logs:

D NimBLEClient: "Got Client event "
D NimBLEClient: "Connection established"

and the second time it logs:

D NimBLEClient: "Got Client event "
D NimBLEClient: "Got Client event "

and then waits forever...

Most of the time, also this time, I use the Arduino IDE, 1.8.10 (that is the one but last I believe). Every now and then I use pio.

from nimble-arduino.

h2zero avatar h2zero commented on May 13, 2024

Turn on event code strings to see what

D NimBLEClient: "Got Client event "
D NimBLEClient: "Got Client event "

actually are.

Looks like you're hanging on a semaphore, or the stack is getting stuck because the peripheral has not disconnected yet. Try putting a delay of 100ms or so between deleting and creating the client.

from nimble-arduino.

Jeroen88 avatar Jeroen88 commented on May 13, 2024

Logging now:

Started
I NimBLEDevice: "BLE Host Task Started"
I NimBLEDevice: "NimBle host synced."
Create
Connecting...
D NimBLEClient: ">> connect(a4:c1:38:5d:ef:16)"
D FreeRTOS: "Semaphore taking: name: OpenEvt (0x3ffc88fc), owner: <N/A> for connect"
D FreeRTOS: "Semaphore taken:  name: OpenEvt (0x3ffc88fc), owner: connect"
D FreeRTOS: ">> wait: Semaphore waiting: name: OpenEvt (0x3ffc88fc), owner: connect for connect"
D NimBLEClient: "Got Client event BLE_GAP_EVENT_CONNECT "
D NimBLEClient: "Connection established"
D FreeRTOS: "Semaphore giving: name: OpenEvt (0x3ffc88fc), owner: connect"
D FreeRTOS: "<< wait: Semaphore released: name: OpenEvt (0x3ffc88fc), owner: <N/A>"
D NimBLEClient: "Refreshing Services for: (a4:c1:38:5d:ef:16)"
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
D NimBLEClientCallbacks: "onConnect: default"
D NimBLEClient: "<< connect()"
Connected
D NimBLEClient: ">> disconnect()"
D NimBLEClient: "<< disconnect()"
Disconnected
D NimBLEClient: ">> deleteServices"
D NimBLEClient: "<< deleteServices"
Create
Connecting...
D NimBLEClient: ">> connect(a4:c1:38:5d:ef:16)"
D FreeRTOS: "Semaphore taking: name: OpenEvt (0x3ffc88fc), owner: <N/A> for connect"
D FreeRTOS: "Semaphore taken:  name: OpenEvt (0x3ffc88fc), owner: connect"
D FreeRTOS: ">> wait: Semaphore waiting: name: OpenEvt (0x3ffc88fc), owner: connect for connect"
D NimBLEClient: "Got Client event BLE_GAP_EVENT_MTU"
D NimBLEClient: "Got Client event BLE_GAP_EVENT_DISCONNECT"

I think the issue is indeed that BLE_GAP_EVENT_DISCONNECT arrives AFTER calling connect() again.

I think disconnect() should wait for this event...!

from nimble-arduino.

Staars avatar Staars commented on May 13, 2024

Adding a 200 ms delay between createClient() and connect() solves the problem, 100 ms is too short. Still I think disconnect() should wait for the event.

Interesting observation, I will test this too.

from nimble-arduino.

h2zero avatar h2zero commented on May 13, 2024

What is the purpose of doing this? It seems odd to me to create a client object delete it and create another in such a short time, why not just reuse the client object?

Still I think disconnect() should wait for the event.

That would unnecessarily slow down other applications, if you really need to know the client is disconnected there is a callback for that.

from nimble-arduino.

Jeroen88 avatar Jeroen88 commented on May 13, 2024

In the integration I am creating several devices are read out independently. Most don't need a connection, some do. I just want to use the functionality that is there. Also, I think it should always work

Could you give me some directions how to check if the client has disconnected? The function isDisconnected() does not do this job

from nimble-arduino.

chegewara avatar chegewara commented on May 13, 2024

For me the solution was to erase the flash , which seemed to have solved it. In the end I erased it basically before every upload.

This is must when you are building bluetooth app.

from nimble-arduino.

chegewara avatar chegewara commented on May 13, 2024

D FreeRTOS: ">> wait: Semaphore waiting: name: OpenEvt (0x3ffc88fc), owner: connect for connect"
D NimBLEClient: "Got Client event BLE_GAP_EVENT_MTU"
D NimBLEClient: "Got Client event BLE_GAP_EVENT_DISCONNECT"

This may have happen when there is no successful connection, maybe except MTU exchange, because this requires full connection established, unless MTU is called too early (in wrong place).

from nimble-arduino.

Staars avatar Staars commented on May 13, 2024

from nimble-arduino.

h2zero avatar h2zero commented on May 13, 2024

This issue was just resolved in commit 4c798fe.

from nimble-arduino.

Jeroen88 avatar Jeroen88 commented on May 13, 2024

This issue was just resolved in commit 4c798fe.

I can confirm that. Thank you @h2zero!

from nimble-arduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.