ESP32 BLE 学习:关于 RSSI 与发射功率

  • Post author:
  • Post category:其他




ESP32 BLE 学习:关于 RSSI 与发射功率



蓝牙发射功率

工作频率:2.4GHz

蓝牙是能工作在以下三种功率级下的短距离无线网络技术:

功率级别 最高功率电平 有效范围 描述
功率级1 +20dbm 100m 即 0.1W, 是GSM手机最大功率的1/20
功率级2 +4dbm 20m 即2.5mW, 是蓝牙耳机常用功率等级
功率级3 0dbm 10m 即1mW, 是GSM手机最大功率的1/2000

esp32 的发射功率的控制范围为 -12dbm ~ 9 dbm (BR/EDR 和 BLE 都是),功率级别设置如下, 若程序中未设置发射功率,默认选择

ESP_PWR_LVL_P3

typedef enum {
    ESP_PWR_LVL_N12 = 0,                /*!< Corresponding to -12dbm */
    ESP_PWR_LVL_N9  = 1,                /*!< Corresponding to  -9dbm */
    ESP_PWR_LVL_N6  = 2,                /*!< Corresponding to  -6dbm */
    ESP_PWR_LVL_N3  = 3,                /*!< Corresponding to  -3dbm */
    ESP_PWR_LVL_N0  = 4,                /*!< Corresponding to   0dbm */
    ESP_PWR_LVL_P3  = 5,                /*!< Corresponding to  +3dbm */
    ESP_PWR_LVL_P6  = 6,                /*!< Corresponding to  +6dbm */
    ESP_PWR_LVL_P9  = 7,                /*!< Corresponding to  +9dbm */
    ESP_PWR_LVL_N14 = ESP_PWR_LVL_N12,  /*!< Backward compatibility! Setting to -14dbm will actually result to -12dbm */
    ESP_PWR_LVL_N11 = ESP_PWR_LVL_N9,   /*!< Backward compatibility! Setting to -11dbm will actually result to  -9dbm */
    ESP_PWR_LVL_N8  = ESP_PWR_LVL_N6,   /*!< Backward compatibility! Setting to  -8dbm will actually result to  -6dbm */
    ESP_PWR_LVL_N5  = ESP_PWR_LVL_N3,   /*!< Backward compatibility! Setting to  -5dbm will actually result to  -3dbm */
    ESP_PWR_LVL_N2  = ESP_PWR_LVL_N0,   /*!< Backward compatibility! Setting to  -2dbm will actually result to   0dbm */
    ESP_PWR_LVL_P1  = ESP_PWR_LVL_P3,   /*!< Backward compatibility! Setting to  +1dbm will actually result to  +3dbm */
    ESP_PWR_LVL_P4  = ESP_PWR_LVL_P6,   /*!< Backward compatibility! Setting to  +4dbm will actually result to  +6dbm */
    ESP_PWR_LVL_P7  = ESP_PWR_LVL_P9,   /*!< Backward compatibility! Setting to  +7dbm will actually result to  +9dbm */
} esp_power_level_t;

esp32s3 和 esp32c3 的发射功率的控制范围为 -27 dbm ~ 18 dbm,功率级别设置如下, 若程序中未设置发射功率,默认选择

ESP_PWR_LVL_P3

typedef enum {
    ESP_PWR_LVL_N27 = 0,              /*!< Corresponding to -27dbm */
    ESP_PWR_LVL_N24 = 1,              /*!< Corresponding to -24dbm */
    ESP_PWR_LVL_N21 = 2,              /*!< Corresponding to -21dbm */
    ESP_PWR_LVL_N18 = 3,              /*!< Corresponding to -18dbm */
    ESP_PWR_LVL_N15 = 4,              /*!< Corresponding to -15dbm */
    ESP_PWR_LVL_N12 = 5,              /*!< Corresponding to -12dbm */
    ESP_PWR_LVL_N9  = 6,              /*!< Corresponding to  -9dbm */
    ESP_PWR_LVL_N6  = 7,              /*!< Corresponding to  -6dbm */
    ESP_PWR_LVL_N3  = 8,              /*!< Corresponding to  -3dbm */
    ESP_PWR_LVL_N0  = 9,              /*!< Corresponding to   0dbm */
    ESP_PWR_LVL_P3  = 10,             /*!< Corresponding to  +3dbm */
    ESP_PWR_LVL_P6  = 11,             /*!< Corresponding to  +6dbm */
    ESP_PWR_LVL_P9  = 12,             /*!< Corresponding to  +9dbm */
    ESP_PWR_LVL_P12 = 13,             /*!< Corresponding to  +12dbm */
    ESP_PWR_LVL_P15 = 14,             /*!< Corresponding to  +15dbm */
    ESP_PWR_LVL_P18 = 15,             /*!< Corresponding to  +18dbm */
    ESP_PWR_LVL_INVALID = 0xFF,       /*!< Indicates an invalid value */
} esp_power_level_t;

esp32s3 数据手册上的可控制范围 是 -25 dbm ~ 20 dbm, 与代码中存在些差异

dbm是一个考征功率绝对值的值,计算公式为:10lgP(功率值/1mw),如功率值为 1mw, 则dbm = 0



RSSI(接收的信号强度指示)

Received Signal Strength Indication 接收的信号强度指示, 蓝牙扫描设备 (如手机) 看到的 RSSI 常为负值,原因有两点:一是蓝牙设备发射功率小,有的是功率级3 的蓝牙设备,发射功率电平最高是 0dbm; 二是路径损耗,主要指从发射机到接收机天线的能量消耗,和路径长度、周围环境、信号干扰都有很大关联

路径损耗与距离的

非官方计算公式



path loss = 40 + 25log(d)

, path loss标识路径损耗,d标识发射机和接收机的距离。数据统计如下:

路径损耗(path loss) 距离(d)
50dbm 2.5m
60dbm 6.3m
70dbm 16m
80dbm 40m
90dbm 100m
100dbm 250m
110dbm 630m

现有蓝牙规范要求接收机灵敏度要大于 -70dbm , 但实际一般低功耗蓝牙的控制器其灵敏度都可大 -90dBm

esp32 BLE 接收器灵敏度 @30.8% PER 范围 -94 dbm~ -92 dbm, 典型值是 -93 dbm

esp32s3 与 esp32c3 BLE 接收器灵敏度 @30.8% PER 范围

  • 1 Mbps: 典型值是 -97 dbm
  • 2 Mbps: 典型值是 -93 dbm
  • 500 Kbps: 典型值是 -100 dbm
  • 125 Kbps: 典型值是 -105 dbm

30.8% PER 表示 30.8 的错包率的情况下的 典型值

从上面来看,125 kbps 的包能传输的更远



API 函数设置和获取 发射功率

/* extra functions */
esp_err_t esp_ble_tx_power_set(esp_ble_power_type_t power_type, esp_power_level_t power_level)
{
    if (ble_txpwr_set(power_type, power_level) != 0) {
        return ESP_ERR_INVALID_ARG;
    }

    return ESP_OK;
}

esp_power_level_t esp_ble_tx_power_get(esp_ble_power_type_t power_type)
{
    return (esp_power_level_t)ble_txpwr_get(power_type);
}


esp_ble_power_type_t

可设置功率类型如下

/**
 * @brief BLE tx power type
 *        ESP_BLE_PWR_TYPE_CONN_HDL0-8: for each connection, and only be set after connection completed.
 *                                      when disconnect, the correspond TX power is not effected.
 *        ESP_BLE_PWR_TYPE_ADV : for advertising/scan response.
 *        ESP_BLE_PWR_TYPE_SCAN : for scan.
 *        ESP_BLE_PWR_TYPE_DEFAULT : if each connection's TX power is not set, it will use this default value.
 *                                   if neither in scan mode nor in adv mode, it will use this default value.
 *        If none of power type is set, system will use ESP_PWR_LVL_P3 as default for ADV/SCAN/CONN0-9.
 */
typedef enum {
    ESP_BLE_PWR_TYPE_CONN_HDL0  = 0,            /*!< For connection handle 0 */
    ESP_BLE_PWR_TYPE_CONN_HDL1  = 1,            /*!< For connection handle 1 */
    ESP_BLE_PWR_TYPE_CONN_HDL2  = 2,            /*!< For connection handle 2 */
    ESP_BLE_PWR_TYPE_CONN_HDL3  = 3,            /*!< For connection handle 3 */
    ESP_BLE_PWR_TYPE_CONN_HDL4  = 4,            /*!< For connection handle 4 */
    ESP_BLE_PWR_TYPE_CONN_HDL5  = 5,            /*!< For connection handle 5 */
    ESP_BLE_PWR_TYPE_CONN_HDL6  = 6,            /*!< For connection handle 6 */
    ESP_BLE_PWR_TYPE_CONN_HDL7  = 7,            /*!< For connection handle 7 */
    ESP_BLE_PWR_TYPE_CONN_HDL8  = 8,            /*!< For connection handle 8 */
    ESP_BLE_PWR_TYPE_ADV        = 9,            /*!< For advertising */
    ESP_BLE_PWR_TYPE_SCAN       = 10,           /*!< For scan */
    ESP_BLE_PWR_TYPE_DEFAULT    = 11,           /*!< For default, if not set other, it will use default value */
    ESP_BLE_PWR_TYPE_NUM        = 12,           /*!< TYPE numbers */
} esp_ble_power_type_t;

参考:


【BLE】信号强度(RSSI)知识整理


蓝牙功率等级划分


esp32、esp32s3 和 esp32c3 技术参考书



版权声明:本文为start_0912原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。