英文:
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()
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论