BLE.connect causing "assertion failure" crash

Hi guys, I’m trying to get two Argon devices to pair via bluetooth - a “sensor” and a “clusterhead”. Currently however, the cluster head/central node crashes when it attempts to connect, showing the 10 red flashes corresponding to “assertion error.”

Here is the initial setup code for the sensor node:

const char* sensorNode1ServiceUuid("754ebf5e-ce31-4300-9fd5-a8fb4ee4a811");

const char* temperatureSensorUuid("bc7f18d9-2c43-408e-be25-62f40645987c");
BleCharacteristic temperatureSensorCharacteristic("temp",
BleCharacteristicProperty::NOTIFY, temperatureSensorUuid, sensorNode1ServiceUuid);
const char* lightSensorUuid("ea5248a4-43cc-4198-a4aa-79200a750835");
BleCharacteristic lightSensorCharacteristic("temp",
BleCharacteristicProperty::NOTIFY, lightSensorUuid, sensorNode1ServiceUuid);
const char* humiditySensorUuid("99a0d2f9-1cfa-42b3-b5ba-1b4d4341392f");
BleCharacteristic humiditySensorCharacteristic("temp",
BleCharacteristicProperty::NOTIFY, humiditySensorUuid, sensorNode1ServiceUuid);
const char* distanceSensorUuid("45be4a56-48f5-483c-8bb1-d3fee433c23c");
BleCharacteristic distanceSensorCharacteristic("temp",
BleCharacteristicProperty::NOTIFY, distanceSensorUuid, sensorNode1ServiceUuid);
void setup() {
    (void)logHandler; // Does nothing, just to eliminate the unused variable warning
    /* Setup bluetooth characteristics and advertise sensorNode1Service to be connected to by the clusterhead */
    BLE.on();//activate BT

    //add characteristics

    //data to be advertised
    BleAdvertisingData advData;

    // Continuously advertise when not connected to clusterhead"Start advertising");

Here is the code for the clusterhead:

void loop() {"Loop entered");
    //do stuff if both sensors have been connected
    if (sensorNode1.connected() /*&& sensorNode2.connected()*/) {"Connected!");
        //do stuff here
    //if we haven't connected both, then scan for them
    else {
        // We are not connected to our sensors, scan for them"About to scan...");
        int count = BLE.scan(scanResultCallback, NULL);
        if (count > 0) {
  "%d devices found", count);

/* function which executes while scanning on each bluetooth device which is discovered, to decide whether to conneect */
void scanResultCallback(const BleScanResult *scanResult, void *context) {"Found a bluetooth device...");
    //print info about the found bluetooth device"MAC: %02X:%02X:%02X:%02X:%02X:%02X | RSSI: %dBm",
            scanResult->address[0], scanResult->address[1], scanResult->address[2],
            scanResult->address[3], scanResult->address[4], scanResult->address[5], scanResult->rssi);

    // String name = scanResult->advertisingData.deviceName();
    // if (name.length() > 0) {
    //"deviceName: %s", name.c_str());
    // }
    /* Connect if it is one of our sensors */
    //After connecting, this is how long to wait without connection before determining that the other side is no longer available
    //Connection timeout is in units of 10 milliseconds. e.g. 1000 = 10 seconds 
    uint16_t timeoutInterval = 1000;
    //read the serviceUUID being advertised by this device
    BleUuid foundServiceUUID;
    size_t svcCount = scanResult->advertisingData.serviceUUID(&foundServiceUUID, 1);    
    //check if it matches sensorNode1"Found UUID: " + foundServiceUUID.toString());"Target UUID: " + sensorNode1ServiceUuid.toString());>address.toString());//prints "D7:C8:38:F8:2E:06"

    if (sensorNode1.connected() == false && svcCount > 0 && foundServiceUUID == sensorNode1ServiceUuid) {"Attempting to connect to sensor node 1...");
        sensorNode1 = BLE.connect(scanResult->address/*"D7:C8:38:F8:2E:06"*//*,24 ,0, timeoutInterval*/);//24 and 0 are default values
  "Successfully connected to sensor node 1!");
            //map characteristics from this service to the variables in this program, so they're handled by our "on<X>Received" functions
            sensorNode1.getCharacteristicByUUID(temperatureSensorCharacteristic1, "bc7f18d9-2c43-408e-be25-62f40645987c");
            sensorNode1.getCharacteristicByUUID(lightSensorCharacteristic1, "bc7f18d9-2c43-408e-be25-62f40645987c");
            sensorNode1.getCharacteristicByUUID(humiditySensorCharacteristic, "bc7f18d9-2c43-408e-be25-62f40645987c");
            sensorNode1.getCharacteristicByUUID(distanceSensorCharacteristic, "bc7f18d9-2c43-408e-be25-62f40645987c");
  "Failed to connect to sensor node 1.");

When the cluster head is started, it begins scanning and detecting bluetooth devices other than the sensor argon with no issues. It Logs all details successfully and ignores them.

Once I activate the sensor as well, it will be picked up in the scan, and the serviceUuid will be succesfully read and matched by the clusterhead. I can even get it to print out the MAC address of the sensor argon. All log statements print until the line


The program will then freeze, before eventually crashing the clusterhead argon and sending the 10 red flashes.

If I instead manually replace the scanResult->address with the observed string result of scanResult->address.toString() //"D7:C8:38:F8:2E:06", then the program does not crash, but the connection fails. The Log message “Failed to connect to sensor node 1” is printed. This will repeat indefinitely.

I’m all out of ideas for what to try next. Any help is appreciated!

This seems to be a “double post” of this

(I locked and hid the former thread for that reason)

Even if you don’t get an answer to that question on your first post it’s not appreciated to open an new thread for the same thing again.
You may ammend or bump your original post but don’t double post - it just scatters the conversation, potentially ties down resources on multiple fronts for the same thing and won’t add value to your request.

BTW, it’s just 2 days since your original post and these were weekend and bank holidays.

Sorry, just realised it was probably in the wrong category and didn’t know how to change that.

You can change the category by clicking the pencil icon next to the topic title


This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.