Update NimBLEAdvertising.cpp

Apparently a name length of 19 is a magic number because if it is longer than this then adding the null at the end isn't necessary, shortening the name works. Furthermore, adding the null appears to step on something and cause the uP to reboot. However if the name is shorter than 19 then adding a null at the end allows the name to be shortened without having the end of the previous longer name tacked onto the end of the shorter name AND it doesn't seem to step on anything as the uP appears to continue to operate fine.
This commit is contained in:
David Lehrian 2023-10-22 15:05:29 -07:00
parent 6b555d763b
commit 217d06ca3a

View file

@ -138,7 +138,7 @@ void NimBLEAdvertising::addTxPower() {
*/
void NimBLEAdvertising::setName(const std::string &name) {
m_name.assign(name.begin(), name.end());
m_name[name.length()] = 0;
if (name.length() <= 19) m_name[name.length()] = 0;
m_advData.name = &m_name[0];
m_advData.name_len = m_name.size();
m_advDataSet = false;