-
-
Notifications
You must be signed in to change notification settings - Fork 161
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
Question: can a client and server run at the same time? #298
Comments
Code looks ok to me. Any chance you could provide logs with the debugging level set to debug? |
Hi I changed it to use the other BLE library and this bit works - it gets to having two connections but the other library doesn't have your nice onSubscribe method so I've lost some useful info!
|
interesting, could you please try commenting out this line NimBLE-Arduino/src/NimBLEServer.cpp Line 181 in f0bfd4c
it should be ok for testing to do this, the error code you have there is BLE_HS_EDONE, which is actually another success code, therefore there is no error here, just a bug that the check doesn't account for that. |
I made the changes below, and get the abort as shown in the second table - seems like it isn't the abort commented out, but somehow asynchronous straight after it?
|
Actually I was instrumenting commented out code above - oops! Now it seems to crash here - at this abort which shows no error log:
I also changed my code to use a different service ID and characteristic IDs but the same happens - so it doesn't seem to be because I am using the same IDs in server and client. |
Sorry I had stated the wrong error code. 15 == host busy. Which is strange, I wonder what it's doing at that time. For a test, try deleting the client instead of disconnecting. |
pClient_sp->deleteServices(); ? |
At line 165 in your code change |
Thanks, but the same result - my code never gets there. I added a Serial.println() to say if it ever reached that bit, but it doesn't. |
Removing parts from the code, the server works even if after the scan. This is the failing version with the connect() still in
So this code (commenting out the ->connect() and leaving the rest of the client code in, to fail if it wants, but it seems to pass through it without 'error' but also without connecting - as expected) allows the server code to work.
Gives this:
|
Sorry, it's not easy to see things from my phone sometimes. Now that you said that I can see the issue. In order to set the server attributes and start it you need to close all connections / scanning / advertising because the NimBLE stack needs to reset the GATT structure. So the fix would be to simply setup all the server things before starting the scan. Also add a call to NimBLEServer::start() after that. From there you can start scanning and connecting and just start advertising after the scan stop. |
Like this? Still same abort, though, so I must have got something wrong.
|
You'll also need to move these
to a point before you start the scan, probably right after That bit isn't well documented as this is not a case I've encountered before, I'll need to update the docs for this as well, sorry for the frustration. |
Thank you!!
|
It's not documented because it's not needed in 99% of cases lol. Advertising start calls it for you but in this case you needed to have the server started before advertising to fix the issue. |
Thank you for all your help!! I've just managed to get my code fully working - it now can connect to my amp, accept a connection from an app on an iphone, and pass data between the two! Exactly what I needed. Thank you!!! |
You're very welcome, glad to hear all is working! |
Hi - I have another question - can NimBLE work with BluetoothSerial? I'd like to have two varieties of the server - one NimBLE and one BluetoothSerial (for an Android app that doesn't seem to want to use BLE) - and keep the client part as NimBLE. |
This is not possible with NimBLE as you would need the bluedroid stack to use classic Bluetooth. |
I have seen this question asked before and it looked like 'yes, but you can't scan and advertise at the same time'
I want to create a server and client to sit between two devices. The aim is to get the server to mimic the services and characteristics of the end device, so I can intercept and change the commands on the way. But the current problem is that my code crashes with an abort() error.
I am using an M5 Stack Core 2.
My code is here: https://github.com/paulhamsh/BLEAppSpark
The client works by itself, and the server works by itself - just not together.
I am scanning, connecting to a client, building the server, then it crashes just as I advertise the server:
pAdvertising->start(); // start advertising
I had to move
pServer = NimBLEDevice::createServer();
to the start of setup() else it failed on an ASSERT when it ran that.
(C:\Users\Family\Documents\Arduino\libraries\NimBLE-Arduino\src\nimble\host\services\gap\src\ble_svc_gap.c, line 297, function: ble_svc_gap_init)
Is it possible? Am I missing a way to close the scan before starting the advertise?
I would appreciate any help.
The text was updated successfully, but these errors were encountered: