Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

More than 3 concurrent BLE Connections (Arduino Nano 33 BLE) #40

Open
Dorsel89 opened this issue Dec 18, 2019 · 12 comments
Open

More than 3 concurrent BLE Connections (Arduino Nano 33 BLE) #40

Dorsel89 opened this issue Dec 18, 2019 · 12 comments
Assignees

Comments

@Dorsel89
Copy link

Hi everyone,
I would like to have more than 3 concurrent BLE connections with the Arduino Nano 33 BLE. As far as i understand i have to adjust the DM_CONN_MAX in cfg_stack.h.

Unfortunately, that doesn't work, do you have any tips on what I'm doing wrong?
Thanks and kind regards!

@sandeepmistry
Copy link
Contributor

Hi @Dorsel89,

I believe the link layer inside libmbed.a will need to be re-compiled for the changes to take effect. I also believe variants/ARDUINO_NANO33BLE/mbed_config.h is the correct place to update the define.

There is a script to re-compile mbed: https://github.com/arduino/ArduinoCore-nRF528x-mbedos/blob/master/mbed-os-to-arduino

@Dorsel89
Copy link
Author

Dorsel89 commented Jan 7, 2020

Hi @sandeepmistry
thanks for your help! I followed your suggestions but I am still not able to connect more devices (or less after I decreased DM_CONN_MAX).

I wonder about the mbed_config.h , in the header it is mentioned that the file should not be edited, because the values are generated automatically. This is exactly what I noticed, after I start the script mbed-os-to-arduino all defines are back to default.

It would be nice if you have more tips for me!

edit: I used the script with these parameters:
./mbed-os-to-arduino -c ARDUINO_NANO33BLE:ARDUINO_NANO33BLE

@sandeepmistry
Copy link
Contributor

Hi @Dorsel89,

I've just spoken to @facchinm about this, the correct place to add the define is in variants/ARDUINO_NANO33BLE/conf/mbed_app.json, then re-compile mbed.

Apologies for the incorrect information I provided earlier.

@Dorsel89
Copy link
Author

Dorsel89 commented Jan 10, 2020

Hey @sandeepmistry,

thanks for your help! I just managed to override DM_CONN_MAX. Will check if it really works now =)

Thanks in advance

@Dorsel89
Copy link
Author

Hi @sandeepmistry,
I would like to sum up my current results. I edited my mbed_app.json, recompiled everything, and be able to connect up to 8 devices to my arduino.

I found the right macro names in this file (mbed-os repository) : mbed_lib.json.

Unfortunately I cannot increase the maximum number of connections. If I set max-connections to something >8 the BLE Server does not start. Maybe I have to increse some memory size? If yes, where? But I have to admit, I actually dont know how to debug this right now.

@facchinm
Copy link
Member

Hi @Dorsel89 ,
sorry for the late response but I missed this thread. It could indeed be a memory limitation related to ble thread; if so, you could try increasing the allocated memory here (https://github.com/arduino-libraries/ArduinoBLE/blob/master/src/utility/HCICordioTransport.cpp#L164) so that line reads

static rtos::Thread bleLoopThread(osPriorityNormal, PREFERRED_STACK_SIZE);

By increasing PREFERRED_STACK_SIZE (from the initial 4KB) you can check if the BLE server starts again.

@Dorsel89
Copy link
Author

Hey @facchinm,

I just checked if the Bluetooth Server starts by changeing:

A) increase the STACK_SIZE of the bleLoopThread
and
B) increase the MBED_CONF_RTOS_THREAD_STACK_SIZE with the mbed_app.json

Of course both should do the same in the end, both ways do not work for max-connections = 9. I changed the size to 2*4096 for both ways.

Do you have any further ideas?

Many Thanks

@gnsmrky
Copy link

gnsmrky commented Aug 13, 2020

@Dorsel89 Can you share how you managed to do multiple concurrent connections? I have Arduino Nano 33 BLE acting as central. Only got 1 peripheral connection. 2nd connection always fails.

@polldo
Copy link
Contributor

polldo commented Aug 17, 2020

@gnsmrky you can follow this issue arduino-libraries/ArduinoBLE#108

@Dorsel89
Copy link
Author

Dorsel89 commented Aug 17, 2020

Hey @gnsmrky & @polldo ,
sorry for my late response. You can take a look at this library:

https://github.com/Dorsel89/phyphox-arduino

I just tested the example "randomNumbers" and it works on 2 phones at the same time for me. It should work up to 3 concurrent connections without changing the mbed_app.json. If you change the mbed_app.json as discussed in this issue you can get up to 8 connections. Unfortunately i did not manage to get more connections but it is still on my todo list.

Hope this helps

edit: I'm using the board driver: Arduino nrf528x Boards(Mbed OS) V 1.1.4

@Dorsel89
Copy link
Author

Hey @giulcioffi,

is there reason to stick at 5 connections? In general I would like to get up to 20 connections but I couldnt figure out why my bluetoothserver crashed with DM_CONN_MAX>8. Unfortunately this topic is not on top of my TODO list so I didnt spent any time on this since months..

@giulcioffi
Copy link

Hi @Dorsel89,
the reason why it crashes with DM_CONN_MAX = 8 is because there is not enough space in the RAM for it. We decided to stick at 5 connections because this can be handled fine with the RAM. However, since the methodology to increase the number of connected BLE peripherals has been provided, nothing prevents the user from customly adjust this number according to his/her needs :) Keep in mind that the higher the number of connected peripherals, the higher the min/max time intervals in ArduinoBLE library. So if you decide to increase DM_CONN_MAX, remember to increase also these two connection parameters. The explanation for this and how to set these parameters comes from mbed-os.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants