温湿度传感器

[English]

温湿度传感器包括温度传感器、湿度传感器和兼具两种功能的传感器,可用于智慧人居、智慧农场、智能工厂等场景下的环境温湿度检测。

已适配列表

名称

功能

总线

供应商

规格书

硬件抽象层

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 to

  • id: 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 operate

  • data_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 operate

  • cmd: control commands detailed in sensor_command_t

  • args: control commands args

    • ESP_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

Enumerations

enum humiture_id_t

humiture sensor id, used for humiture_create

Values:

SHT3X_ID = 0x01

sht3x humiture sensor id

HTS221_ID

hts221 humiture sensor id

HUMITURE_MAX_ID

max humiture sensor id