重命名Arduino Nano 33 BLE的特征

huangapple go评论74阅读模式
英文:

Rename Arduino nano 33 BLE from characteristics

问题

我需要使用Arduino Nano BLE 33和ArduinoBLE库开发一小批物品。有人知道批量命名这些物品的最佳方式吗?

我尝试设置BLE特征,但没有成功:

void changeNameCharWritten(BLEDevice central, BLECharacteristic characteristic) 
{
    BLE.setLocalName(changeNameChar.value);
    BLE.setDeviceName(changeNameChar.value);
}

参数是静态的。

是否有其他方法可以实现,还是我需要为每个设备编写特定的固件?

英文:

I need to develop a small batch of items with the Arduino Nano BLE 33 with the ArduinoBLE library. Does anybody know the best way to name the things in a batch?

I tried to set up a BLE characteristic with no success:

void changeNameCharWritten(BLEDevice central, BLECharacteristic characteristic) 
{
    BLE.setLocalName(changeNameChar.value);
    BLE.setDeviceName(changeNameChar.value);
}

The argument is static.

Is there any other way to do it or do I need to write a specific firmware for each device?

答案1

得分: 1

文档没有提到更改名称是不可能的。

查看BLELocalDevice::advertise()实现,我会假设在设置名称后,您需要调用BLE.advertise()来更新名称。

扩展您的示例:

void changeNameCharWritten(BLEDevice central, BLECharacteristic characteristic) 
{
    BLE.setLocalName(changeNameChar.value);
    BLE.setDeviceName(changeNameChar.value);
    // 在此之前可能需要调用BLE.stopAdvertise()
    BLE.advertise();
}
英文:

The documentation does not suggest that changing the name is not possible.

Looking at the implementation of BLELocalDevice::advertise() I would assume that you need to call BLE.advertise() to update the name after you did set it.

To extend your example:

void changeNameCharWritten(BLEDevice central, BLECharacteristic characteristic) 
{
    BLE.setLocalName(changeNameChar.value);
    BLE.setDeviceName(changeNameChar.value);
    // BLE.stopAdvertise() might be needed before
    BLE.advertise()
}

huangapple
  • 本文由 发表于 2023年7月17日 23:10:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/76705836.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定