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

HDC2010 Datasheet

HTS221

Temperature, Humidity

I2C

ST

HTS221 Datasheet

SHT3X

Temperature, Humidity

I2C

Sensirion

SHT3X 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.

Parameters
  • bus – i2c bus handle the sensor attached to

  • id – id declared in humiture_id_t

Returns

sensor_humiture_handle_t return humiture sensor handle if succeed, return NULL if create failed.

esp_err_t humiture_delete(sensor_humiture_handle_t *sensor)

Delete and release the sensor resource.

Parameters

sensor – point to humiture sensor handle, will set to NULL if delete succeed.

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t humiture_test(sensor_humiture_handle_t sensor)

Test if sensor is active.

Parameters

sensor – humiture sensor handle to operate

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

esp_err_t humiture_acquire_humidity(sensor_humiture_handle_t sensor, float *humidity)

Acquire humiture sensor relative humidity result one time.

Parameters
  • sensor – humiture sensor handle to operate.

  • humidity – result data (unit:percentage)

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t humiture_acquire_temperature(sensor_humiture_handle_t sensor, float *sensor_data)

Acquire humiture sensor temperature result one time.

Parameters
  • sensor – humiture sensor handle to operate.

  • sensor_data – result data (unit:dCelsius)

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t humiture_sleep(sensor_humiture_handle_t sensor)

Set sensor to sleep mode.

Parameters

sensor – humiture sensor handle to operate

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t humiture_wakeup(sensor_humiture_handle_t sensor)

Wakeup sensor from sleep mode.

Parameters

sensor – humiture sensor handle to operate

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

  • ESP_ERR_NOT_SUPPORTED Function not supported on this sensor

esp_err_t humiture_acquire(sensor_humiture_handle_t sensor, sensor_data_group_t *data_group)

acquire a group of sensor data

Parameters
  • sensor – humiture sensor handle to operate

  • data_group – acquired data

Returns

esp_err_t

  • ESP_OK Success

  • ESP_FAIL Fail

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:

enumerator SHT3X_ID

sht3x humiture sensor id

enumerator HTS221_ID

hts221 humiture sensor id

enumerator HUMITURE_MAX_ID

max humiture sensor id