fix BLE advert name for backwards compatibility

This commit is contained in:
liquidraver
2026-03-16 11:49:12 +01:00
parent 96dd454c04
commit eb5149fd0f
3 changed files with 13 additions and 15 deletions
+3 -4
View File
@@ -35,7 +35,7 @@ LOG_MODULE_REGISTER(zephcore_ble, CONFIG_ZEPHCORE_BLE_LOG_LEVEL);
/* ========== Constants ========== */
#define DEVICE_NAME_MAX 24
#define DEVICE_NAME_MAX 29
#define FRAME_QUEUE_SIZE CONFIG_ZEPHCORE_BLE_QUEUE_SIZE
#define BLE_TX_POWER 4
#define BLE_TX_RETRY_MS 20
@@ -230,9 +230,8 @@ static int secure_nus_send(struct bt_conn *conn, const void *data, uint16_t len)
static void build_device_name_and_adv(const char *name_from_prefs)
{
if (name_from_prefs && name_from_prefs[0]) {
size_t name_len = strnlen(name_from_prefs, sizeof(device_name) - 1);
memcpy(device_name, name_from_prefs, name_len);
device_name[name_len] = '\0';
/* Prepend "MeshCore-" prefix so apps that filter on it can find us */
snprintf(device_name, sizeof(device_name), "MeshCore-%s", name_from_prefs);
/* Apple BLE Accessory Design Guidelines: device name must not
* contain ':' or ';' characters. Replace with '-'.
+1 -1
View File
@@ -66,7 +66,7 @@ CONFIG_BT_ZEPHYR_NUS=y
CONFIG_BT_ZEPHYR_NUS_DEFAULT_INSTANCE=n
CONFIG_BT_DEVICE_NAME="MeshCore"
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
CONFIG_BT_DEVICE_NAME_MAX=24
CONFIG_BT_DEVICE_NAME_MAX=29
CONFIG_BT_DEVICE_NAME_GATT_WRITABLE=y
CONFIG_BT_DEVICE_APPEARANCE=0
CONFIG_BT_MAX_CONN=1
+9 -10
View File
@@ -546,16 +546,6 @@ int main(void)
companion_mesh.prefs.rx_duty_cycle = 1; /* Companions: duty cycle ON by default (power save) */
companion_mesh.prefs.rx_boost = 1; /* Default: boosted RX (+3dB sensitivity, +2mA) */
/* Generate default node name from hardware device ID */
uint8_t dev_id[8];
ssize_t id_len = hwinfo_get_device_id(dev_id, sizeof(dev_id));
if (id_len >= 4) {
snprintf(companion_mesh.prefs.node_name, sizeof(companion_mesh.prefs.node_name),
"MeshCore-%02X%02X%02X%02X", dev_id[0], dev_id[1], dev_id[2], dev_id[3]);
} else {
strncpy(companion_mesh.prefs.node_name, "MeshCore", sizeof(companion_mesh.prefs.node_name) - 1);
}
/* Load prefs from storage */
data_store.loadPrefs(companion_mesh.prefs);
@@ -598,6 +588,15 @@ int main(void)
}
companion_mesh.self_id = self_identity;
/* Set default node name from first 4 bytes of public key if not set.
* Must happen after identity load so pub_key is available. */
if (companion_mesh.prefs.node_name[0] == '\0') {
snprintf(companion_mesh.prefs.node_name, sizeof(companion_mesh.prefs.node_name),
"%02X%02X%02X%02X",
self_identity.pub_key[0], self_identity.pub_key[1],
self_identity.pub_key[2], self_identity.pub_key[3]);
}
/* Set callbacks */
companion_mesh.setWriteFrameCallback(write_frame);
companion_mesh.setPushCallback(push_callback);