Humidity and Temperature Sensor

[中文]

The humidity and temperature sensor can be used as a temperature sensor, a humidity sensor or a sensor with both functions. It is mainly used for environmental temperature and humidity detections in smart home, smart farm and smart factory applications.

Adapted Products

Name

Function

Bus

Vendor

Datasheet

HAL

HDC2010

Temperature, Humidity

I2C

TI

Datasheet

HTS221

Temperature, Humidity

I2C

ST

Datasheet

SHT3X

Temperature, Humidity

I2C

Sensirion

Datasheet

MVH3004D

Temperature, Humidity

I2C

API Reference

The following APIs have implemented hardware abstraction on the humidity and temperature sensor. Users can call the code from this layer directly to write a sensor application, or use the sensor interface in sensor_hub for easier development.

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