ArduinoBLE icon indicating copy to clipboard operation
ArduinoBLE copied to clipboard

(Nano.33 BLE Sense) problem with one Central and multi ( up to 10 ) peripherals

Open AR-kazemzadeh opened this issue 4 years ago • 1 comments

Hi Dear, I'm trying to connect multi ( up to 10 ) Nano.33 BLE Senes together with BLE, but I can connect two peripherals with ArduinoBLE.H v1.2.1 and Mbed OS 2.5.2. I do this test with Portenta H7 as Central and Nano.33 BLE Senes as peripherals, but I can't connect more than two peripherals. After trying Link By @polldo changes, I can connect with Portenta H7 as central to 3 Nano.33 BLE Senes as peripherals, but it's not Stable. I should reset ten times so I can connect to 3 peripherals. And I can't connect to more than two peripherals with Nano.33 BLE Senes as Central and peripherals. Below you can find a simplification of my code for the central and the peripheral (other peripherals are equal but with the name changed). Best Regards

Central:


#include 

//----------------------------------------------------------------------------------------------------------------------
// BLE UUIDs
//----------------------------------------------------------------------------------------------------------------------

// https://www.bluetooth.com/specifications/gatt/services//
// https://www.bluetooth.com/specifications/gatt/characteristics/



// define LED service & characteristic UUID
#define BLE_UUID_LED                             "19B10000-E8F2-537E-4F6C-D104768A1214" 
#define BLE_UUID_LED_CHAR                        "19B10001-E8F2-537E-4F6C-D104768A1214" 


// define max number of peripherals we want Scan 
#define BLE_MAX_PERIPHERALS 15  
// max interval for find peripherals
#define BLE_SCAN_INTERVALL 10000


// array of scaned peripherals
BLEDevice peripherals[BLE_MAX_PERIPHERALS];
// array of scaned peripherals characteristic
BLECharacteristic ledCharacteristics[BLE_MAX_PERIPHERALS];
// array of Led state for each peripherals
byte state[BLE_MAX_PERIPHERALS] ; 

//  final number of connected peripherals
int peripheralsConnected = 0;

// array of valid name of peripherals
String validperipheralNames[7] = { "LED_1" ,"LED_2" ,"LED_3" ,"LED_4" ,"LED_5" ,"LED_6" ,"LED_7" } ;




// set of central 
void setup()
{
  Serial.begin( 9600 );
  while ( !Serial );
  BLE.begin();

  BLE.scanForUuid( BLE_UUID_LED );  // scaning for finding peripherals with the input service UUID

  int peripheralCounter = 0;  // count founded peripherals 
  unsigned long startMillis = millis();

  // Continue until either the number of repetitions or the number of peripherals reaches its maximum
  while ( millis() - startMillis 

peripheral:

#include 

BLEService ledService("19B10000-E8F2-537E-4F6C-D104768A1214"); // BLE LED Service
//BLEService ledService("1101"); // BLE LED Service

// BLE LED Switch Characteristic - custom 128-bit UUID, read and writable by central
BLEByteCharacteristic switchCharacteristic("19B10001-E8F2-537E-4F6C-D104768A1214", BLERead | BLEWrite);
//BLEByteCharacteristic switchCharacteristic("2101", BLERead | BLEWrite|BLENotify);


const int ledPin = LED_BUILTIN; // pin to use for the LED

void setup() {
  Serial.begin(9600);
  //while (!Serial);

  // set LED pin to output mode
  pinMode(ledPin, OUTPUT);

  // begin initialization
  if (!BLE.begin()) {
    Serial.println("starting BLE failed!");

    while (1);
  }

  // set advertised local name and service UUID:
  BLE.setLocalName("LED_3");
  BLE.setAdvertisedService(ledService);

  // add the characteristic to the service
  ledService.addCharacteristic(switchCharacteristic);

  // add service
  BLE.addService(ledService);

  // set the initial value for the characeristic:
  switchCharacteristic.writeValue(0);

  // start advertising
  BLE.advertise();

  Serial.println("BLE LED Peripheral");
}

void loop() {
  // listen for BLE peripherals to connect:
  BLEDevice central = BLE.central();
  Serial.println("Not connected...");
  // if a central is connected to peripheral:
  if (central) {
    Serial.print("Connected to central: ");
    // print the central's MAC address:
    Serial.println(central.address());

    // while the central is still connected to peripheral:
    while (central.connected()) {
      // if the remote device wrote to the characteristic,
      // use the value to control the LED:
      if (switchCharacteristic.written()) {
        if (switchCharacteristic.value()) {   // any value other than 0
          Serial.println("LED on");
          digitalWrite(ledPin, HIGH);         // will turn the LED on
        } else {                              // a 0 value
          Serial.println(F("LED off"));
          digitalWrite(ledPin , LOW);          // will turn the LED off
        }
      }

    }

    // when the central disconnects, print it out:
    Serial.print(F("Disconnected from central: "));
    Serial.println(central.address());
  }
}

AR-kazemzadeh avatar Oct 03 '21 06:10 AR-kazemzadeh

Any update on this? Presently, I am using four Nano BLE 33 boards and also maxing out at subscribing 2 peripherals from a central, I can connect to and discover attributes from the third peripheral, but not subscribe.

I am using ArduinoBLE library version 1.3.1 and Mbed OS Nano Board version 3.4.1

Existentialist-Robot avatar Oct 21 '22 01:10 Existentialist-Robot