Comments (38)
@GianCann I could connect at the same time to 2 train hubs, 2 train remote controls, 1 boost hub and 1 control+ hub π
from nimble-arduino.
I successful get 8 device connected to my ESP32
Now the fun begins π
from nimble-arduino.
@h2zero, @GianCann I have tested it today on my MAC with the following procedure and it worked like a charm! I think i have changed maybe the wrong header files or the Arduino IDE does not recompile the hardware libs after the header was changed.
- Delete Arduino out of my Application folder
- Delete the
/Users/<username>/Documents/Arduino
folder - Delete the
/Users/<username>/Library/Arduino15
folder - Install Arduino again via download from https://www.arduino.cc
- Download mimble library zip file and extract it to
/Users/<username>/Documents/Arduino/libraries
- Install esp32 Boards via the Boardmanager
- Changed the setting in the
/Users/<username>/Documents/Arduino/libraries/NimBLE-Arduino/src/nimconfig.h
file to#define CONFIG_BT_NIMBLE_MAX_CONNECTIONS 8
- Changed the setting in the
/Users/<username>/Library/Arduino15/packages/esp32/hardware/esp32/1.0.4/tools/sdk/include/config/sdkconfig.h
file to#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF 8
and#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN 8
- Install the Lego Library in the
/Users/<username>/Documents/Arduino/libraries
directory via downloading the Files of the specific nimble feature branch https://github.com/corneliusmunz/legoino/tree/feature/check_NimBle_Library - Open the following sketch in the Arduino IDE and load it to the esp32 board https://github.com/corneliusmunz/legoino/blob/feature/check_NimBle_Library/examples/MultipleTrainHubs/MultipleTrainHubs.ino
- Connect the hubs (BLE peripheral devices)
- Be happy π
from nimble-arduino.
Yeah!
09:51:41.275 -> Number of Clients: 0
09:51:41.275 -> New client created
09:51:41.377 -> Connected to: 90:84:2b:0c:06:41
09:51:41.377 -> RSSI: -63
09:51:42.022 -> Connected to HUB1
09:51:44.803 -> Number of Clients: 1
09:51:44.803 -> New client created
09:51:44.905 -> Connected to: 90:84:2b:0c:09:16
09:51:44.939 -> RSSI: -71
09:51:45.516 -> Connected to HUB2
09:51:48.502 -> Number of Clients: 2
09:51:48.502 -> New client created
09:51:48.638 -> Connected to: a4:34:f1:9b:07:9e
09:51:48.638 -> RSSI: -60
09:51:49.112 -> Connected to Remote1
09:51:53.653 -> Number of Clients: 3
09:51:53.653 -> New client created
09:51:53.789 -> Connected to: e0:7d:ea:0d:6d:94
09:51:53.789 -> RSSI: -73
09:51:54.262 -> Connected to Remote2
Now... go with others hub!
from nimble-arduino.
@GianCann I see now why this was failing on your side. The NimBLE lib has changed the interface yesterday and i was downloading it before the change. I will update the code on my feature branch according to your changes. Thanks for evaluating this and fixing the error
from nimble-arduino.
I successful get 8 device connected to my ESP32
Now the fun begins π
Very cool! Thanks for your patience and your super hint to use the nimBLE Lib! I have pushed the code changes with your fix on the feature branch. Can you check it with 10 Devices? maybe it works :-) As far as i remember you have had 10 TrainHubs in your test setup picture
from nimble-arduino.
A simple example:
https://www.youtube.com/watch?v=vOMIabLJhak
from nimble-arduino.
In the worst case, I will use an ESP8266 as a WiFi / MQTT gateway connected via serial to the ESP32
That shouldn't need to be done at all. The connection parameters are easy to change, just a matter of testing with different values if you need to. Connection parameter documentation is here and here
from nimble-arduino.
Hi @GianCann, yes up to 9 connections are supported (esp controller limit). You will need to change the setting in nimconfig.h on this line.
from nimble-arduino.
Edit: deleted, wrong fix - see below.
from nimble-arduino.
@h2zero thanks for that hint. Up to now (without rebuilding the libbtdm_app.a ) the connection to more than 3 peripheral devices was not possible. Do you have a hint how i could rebuild the libbtdm_app.a library?
from nimble-arduino.
Edit: deleted, wrong fix - see below.
from nimble-arduino.
Could you post a log of the error you get when trying to connect to more than 3 devices?
from nimble-arduino.
@corneliusmunz @GianCann I was wrong, no files need to be replaced, sorry for the bad info. I was playing with controller versions to test some things and I thought that was what made it work for me, it was not.
The solution is actually a lot simpler. Just change the defines in the sdkconfig.h file at Arduino/hardware/espressif/esp32/tools/sdk/include/config to:
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN 9
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF 9
That will allow the controller the max connections it can handle and you can set the NimBLE max connections to what you need.
from nimble-arduino.
@h2zero First of all many thanks for your support! I have tested it with the changed settings in sdkconfig.h. and in the nimconfig.h file. Unfortunately it does not connect to the 4th device. The devices are Lego Hubs which are connected via the legoino arduino library: https://github.com/corneliusmunz/legoino
The following error message occurs which tells me, that the max connections in sdkconfig.h. and nimconfig.h are not really taken into account:
22:44:59.737 -> E NimBLEClient: "Error: Failed to connect to device; addr_type=0 " "addr=00:81:f9:43:f2:06, rc=521; Connection Limit Exceeded"
Here you can find the complete log with nimble logging enabled and esp logging set to verbose
The follwing settings were used:
nimconfig.txt
sdkconfig.txt
For the connection procedure i used this sketch from my Lego Bluetooth library:
https://github.com/corneliusmunz/legoino/tree/feature/check_NimBle_Library/examples/MultipleTrainHubs
from nimble-arduino.
Thatβs odd, I connected to 5 devices today just with the config changes. I will try again with my other pc as Iβm not quite sure about the status of the binary I used.
from nimble-arduino.
Thank you @h2zero : I look forward to a definitive clarification on the use of the ESP32 module with more than 3 BLE devices
from nimble-arduino.
I was just able to do some more testing, with the above changes to the config files I am able to connect to 4 devices with no issue currently. This is using arduino-esp32 1.0.4 and arduino IDE. I am wondering if you are using platformio, this may be why the config changes do not have effect?
from nimble-arduino.
@h2zero π π πͺ π€ β€οΈ I switch to another PC (former try was on a MAC) and have done all your proposed changes (so only 3 changed settings in 2 header files) and fortunately it works like a charm!! I think on my OSX environment the formerly build object-files are used without applying the changes in the max connection values. I will try to evaluate a littlebit deeper why it have not worked out on my OSX system.
So again: Thank you very much for you help and your superb work on that library. I will have a look on your proceeding and will definitely think about porting my Lego library (https://github.com/corneliusmunz/legoino) from the standard ble library to yours. Do you plan to "officially" release the libray for the library manager?
@GianCann Can you try it with your 8 Train Hub setup? So for me it worked out and i can connect to 4 hubs at the same time
from nimble-arduino.
@corneliusmunz π― I'm glad you found the issue and all is working as expected, I have not connected to more than 6 devices before so if you have any issues connecting to this many them please make an issue about it. NimBLE actually supports up to 32 connections, sadly the esp32 controller is not equipped for this, but I'd be curious to see what happens if attempted.
Do you plan to "officially" release the libray for the library manager?
This is in the works, a few minor things to deal with like mirroring the code between Arduino and IDF repos and some documentation/minor cleanup, other than that the current code is v1.0.0 I believe and ready to release. I just haven't had time to finish up these things.
from nimble-arduino.
@corneliusmunz I have seen your test. Today I try to replicate on Windows PC.
from nimble-arduino.
@corneliusmunz Thank you for providing the details of your solution. I will include this in the library documentation.
How many simultaneous connections have you been able to maintain?
from nimble-arduino.
@corneliusmunz I following your instruction but I get this error:
C:\Users\remoteadmin\Documents\Arduino\libraries\legoino-feature-check_NimBle_Library\src\Lpf2Hub.cpp: In member function 'bool Lpf2Hub::connectHub()':
C:\Users\remoteadmin\Documents\Arduino\libraries\legoino-feature-check_NimBle_Library\src\Lpf2Hub.cpp:885:66: error: no matching function for call to 'NimBLEClient::connect(NimBLEAddress&, int, bool)'
if(!pClient->connect(pAddress, BLE_ADDR_PUBLIC, false)) {
^
In file included from C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEDevice.h:31:0,
from C:\Users\remoteadmin\Documents\Arduino\libraries\legoino-feature-check_NimBle_Library\src\Lpf2Hub.h:13,
from C:\Users\remoteadmin\Documents\Arduino\libraries\legoino-feature-check_NimBle_Library\src\Lpf2Hub.cpp:9:
C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEClient.h:41:49: note: candidate: bool NimBLEClient::connect(NimBLEAdvertisedDevice*, bool)
bool connect(NimBLEAdvertisedDevice* device, bool deleteAttibutes = true);
^
C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEClient.h:41:49: note: candidate expects 2 arguments, 3 provided
C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEClient.h:42:49: note: candidate: bool NimBLEClient::connect(const NimBLEAddress&, bool)
bool connect(const NimBLEAddress &address, bool deleteAttibutes = true);
^
C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEClient.h:42:49: note: candidate expects 2 arguments, 3 provided
C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEClient.h:43:49: note: candidate: bool NimBLEClient::connect(bool)
bool connect(bool deleteAttibutes = true);
^
C:\Users\remoteadmin\Documents\Arduino\libraries\NimBLE-Arduino-master\src/NimBLEClient.h:43:49: note: candidate expects 1 argument, 3 provided
exit status 1
Errore durante la compilazione per la scheda M5Stack-Core-ESP32.
from nimble-arduino.
Ok, I have changed this part of code in C:\Users\remoteadmin\Documents\Arduino\libraries\legoino-feature-check_NimBle_Library\src\Lpf2Hub.cpp
/** Check if we have a client we should reuse first **/
if(NimBLEDevice::getClientListSize()) {
/** Special case when we already know this device, we send false as the
* second argument in connect() to prevent refreshing the service database.
* This saves considerable time and power.
*/
pClient = NimBLEDevice::getClientByPeerAddress(pAddress);
if(pClient){
/* if(!pClient->connect(pAddress, BLE_ADDR_PUBLIC, false)) { */
if(!pClient->connect(pAddress, false)) {
Serial.println("Reconnect failed");
return false;
}
Serial.println("Reconnected client");
}
from nimble-arduino.
Yeah!
09:51:41.275 -> Number of Clients: 0
09:51:41.275 -> New client created
09:51:41.377 -> Connected to: 90:84:2b:0c:06:41
09:51:41.377 -> RSSI: -63
09:51:42.022 -> Connected to HUB1
09:51:44.803 -> Number of Clients: 1
09:51:44.803 -> New client created
09:51:44.905 -> Connected to: 90:84:2b:0c:09:16
09:51:44.939 -> RSSI: -71
09:51:45.516 -> Connected to HUB2
09:51:48.502 -> Number of Clients: 2
09:51:48.502 -> New client created
09:51:48.638 -> Connected to: a4:34:f1:9b:07:9e
09:51:48.638 -> RSSI: -60
09:51:49.112 -> Connected to Remote1
09:51:53.653 -> Number of Clients: 3
09:51:53.653 -> New client created
09:51:53.789 -> Connected to: e0:7d:ea:0d:6d:94
09:51:53.789 -> RSSI: -73
09:51:54.262 -> Connected to Remote2Now... go with others hub!
Cool! I am really looking forward to your test with more that 4 hubs :-) I only have 6 hubs so that was my maximum
from nimble-arduino.
As far as i remember you have had 10 TrainHubs in your test setup picture
I have 12 Train Hub, 6 Control+ Hub, 2 Move Hub and 4 Remote control π
from nimble-arduino.
@h2zero I suggest you add a note on the description page of the library, useful for those who need to connect to more than 3 devices
from nimble-arduino.
@h2zero I suggest you add a note on the description page of the library, useful for those who need to connect to more than 3 devices
I will do that. Thanks for confirming the required changes.
I'm curious also to know what happens if you connect to more than 9. If you try it please post your results.
from nimble-arduino.
I'm curious also to know what happens if you connect to more than 9. If you try it please post your results
Yes! I will try later
from nimble-arduino.
I can confirm: max 9 device!
11:34:40.116 -> Wait for connection
11:35:16.708 -> Number of Clients: 0
11:35:16.708 -> New client created
11:35:16.843 -> Connected to: 90:84:2b:49:63:64
11:35:16.843 -> RSSI: -41
11:35:17.450 -> Connected to HUB1
11:35:18.835 -> Number of Clients: 1
11:35:18.835 -> New client created
11:35:18.937 -> Connected to: 90:84:2b:49:63:9d
11:35:18.937 -> RSSI: -30
11:35:19.546 -> Connected to HUB2
11:35:23.603 -> Number of Clients: 2
11:35:23.603 -> New client created
11:35:23.739 -> Connected to: 90:84:2b:4a:b0:aa
11:35:23.739 -> RSSI: -22
11:35:24.347 -> Connected to HUB3
11:35:27.055 -> Number of Clients: 3
11:35:27.055 -> New client created
11:35:27.123 -> Connected to: 90:84:2b:4b:17:a2
11:35:27.123 -> RSSI: -37
11:35:27.765 -> Connected to HUB4
11:35:29.452 -> Number of Clients: 4
11:35:29.452 -> New client created
11:35:29.588 -> Connected to: 90:84:2b:4c:7c:f9
11:35:29.588 -> RSSI: -22
11:35:30.195 -> Connected to HUB5
11:35:31.517 -> Number of Clients: 5
11:35:31.517 -> New client created
11:35:31.653 -> Connected to: 90:84:2b:4c:88:23
11:35:31.653 -> RSSI: -25
11:35:32.262 -> Connected to HUB6
11:35:33.618 -> Number of Clients: 6
11:35:33.618 -> New client created
11:35:33.753 -> Connected to: 90:84:2b:0c:0c:12
11:35:33.753 -> RSSI: -45
11:35:34.396 -> Connected to HUB7
11:35:35.347 -> Number of Clients: 7
11:35:35.347 -> New client created
11:35:35.449 -> Connected to: 90:84:2b:0d:a7:ea
11:35:35.449 -> RSSI: -37
11:35:36.059 -> Connected to HUB8
11:35:37.075 -> Number of Clients: 8
11:35:37.075 -> New client created
11:35:37.210 -> Connected to: 90:84:2b:0c:06:41
11:35:37.210 -> RSSI: -43
11:35:37.820 -> Connected to HUB9
If I try to modify these line with 10 value:
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN 10
#define CONFIG_BTDM_CONTROLLER_BLE_MAX_CONN_EFF 10
(and also the nimconfig.h file)
I get ESP32 crashing in loop at boot time...
So, maximum 9 BLE device.
Now, the next step is to use the WiFi network simultaneously
(I want to make a MQTT/BLE Gateway)
from nimble-arduino.
Thanks for testing that, interesting that it crashes on boot with those values set to 10.
WiFi + 9 BLE connections might need some connection interval management to maintain.
from nimble-arduino.
WiFi + 9 BLE connections might need some connection interval management to maintain
Can you explain better?
from nimble-arduino.
Iβm not sure if you will need to do anything until you try it but I will explain.
The BLE connection interval sets how often the devices should send a packet to each other. There is also connection supervision timeout that will disconnect if a packet is not received in that time.
Depending on the device youβre connected to and the parameters set you may get disconnected from one or more devices frequently. Also if the connection interval is short and youβre also using WiFi you may get disconnected from WiFi often as the BLE connections may not give it enough time to use the antenna.
I would say donβt worry about it until you try it. If you have issues we can make the adjustments then.
from nimble-arduino.
Ok, it's all clear.
I will do real tests and see what happens.
In the worst case, I will use an ESP8266 as a WiFi / MQTT gateway connected via serial to the ESP32
from nimble-arduino.
As an update to this I have created a patch that should allow maximum connection change without the need to modify sdkconfig
, only need to change the value in nimconfig
now. I need someone to help test it though as I do not have enough BT devices to test more than 3 currently.
@GianCann if you're interested, perhaps you could test this patch with your setup, just apply the patch and revert the changes you made in sdkconfig.
from nimble-arduino.
@h2zero I have applied your patch and used the original settings in the sdkconfig.h
(MAX_CONN = 3) With your patch i could connect to more than 3 devices with only change the settings in the nimconfig.h
So in my point of view, your patch works and i think it could be merged into the master branch. Very cool, that you only have to change one setting in one header file!
from nimble-arduino.
@corneliusmunz Thank you for testing and I'm glad it works as intended. Will will commit this to master shortly.
from nimble-arduino.
Closing this as resolved.
from nimble-arduino.
Related Issues (20)
- Connection only on client request after disconnecting? HOT 2
- Adafruit Feather ESP32-S3 panik resets in the Scan Continuous example. HOT 1
- NimBLEClient issue on TRANSPARENT UART: receiving only one callback from ble server after writing HOT 2
- NimBLEServerCallbacks won't call onConnect(BLEServer*, NimBLEConnInfo&) HOT 2
- Is it possible to scan and detect smartphones? HOT 1
- suppressing some serial output from the scan whitelist example HOT 3
- Support for new ESP32 Arduino core (3.x) and IDF (5.1) HOT 7
- [Feature request] Support for ESP32-C6 HOT 17
- ESP_ERROR_CHECK failed on platformio, [email protected]
- Is it possible to advertise multiple 128bit services with data? HOT 1
- no advertising with ESP32-C6 HOT 4
- Set Manufacturer Data - Bug HOT 1
- Platformio, arduino and esp32 - pinning nimble to core and debug HOT 3
- onAuthenticationComplete() never called HOT 2
- ESP32-S3 crashing with the examples HOT 2
- Device name not showed at first connection HOT 2
- Allow only certain bonded client to connect to NimBLEServer. Whitelist in advertising does not work for already bonded peers
- Changing CPU frequency causes crash HOT 4
- Notification 8 byte data size
- how to get faster reconnects from deep sleep HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nimble-arduino.