Change Local Name with serial data


#1

Hi friends… Can anyone help me to change Local Name BLE Nano 2 ? I want to change the local name with data from simple chat :

void gattServerWriteCallBack(const GattWriteCallbackParams *Handler) {
uint8_t buf[TXRX_BUF_LEN];
uint8_t index, names[TXRX_BUF_LEN];
uint16_t bytesRead = TXRX_BUF_LEN;

Serial.println("onDataWritten : ");
if (Handler->handle == characteristic1.getValueAttribute().getHandle()) {
ble.readCharacteristicValue(characteristic1.getValueAttribute().getHandle(), buf, &bytesRead);
Serial.print(“bytesRead: “);
Serial.println(bytesRead, HEX);
for(index=0; index<bytesRead; index++) {
dataRcv += (char)buf[index];
}
Serial.println(””);
}

if(dataRcv==“OK”) {
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME,
(uint8_t *)dataRcv, sizeof(dataRcv) - 1);
// start advertising
ble.startAdvertising();
}
dataRcv = NULL;
}


#2

me neither, I just bought a BLE-Nano v2 module bluetooth and start to working on to change the name via bluetooth advertising and the name doesn’t change. Someone maybe can help us :slight_smile:


#3

It seems, that you have omitted the relevant part of the code.
first, define a
#define DEVICE_NAME “YOUR-NAME”

then, in the setup()
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1);
Examples already do that, you have just to change the constant.


#4

thank you for your respon @pt-makerlab and @irfan
i have already to change local name bluetooth with your suggestion

#define DEVICE_NAME “YOUR-NAME”

then, in the setup()
ble.accumulateAdvertisingPayload(GapAdvertisingData::SHORTENED_LOCAL_NAME, (const uint8_t *)DEVICE_NAME, sizeof(DEVICE_NAME) - 1);

and it’s work . :slight_smile:

But in my problem, if i change #define DEVICE_NAME “YOUR-NAME” with a variable like uint8_t name[2]={‘o’,‘k’}; it’s not work.:frowning:

Is it possible to use a variable to change local name ? or may be because there is constant variable((const uint8_t ) ?


#5

From what I read in durr question topics, he want to custom the variable that handle the local name from constant uint8_t to another variable, so he can do a custom work with the name. Maybe like change the name via bluetooth command (not in the code program). I just work on that too recently, but still no luck… :joy: