From 80b16c58bbc517e085d66f11a62b7aabe0310048 Mon Sep 17 00:00:00 2001 From: lly Date: Wed, 27 May 2020 09:34:33 +0800 Subject: [PATCH] ble_mesh: stack: Add clear hb_pub in settings --- .../bt/esp_ble_mesh/mesh_core/settings.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/components/bt/esp_ble_mesh/mesh_core/settings.c b/components/bt/esp_ble_mesh/mesh_core/settings.c index beca5ad363..f3b711d93d 100644 --- a/components/bt/esp_ble_mesh/mesh_core/settings.c +++ b/components/bt/esp_ble_mesh/mesh_core/settings.c @@ -550,13 +550,13 @@ static int hb_pub_set(const char *name) BT_DBG("%s", __func__); if (!hb_pub) { - BT_ERR("Invalid heartbeat pub"); + BT_ERR("Invalid heartbeat publication"); return -EINVAL; } err = bt_mesh_load_core_settings(name, (u8_t *)&hb_val, sizeof(hb_val), &exist); if (err) { - BT_ERR("Failed to load heartbeat pub"); + BT_ERR("Failed to load heartbeat publication"); hb_pub->dst = BLE_MESH_ADDR_UNASSIGNED; hb_pub->count = 0U; hb_pub->ttl = 0U; @@ -1652,7 +1652,7 @@ static void store_pending_hb_pub(void) struct hb_pub_val val = {0}; if (!hb_pub) { - BT_WARN("NULL heartbeat publication"); + BT_ERR("Invalid heartbeat publication"); return; } @@ -1666,6 +1666,12 @@ static void store_pending_hb_pub(void) bt_mesh_save_core_settings("mesh/hb_pub", (const u8_t *)&val, sizeof(val)); } +static void clear_hb_pub(void) +{ + BT_DBG("Clear heartbeat publication"); + bt_mesh_erase_core_settings("mesh/hb_pub"); +} + static void store_pending_cfg(void) { struct bt_mesh_cfg_srv *cfg = bt_mesh_cfg_get(); @@ -2041,7 +2047,11 @@ static void store_pending(struct k_work *work) if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() && bt_mesh_atomic_test_and_clear_bit(bt_mesh.flags, BLE_MESH_HB_PUB_PENDING)) { - store_pending_hb_pub(); + if (bt_mesh_is_provisioned()) { + store_pending_hb_pub(); + } else { + clear_hb_pub(); + } } if (IS_ENABLED(CONFIG_BLE_MESH_NODE) && bt_mesh_is_node() &&