Local Name showing as "nRF5x" - not what I set it at in code - a second try


Hello, because no one replied to my question the first time I posted it, I will try again. I am using the BLE Nano 1 to read analog values from a resistive pressure sensor and transmit them to my computer (running windows 10). I have named my device “Button Test” and when I pair my computer to it, it initially connects to the device “Button Test” but after a couple seconds the name that is displayed as “Button Test” changes to “nRF5x”. When this happens, the software that I have written is no longer able to communicate with my device. It will say that it is connected, but when I try to read/write from any of my GATT characteristics the code returns the error that the device does not exist. This ONLY happens when the name of the device is shown as “nRF5x”. If the device name reads “Button Test” then everything works exactly how it should. I tried to add a shortened device name to see if that would help, but it didn’t.

Here is the code on the BLE Nano, from Mbed:

#include "mbed.h"
#include "ble/BLE.h"
#include "ButtonSensorService.h"

//Serial pc(USBTX, USBRX);

DigitalOut led1(LED1);
AnalogIn press(p4);

const static char       COMPLETE_DEVICE_NAME[] = "Button Test";
const static char       SHORTENED_DEVICE_NAME[] = "Btn 1";
const static uint16_t   uuid16_list[] = {ButtonSensorService::BUTTON_SENSOR_SERVICE_UUID};
static bool collecting = false;
static uint16_t analogValues[20] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
uint16_t length = 20;
static Gap::ConnectionParams_t fast;

static ButtonSensorService *btnSensorServicePtr;

void disconnectionCallBack(const Gap::DisconnectionCallbackParams_t *params)
    collecting = false;

void onDataWrittenCallback(const GattWriteCallbackParams *params)
    // Check to see what characteristic was written by handle
    if (params->handle == btnSensorServicePtr->sensorState.getValueHandle() && params->len == 1)
        collecting = *(params->data);
        //pc.printf("New bool written \r\n");

void GetData()
    for (int i = 0; i < length; i++)
        analogValues[i] = press.read_u16();
        //pc.printf("Value Read \r\n");

void periodicCallBack(void)
    led1 = !led1; // Do blinky to indicate it is alive

// Call this function if the BLE initialization fails
void onBLEInitError(BLE &ble, ble_error_t error)
    // Place error handling here

// Trigger when the BLE initialization has finished
void bleInitComplete(BLE::InitializationCompleteCallbackContext *params)
    BLE&            ble = params->ble;
    ble_error_t     error = params->error;
    if (error != BLE_ERROR_NONE)
        // In case of error, forward to error handling
        onBLEInitError(ble, error);
    // Ensure that it is the default instance of the BLE
    if (ble.getInstanceID() != BLE::DEFAULT_INSTANCE)
    // Setup primary service
    btnSensorServicePtr = new ButtonSensorService(ble, analogValues, collecting);
    // Setup Advertising
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::BREDR_NOT_SUPPORTED | GapAdvertisingData::LE_GENERAL_DISCOVERABLE);
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LIST_16BIT_SERVICE_IDS, (uint8_t *)uuid16_list, sizeof(uuid16_list));
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::COMPLETE_LOCAL_NAME, (uint8_t *)COMPLETE_DEVICE_NAME, sizeof(COMPLETE_DEVICE_NAME));
    ble.gap().accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (uint8_t *)SHORTENED_DEVICE_NAME, sizeof(SHORTENED_DEVICE_NAME));
    ble.gap().setAdvertisingInterval(100); /* 100ms. */

int main(void)
    led1 = 1;
    Ticker ticker;
    ticker.attach_us(periodicCallBack, 100000);
    BLE &ble = BLE::Instance();
    fast.minConnectionInterval = 8; // 10 ms
    fast.maxConnectionInterval = 8; // 10 ms
    fast.slaveLatency = 0;
    ble.securityManager().init();   // Uncomment to allow the device to pair to windows computers
    // Wait for initialization to complete
    //while (ble.hasInitialized() == false) // Spin Loop
    while (true)
        if (collecting)
            btnSensorServicePtr->UpdateAnalogValues((uint8_t*) analogValues, length);
            //pc.printf("Main Loop\r\n");

The ButtonSensorService.h code is:

    Author: Jayden Booth
    Date: 8/28/2017
    Code to set up the Custom BLE Profile for Button Sensor Services for the button sized 
        pressure sensor.
#include "ble/BLE.h"


class ButtonSensorService
        ReadWriteGattCharacteristic<bool> sensorState;
        const static uint16_t BUTTON_SENSOR_SERVICE_UUID        = 0xA042;
        const static uint16_t ANALOG_OUT_CHARACTERISTIC_UUID    = 0x2A59;
        const static uint16_t SENSOR_STATE_CHARACTERISTIC_UUID  = 0xA044;
        ButtonSensorService(BLE &_ble, uint16_t valueArrPtr[], bool state) : 
            analogValues(   ANALOG_OUT_CHARACTERISTIC_UUID, 
            sensorState(    SENSOR_STATE_CHARACTERISTIC_UUID, 
                            GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_NOTIFY | GattCharacteristic::BLE_GATT_CHAR_PROPERTIES_WRITE_WITHOUT_RESPONSE)
            GattCharacteristic  *charTable[] = { &analogValues, &sensorState };
            GattService         buttonSensorService(ButtonSensorService::BUTTON_SENSOR_SERVICE_UUID, charTable, sizeof(charTable)/sizeof(GattCharacteristic *));
        ble_error_t UpdateAnalogValues(uint8_t *newValuesPtr, uint16_t size)
            return ble.gattServer().write(analogValues.getValueHandle(), newValuesPtr, size);
        BLE &ble;
        ReadOnlyArrayGattCharacteristic<uint16_t, 20> analogValues;

#endif // ifndef __BLE_BUTTON_SENSOR_SERVICE_H__