Power Measure
This example demonstrates how to use the BL0937 power measurement chip to detect electrical parameters such as voltage, current, active power, and energy consumption.
Adapted Products
Name |
Function |
Vendor |
Datasheet |
HAL |
---|---|---|---|---|
BL0937 |
detect electrical parameters such as voltage, current, active power, and energy consumption |
BELLING |
x |
API Reference
The following API implements hardware abstraction for power measure. Users can directly call this layer of code to write sensor applications.
Header File
Functions
-
esp_err_t power_measure_init(power_measure_init_config_t *config)
power measure component int
- Parameters
config – configuration for power measure hardware
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_NO_MEM
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_deinit()
power measure component deint
- Returns
ESP_OK
ESP_FAIL
-
esp_err_t power_measure_get_voltage(float *voltage)
get current vltage (V)
- Parameters
voltage – current voltage (V)
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_current(float *current)
get current current (A)
- Parameters
current – current current (A)
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_active_power(float *active_power)
get current active power (W)
- Parameters
active_power – current active power (W)
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_power_factor(float *power_factor)
get current power factor
- Parameters
power_factor – power factor
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_energy(float *energy)
get current energy (Kw/h)
- Parameters
energy – Power consumed by the load (Kw/h)
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_start_energy_calculation()
start the energy calculation
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_stop_energy_calculation()
stop the energy calculation
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_reset_energy_calculation()
reset the energy accumulated value in flash
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_start_calibration(calibration_parameter_t *para)
start calibration for factory test
- Parameters
para – calibration parameters
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_ARG
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_get_calibration_factor(calibration_factor_t *factor)
get calibration factor from flash
- Parameters
factor – calibration factor
- Returns
ESP_OK
ESP_FAIL
ESP_ERR_INVALID_STATE
-
esp_err_t power_measure_calibration_factor_reset(void)
reset factor in flash
- Returns
ESP_OK
ESP_FAIL POWER_MEASURE
Structures
-
struct overcurrent_event_data_t
Data structure for overcurrent event data.
-
struct overvoltage_event_data_t
Data structure for overvoltage event data.
-
struct undervoltage_event_data_t
Data structure for undervoltage event data.
-
struct calibration_parameter_t
Structure for calibration parameters.
-
struct calibration_factor_t
Structure for calibration factors.
-
struct chip_config_t
Configuration structure for the chip.
Public Members
-
power_measure_chip_t type
Type of the chip used
-
calibration_factor_t factor
Calibration factors for the chip
-
gpio_num_t sel_gpio
GPIO number for selection
-
gpio_num_t cf1_gpio
GPIO number for CF1
-
gpio_num_t cf_gpio
GPIO number for CF
-
uint8_t pin_mode
Pin mode configuration
-
float sampling_resistor
Value of the sampling resistor
-
float divider_resistor
Value of the divider resistor
-
power_measure_chip_t type
-
struct power_measure_init_config_t
Initialization configuration structure for power measurement.
Macros
-
STORGE_FACTOR_KEY
STORGE_FACTOR_KEY.
Enumerations
-
enum power_measure_event_t
POWER_MEASURE event base.
Enumeration of power measurement events.
Values:
-
enumerator POWER_MEASURE_INIT_DONE
Initialisation Done
-
enumerator POWER_MEASURE_OVERCURRENT
Overcurrent detected
-
enumerator POWER_MEASURE_OVERVOLTAGE
Overvoltage detected
-
enumerator POWER_MEASURE_UNDERVOLTAGE
Undervoltage
-
enumerator POWER_MEASURE_ENERGY_REPORT
report energy
-
enumerator POWER_MEASURE_HOME_APPLIANCES_ONLINE
appliances online
-
enumerator POWER_MEASURE_HOME_APPLIANCES_OFFLINE
appliances offline
-
enumerator POWER_MEASURE_INIT_DONE