GithubHelp home page GithubHelp logo

Comments (4)

h2zero avatar h2zero commented on June 15, 2024 2

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");.

from nimble-arduino.

h2zero avatar h2zero commented on June 15, 2024

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.

from nimble-arduino.

wwj718 avatar wwj718 commented on June 15, 2024

@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).

from nimble-arduino.

wwj718 avatar wwj718 commented on June 15, 2024

It works for me, thanks a lot!

from nimble-arduino.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.