Can't Connect to multiple Feathers Simultaneously

Please tell us which board you are using.
For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Charleszard
 
Posts: 7
Joined: Mon May 14, 2018 7:09 pm

Can't Connect to multiple Feathers Simultaneously

Post by Charleszard »

Hi there. I'm trying to connect to two feathers simultaneously with a third feather acting as the central.

So far, I can only connect to one at a time, and can connect to one or the other at will by resetting the currently connected feather, causing the central to connect to the other feather.

I've tried looking at the central_bleuart_multi example without any good clues, since the code is quite different when using bleuart.

I feel like I'm missing something simple. My code for the central feather is attached, please give it a glance over and see if there are any glaring errors.

Code: Select all

#include <bluefruit.h>

bool signalPrinted = false;

uint8_t ecgSignal1[20];
uint8_t ecgSignal2[20];
bool ecgSignal1Received = false;
bool ecgSignal2Received = false;


BLEClientService        siggens(0x0dd756a1fdd844c082bff7517ae37455); //IRONMAN
BLEClientCharacteristic sigc(0xdce59ddcb38f49af83b098feb8a3c592);
BLEClientService siggens2(0x0dd756a1fdd844c082bff7517ae37454);
BLEClientCharacteristic sigc2(0xdce59ddcb38f49af83b098feb8a3c591);

void setup()
{
  Serial.begin(9600);

  Serial.println("BLE ECG Central");
  Serial.println("------------------\n");

  Bluefruit.begin(0, 2);

  Bluefruit.setName("BLE ECG Central");

  siggens.begin();
  sigc.setNotifyCallback(hrm_notify_callback);
  sigc.begin();

  siggens2.begin();
  sigc2.setNotifyCallback(hrm_notify_callback2);
  sigc2.begin();
  Serial.println("Notify Callback Set");


  Serial.println("Characteristic begin'd");

  // Callbacks for Central
  Bluefruit.Central.setDisconnectCallback(disconnect_callback);
  Bluefruit.Central.setConnectCallback(connect_callback);

  Bluefruit.Scanner.setRxCallback(scan_callback);
  Bluefruit.Scanner.restartOnDisconnect(true);
  Bluefruit.Scanner.setInterval(160, 80); // in unit of 0.625 ms
  Bluefruit.Scanner.filterUuid(siggens.uuid, siggens2.uuid);
  Bluefruit.Scanner.useActiveScan(false);
  Bluefruit.Scanner.start(0);                   // // 0 = Don't stop scanning after n seconds

  Serial.println("Settings set. Scanning.");

}

void loop()
{


  if (ecgSignal1Received && ecgSignal2Received) {
    for (int x = 0; x < 20; x++) {
      Serial.print(ecgSignal1[x]);
      Serial.print(" ");
      Serial.print(ecgSignal2[x]);
      Serial.print(" ");
      Serial.println();
    }
    ecgSignal1Received = false;
    ecgSignal2Received = false;
  }

}

void scan_callback(ble_gap_evt_adv_report_t* report)
{
  Bluefruit.Central.connect(report);
  Serial.println("Connected");
}

void connect_callback(uint16_t conn_handle)
{
  siggens.discover(conn_handle);
  Serial.println("Service discovered");

  sigc.discover();
  Serial.println("Characteristic discovered");

  sigc.enableNotify();
  Serial.println("Notify enabled");

  siggens2.discover(conn_handle);
  Serial.println("Service 2 discovered");

  sigc2.discover();
  Serial.println("Characteristic 2 discovered");

  sigc2.enableNotify();
  Serial.println("Notify 2 enabled");
}

void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
  (void) conn_handle;
  (void) reason;
  Serial.println("disconnected");

}

void hrm_notify_callback(BLEClientCharacteristic* chr, uint8_t* data, uint16_t len)
{
  for (int i = 0; i < len; i++) {
    ecgSignal1[i] = data[i];
//    Serial.println(data[i]);
  }
  ecgSignal1Received = true;
}

void hrm_notify_callback2(BLEClientCharacteristic* chr, uint8_t* data2, uint16_t len)
{
  for (int i = 0; i < len; i++) {
    ecgSignal2[i] = data2[i];
//    Serial.print(" ");
//    Serial.println(data2[i]);
  }
  ecgSignal2Received = true;
}

User avatar
adafruit_support_mike
 
Posts: 67446
Joined: Thu Feb 11, 2010 2:51 pm

Re: Can't Connect to multiple Feathers Simultaneously

Post by adafruit_support_mike »

The only microcontroller we carry that can work as a BLE central is the nRF52, and I'm not sure if that supports multiple peripheral connections.

User avatar
hathach
 
Posts: 1270
Joined: Tue Apr 23, 2013 1:02 am

Re: Can't Connect to multiple Feathers Simultaneously

Post by hathach »

feather52 could connect to multiple prphs as a central. central_bleuart_multi is indeed the example to start with. You should run and study it a bit before going with your custom service. BTW, did the long int init works, I didn't know we could do that.

Code: Select all

BLEClientService        siggens(0x0dd756a1fdd844c082bff7517ae37455); //IRONMAN
BLEClientCharacteristic sigc(0xdce59ddcb38f49af83b098feb8a3c592);
BLEClientService siggens2(0x0dd756a1fdd844c082bff7517ae37454);
BLEClientCharacteristic sigc2(0xdce59ddcb38f49af83b098feb8a3c591);

User avatar
Charleszard
 
Posts: 7
Joined: Mon May 14, 2018 7:09 pm

Re: Can't Connect to multiple Feathers Simultaneously

Post by Charleszard »

BTW, did the long int init works
Yeah, works just fine. I've used it in multiple projects by now.

I've run and studied bleuart_multi plenty at this point, and have gotten it to work. However I really need it to work with my custom service, as the BLEUART protocol doesn't have the speed and flexibility I need for my applications.

If anyone has anything else to add I'd really appreciate it.

User avatar
hathach
 
Posts: 1270
Joined: Tue Apr 23, 2013 1:02 am

Re: Can't Connect to multiple Feathers Simultaneously

Post by hathach »

Thanks, that is innovative way to init the service and char. Did you enable debug level 1 or 2 and try to analyze its message when the problem occurred. You should enable debug on all feather52, if possible, post the log of them here for us to analyze.

Locked
Please be positive and constructive with your questions and comments.

Return to “Feather - Adafruit's lightweight platform”