Closed wwj718 closed 8 months ago
If you are meaning to change the advertised name you can only do that while advertising is stopped. That name change you are using here will change the device name characteristic value only in this case.
@h2zero Thanks! It works!
I encountered another problem. Is the DeviceName only allowed to be changed once?
#include <Arduino.h>
#include <NimBLEDevice.h>
#include <NimBLEServer.h>
#include <NimBLEAdvertisedDevice.h>
/*
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
lib_deps = h2zero/NimBLE-Arduino@^1.4.1
*/
static NimBLEAdvertising *pAdvertising = nullptr;
static uint32_t count = 0;
BLEUUID serviceUUID("12345678-0003-4538-BCD7-7ECFB51297C1");
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
NimBLEDevice::init("test1");
pAdvertising = NimBLEDevice::getAdvertising();
pAdvertising->addServiceUUID(serviceUUID);
}
void loop() {
pAdvertising->stop();
count++;
char test[100] = "name";
char buffer[50];
sprintf(buffer, "%u", count);
strcat(test, buffer);
Serial.printf(test);
NimBLEDevice::setDeviceName(test);
pAdvertising->start();
delay(3000);
// setDeviceName allowing for changing the device name while the BLE stack is active.: https://github.com/h2zero/NimBLE-Arduino/blob/bc333ccb6e8d9ff2059af9cbd5006a290a4de3a5/CHANGELOG.md?plain=1#L17
}
The DeviceName is always "name1" (observe via NRF Connect).
There are 2 names, one in the advertisement and the other in the device name characteristic. If you just want to change the advertised name you should use pAdvertising->setName("new name");
.
It works for me, thanks a lot!
from the changelog: setDeviceName allowing for changing the device name while the BLE stack is active.
setDeviceName not working properly
I use esp32(esp32doit-devkit-v1, NimBLE-Arduino@^1.4.1), below is my code:
The DeviceName is always "test1"