[Solved] BLE_GROUP: can't make it work on DeviceOS 3.1

Hi,

I am running the typical usage example from the BLE_GROUP library as per this article.

Namely, on the central device:

#include "BLE_Group.h"
BLE_Group *group;

void callbackFunc(const char *event, const char *data)
{
  Log.info("Event: %s, Data: %s", event, data);
}

void setup() {
  group = new BLE_Group_Central(1); // The parameter is the groupID
  group->subscribe("test", callbackFunc);
}

void loop() {
  group->publish("test-central", "Some data");
}

and on the peripheral:

#include "BLE_Group.h"
BLE_Group *group;

void callbackFunc(const char *event, const char *data)
{
  Log.info("Event: %s, Data: %s", event, data);
}

void setup() {
  group = new BLE_Group_Peripheral(1); // The parameter is the groupID
  group->subscribe("test", callbackFunc);
}

void loop() {
  group->publish("test-periph", "Some Data");
}

I flash this to two argons, but nothing happens.


Things I’ve tried:

  • I’ve added Ble.on() in setup() in the hopes this turns on BLE, nothing.

  • I’ve changed groupID in both (same value=2), nothing

  • I’ve added:

SYSTEM_THREAD(ENABLED);
SerialLogHandler logHandler(LOG_LEVEL_ALL);

nothing.

  • I’ve added a small delay plus an info statement in the loop: that’s the only thing I observe in the serial monitor of either.
void loop()
{
  group->publish("test-central", "Some data");
  Log.info("looping in central");
  delay(1000);
}

  • I’ve tried a DeviceOs 3.1 Boron and no success there either

  • I’ve tried another DeviceOs 3.1 Argon and … nothing

I’m using DeviceOs 3.1 on all devices.

I know the devices’ BLE work because I tried this Body temp thermomenter example and I’m able to connect to each one of them from my phone with the NRF Toolbox app.

I read (maybe) all hits from the search on ble_group on the community forum, nothing conclusive.

How can I troubleshoot this?
Thanks!
FYI: @mariano

If you are using Device OS 3.1.0 you’re probably running into the BLE scan bug in 3.1.0.

To work around it, just add this to your setup() function:

#if SYSTEM_VERSION == SYSTEM_VERSION_v310
    // This is required with 3.1.0 only
    BLE.setScanPhy(BlePhy::BLE_PHYS_AUTO);
#endif
1 Like

Thank you.

It might be related, but I couldn’t make it work with BLE_GROUP.

I tried these versions of setup:

void setup()
{
#if SYSTEM_VERSION == SYSTEM_VERSION_v310
  // This is required with 3.1.0 only
  BLE.setScanPhy(BlePhy::BLE_PHYS_AUTO);
#endif

  group = new BLE_Group_Central(2); // The parameter is the groupID
  group->subscribe("test", callbackFunc);
}

and

void setup()
{
  group = new BLE_Group_Central(2); // The parameter is the groupID
  group->subscribe("test", callbackFunc);
  BLE.setScanPhy(BlePhy::BLE_PHYS_AUTO);
}

and

void setup()
{
  BLE.setScanPhy(BlePhy::BLE_PHYS_AUTO);
  group = new BLE_Group_Central(2); // The parameter is the groupID
  group->subscribe("test", callbackFunc);
}

but still nothing, no connection between devices.
Is there a particular way that BLE_GROUP might be hitting that issue?

Thanks

In the Central device, you need to add the scanning so that it will find the peripheral. From the heartbeat example:

    if (group->devices_connected() < BLE_GROUP_MAX_PERIPHERALS && (millis() - scan_time) > 3000)
    {
      group->scan();
      scan_time = millis();
    }

You should add that in loop()

I’ll add this to the article that you linked, as I just noticed that the scanning part is missing from it.

2 Likes

Please do, and the library docs, as well?

I think those two fixes did it for me. Mystery solved.
Thank you!

1 Like

The solution is two fold:

Fix #1:

Fix #2:

Thank you @mariano and @rickkas7

3 Likes

Rick, a follow up question on this ble scan issue.

If instead of doing:

BLE.setScanPhy(BlePhy::BLE_PHYS_AUTO);

I do:

BLE.setScanPhy(BlePhy::BLE_PHYS_1MBPS | BlePhy::BLE_PHYS_CODED);

Will I still be working around the BLE scan bug in 3.1.0 you mentioned?

Thank you,
Gustavo.

Yes, it should work. The problem is that the variable is uninitialized in 3.1.0, so the behavior is unpredictable if not set, but you can set it to the coded PHY version instead like that.

1 Like