[nano33ble] Multiple Concurrent Connections · Issue #108 - GitHub

Skip to content Dismiss alert {{ message }} / ArduinoBLE Public
  • Notifications You must be signed in to change notification settings
  • Fork 231
  • Star 345
  • Code
  • Issues 114
  • Pull requests 22
  • Actions
  • Projects
  • Security

    Uh oh!

    There was an error while loading. Please reload this page.

  • Insights
Additional navigation options [nano33ble] Multiple concurrent connections #108New issueNew issueOpenOpen[nano33ble] Multiple concurrent connections#108Labelshelp wantedAssistance from the community is especially welcometype: imperfectionPerceived defect in any part of project@polldo

Description

@polldopolldoopened on Aug 17, 2020

ArduinoBLE library supports up to ATT_MAX_PEERS multiple concurrent connections.

ArduinoBLE/src/utility/ATT.h

Lines 29 to 35 in 8a49b8c

#if defined(ARDUINO_PORTENTA_H7_M4) || defined(ARDUINO_PORTENTA_H7_M7)
#define ATT_MAX_PEERS 7
#elif DM_CONN_MAX
#define ATT_MAX_PEERS DM_CONN_MAX // Mbed + Cordio
#else
#define ATT_MAX_PEERS 3
#endif
However, using the latest versions of the nano33ble core there are problems when trying to handle multiple connections.
  • With version 1.1.3 of the core arduino/ArduinoCore-nRF528x-mbedos@67ef327 the board does not present any problems.
  • With version 1.1.4 arduino/ArduinoCore-nRF528x-mbedos@f4ddc96 and following, if the nano33ble board works as a central device, then it cannot connect to multiple peripherals. On the other hand, if it works as a peripheral device, then it is able to handle multiple central devices connected to it.

SETUP: ArduinoBLE version: 1.1.3-10-g89fd740 89fd740 , in branch 'multi-connection' https://github.com/arduino-libraries/ArduinoBLE/tree/multi-connection

Test sketches

  • Central, connecting to more peripherals:
#include <ArduinoBLE.h> void setup() { Serial.begin(115200); while(!Serial); BLE.begin(); BLE.debug(Serial); BLE.scanForName("peripheral"); } void connectionLoop() { // If not already connected to 2 peripherals, try to connect to a new found peripheral. if (BLE.peripheralCount() < 2) { BLEDevice peripheral = BLE.available(); if (peripheral) { BLE.stopScan(); if (!peripheral.connect()) { Serial.println("Failed to connect!"); return; } if (!peripheral.discoverAttributes()) { Serial.println("Attribute discovery failed!"); peripheral.disconnect(); return; } } } } auto timeRef = millis(); void loop() { connectionLoop(); if (millis() - timeRef >= 5000) { timeRef = millis(); int periphCount = BLE.peripheralCount(); Serial.print(" Peripheral connected: "); Serial.println(periphCount); if (periphCount < 2) { BLE.scanForName("peripheral"); } // Loop through all connected peripherals for (int periphIdx = 0; periphIdx < periphCount; periphIdx++) { BLEDevice peripheral = BLE.peripheral(periphIdx); if (peripheral) { BLECharacteristic batteryLevelChar = peripheral.characteristic("2A19"); if (!batteryLevelChar) { Serial.println("Peripheral does not have battery level characteristic!"); peripheral.disconnect(); } else { Serial.print("Peripheral connected, value: "); batteryLevelChar.read(); Serial.println(*batteryLevelChar.value()); } } } } }
  • Peripherals:
#include <ArduinoBLE.h> BLEService batteryService("180F"); BLEUnsignedCharCharacteristic batteryLevelChar("2A19", BLERead | BLEWrite); void setup() { Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); if (!BLE.begin()) { Serial.println("starting BLE failed!"); while (1); } // Configure peripheral BLE.setLocalName("peripheral"); BLE.setAdvertisedService(batteryService); batteryService.addCharacteristic(batteryLevelChar); BLE.addService(batteryService); BLE.advertise(); Serial.println("peripheral configured - central connected: 0"); } auto timeRef = millis(); void loop() { static uint8_t battery = 0; BLE.poll(); if (millis() - timeRef >= 3000) { timeRef = millis(); if (BLE.centralCount() > 0) { digitalWrite(LED_BUILTIN, HIGH); batteryLevelChar.writeValue(battery); battery++; } else { digitalWrite(LED_BUILTIN, LOW); } } }

Metadata

Metadata

Assignees

No one assigned

Labels

help wantedAssistance from the community is especially welcometype: imperfectionPerceived defect in any part of project

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You can’t perform that action at this time.

Tag » Arduino Ble Multiple Clients