BLE Error Codes

Hey guys.

I’ve been trying to setup some basic BLE on my boron, but I don’t seem to be able to start advertising.
I setup some characteristics and callbacks, set some advertising data, then call

BLE.advertise(adv_data);

I’m getting a -270 return code and can’t for the life of me find a table of error code values.
Tried looking at the Nordic SDK BLE data, and am still digging through it.
If anyone has a link to documentation that’d be very appreciated.

My current draft code can be found on my github,
but I’m still getting this error with even a minimal example:

SYSTEM_THREAD(ENABLED);

// Private battery and power service UUID
const BleUuid serviceUuid("5c1b9a0d-b5be-4a40-8f7a-66b36d0a5176"); // CHANGE ME

BleCharacteristic uptimeCharacteristic(
  "uptime", 
  BleCharacteristicProperty::NOTIFY, 
  BleUuid("fdcf4a3f-3fed-4ed2-84e6-04bbb9ae04d4"), 
  serviceUuid);

BleCharacteristic signalStrengthCharacteristic(
  "strength", 
  BleCharacteristicProperty::NOTIFY, 
  BleUuid("cc97c20c-5822-4800-ade5-1f661d2133ee"), 
  serviceUuid);

BleCharacteristic freeMemoryCharacteristic(
  "freeMemory", 
  BleCharacteristicProperty::NOTIFY, 
  BleUuid("d2b26bf3-9792-42fc-9e8a-41f6107df04c"), 
  serviceUuid);

void configureBLE() {
  BLE.addCharacteristic(uptimeCharacteristic);
  BLE.addCharacteristic(signalStrengthCharacteristic);
  BLE.addCharacteristic(freeMemoryCharacteristic);

  BleAdvertisingData advData;

  // Advertise our private service only
  advData.appendServiceUUID(serviceUuid);

  // Continuously advertise when not connected
  BLE.advertise(&advData); // Returning -270
}

void setup() {
  configureBLE();
}

void loop() {
  if (BLE.connected())
  {
    uptimeCharacteristic.setValue(System.uptime());
    signalStrengthCharacteristic.setValue(Cellular.getSignal().getStrengthValue());
    freeMemoryCharacteristic.setValue(System.freeMemory());
  }
}

Is this the exact code you are running?
I see a stray semi-colon in this line

What device OS version are you running?

When I try your code with 3.3.0 and connect to the Boron my SerialLogHandler logger(LOG_LEVEL_ALL) reports a bunch of data but I cannot see an error code.

Updated to reflect the actual code.
I’m using 3.3.0, compiling with Workbench (locally).

Added the logger to my own test.
Added some initial delay to fully capture serial data on my machine’s terminal.
Seems to be working now… might be I’m just trying to start the BLE peripheral too aggressively.

#include "Particle.h"

SYSTEM_THREAD(ENABLED);

SerialLogHandler logger(LOG_LEVEL_ALL);

// Private battery and power service UUID
const BleUuid serviceUuid("5c1b9a0d-b5be-4a40-8f7a-66b36d0a5176"); // CHANGE ME

BleCharacteristic uptimeCharacteristic(
  "uptime",
  BleCharacteristicProperty::NOTIFY,
  BleUuid("fdcf4a3f-3fed-4ed2-84e6-04bbb9ae04d4"),
  serviceUuid);

BleCharacteristic signalStrengthCharacteristic(
  "strength",
  BleCharacteristicProperty::NOTIFY,
  BleUuid("cc97c20c-5822-4800-ade5-1f661d2133ee"),
  serviceUuid);

BleCharacteristic freeMemoryCharacteristic(
  "freeMemory",
  BleCharacteristicProperty::NOTIFY,
  BleUuid("d2b26bf3-9792-42fc-9e8a-41f6107df04c"),
  serviceUuid);

void configureBLE() {
  BLE.addCharacteristic(uptimeCharacteristic);
  BLE.addCharacteristic(signalStrengthCharacteristic);
  BLE.addCharacteristic(freeMemoryCharacteristic);
  BLE.setDeviceName("BLETEST");

  BleAdvertisingData advData;

  // Advertise our private service only
  advData.appendServiceUUID(serviceUuid);
  advData.appendLocalName("LOCAL1");
  Log.trace("BLE result %d", BLE.advertise(&advData)); // Returning -270
}

void setup() {
  delay(1000);
  Log.trace("Startup");
  configureBLE();
}

void loop() {
  if (BLE.connected())
  {
    Log.trace("BLE Connected");
    uptimeCharacteristic.setValue(System.uptime());
    signalStrengthCharacteristic.setValue(Cellular.getSignal().getStrengthValue());
    freeMemoryCharacteristic.setValue(System.freeMemory());
  }
}

This code functions

2 Likes

It appears like setting BLE.setDeviceName or BleAdrevtisingData::appendLocalName with too many characters is one cause of this error.