温湿度传感器¶
温湿度传感器包括温度传感器、湿度传感器和兼具两种功能的传感器,可用于智慧人居、智慧农场、智能工厂等场景下的环境温湿度检测。
已适配列表¶
名称 |
功能 |
总线 |
供应商 |
规格书 |
硬件抽象层 |
---|---|---|---|---|---|
HDC2010 |
温度、湿度 |
I2C |
TI |
||
HTS221 |
温度、湿度 |
I2C |
ST |
√ |
|
SHT3X |
温度、湿度 |
I2C |
Sensirion |
√ |
|
MVH3004D |
温度、湿度 |
I2C |
– |
API 参考¶
以下 API 实现了对温湿度传感器的硬件抽象,用户可直接调用该层代码编写传感器应用程序,也可以使用 sensor_hub 中的传感器接口实现更简单的调用。
Header File¶
Functions¶
-
sensor_humiture_handle_t
humiture_create
(bus_handle_t bus, int id)¶ Create a humiture/temperature/humidity sensor instance. Same series’ sensor or sensor with same address can only be created once.
- Return
sensor_humiture_handle_t return humiture sensor handle if succeed, return NULL if create failed.
- Parameters
bus
: i2c bus handle the sensor attached toid
: id declared in humiture_id_t
-
esp_err_t
humiture_delete
(sensor_humiture_handle_t *sensor)¶ Delete and release the sensor resource.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: point to humiture sensor handle, will set to NULL if delete succeed.
-
esp_err_t
humiture_test
(sensor_humiture_handle_t sensor)¶ Test if sensor is active.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: humiture sensor handle to operate
-
esp_err_t
humiture_acquire_humidity
(sensor_humiture_handle_t sensor, float *humidity)¶ Acquire humiture sensor relative humidity result one time.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: humiture sensor handle to operate.humidity
: result data (unit:percentage)
-
esp_err_t
humiture_acquire_temperature
(sensor_humiture_handle_t sensor, float *sensor_data)¶ Acquire humiture sensor temperature result one time.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: humiture sensor handle to operate.sensor_data
: result data (unit:dCelsius)
-
esp_err_t
humiture_sleep
(sensor_humiture_handle_t sensor)¶ Set sensor to sleep mode.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: humiture sensor handle to operate
-
esp_err_t
humiture_wakeup
(sensor_humiture_handle_t sensor)¶ Wakeup sensor from sleep mode.
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
- Parameters
sensor
: humiture sensor handle to operate
-
esp_err_t
humiture_acquire
(sensor_humiture_handle_t sensor, sensor_data_group_t *data_group)¶ acquire a group of sensor data
- Return
esp_err_t
ESP_OK Success
ESP_FAIL Fail
- Parameters
sensor
: humiture sensor handle to operatedata_group
: acquired data
-
esp_err_t
humiture_control
(sensor_humiture_handle_t sensor, sensor_command_t cmd, void *args)¶ control sensor mode with control commands and args
- Parameters
sensor
: humiture sensor handle to operatecmd
: control commands detailed in sensor_command_targs
: control commands argsESP_OK Success
ESP_FAIL Fail
ESP_ERR_NOT_SUPPORTED Function not supported on this sensor
Type Definitions¶
-
typedef void *
sensor_humiture_handle_t
¶ humiture sensor handle