From bd7ea4a17a6083f465fa199f84d1b55ef7c1c838 Mon Sep 17 00:00:00 2001 From: jhchun Date: Tue, 25 Aug 2026 18:23:37 +0900 Subject: [PATCH] =?UTF-8?q?BLE=20advertising=20=EC=83=81=ED=83=9C=20?= =?UTF-8?q?=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 연결 성공 시 advertising stop - 이미 advertising 꺼진 경우 -EALREADY 정상 처리 - advertising identity 사용 옵션 추가: BT_LE_ADV_OPT_USE_IDENTITY --- src/ble/ble_service.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ble/ble_service.c b/src/ble/ble_service.c index 570ed21..b5cec68 100644 --- a/src/ble/ble_service.c +++ b/src/ble/ble_service.c @@ -571,6 +571,7 @@ static void connected(struct bt_conn *conn, uint8_t err) current_conn = bt_conn_ref(conn); ble_connection_st = true; + (void)ble_advertising_stop(); ble_tx_power_on_connected(conn); // TX power/RSSI 상태는 별도 모듈에서 관리 char addr_str[BT_ADDR_LE_STR_LEN]; @@ -768,6 +769,7 @@ int ble_service_init(ble_data_rx_cb_t rx_cb) k_work_init_delayable(&pairing_window_timeout_work, pairing_window_timeout_handler); #endif ble_tx_power_init(); + // BLE stack 활성화 err = bt_enable(NULL); if (err) @@ -825,7 +827,7 @@ int ble_advertising_start(void) }; struct bt_le_adv_param adv_param = BT_LE_ADV_PARAM_INIT( - BT_LE_ADV_OPT_CONN, + BT_LE_ADV_OPT_CONN | BT_LE_ADV_OPT_USE_IDENTITY, APP_ADV_INTERVAL, // min interval APP_ADV_INTERVAL, // max interval NULL // undirected @@ -862,6 +864,13 @@ int ble_advertising_start(void) int ble_advertising_stop(void) { int err = bt_le_adv_stop(); + if (err == -EALREADY) + { + k_work_cancel_delayable(&adv_timeout_work); + DBG_PRINTF("[BLE] Advertising already stopped\r\n"); + return 0; + } + if (err) { DBG_ERR("[BLE] Adv stop failed (err %d)\r\n", err);