Temperature API

The temperature API abstracts away the need to specify a specific sensor’s init/read/write/etc functions in order to gather temperature and humidity data.

In order to use this API, the sensors object must be present in the project’s config.json file, along with one of the supported child sensors. An example is given below:

{
    "sensors": {
        "htu21d": {
            "i2c_bus": "K_I2C1"
        }
    }
}

See the Kubos Sensor Example for an example of how to use this sensor.

KSensorStatus k_initialize_temperature_sensor(void)

Setup the temperature sensor interface and any related sensors.

Return
KSensorStatus - SENSOR_OK on success or SENSOR_WRITE_ERROR on error

KSensorStatus k_get_temperature(float *temp)

Reads back temperature data from related sensor.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_ERROR, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • temp: pointer to temperature in celsius (-40.0 to 125.0)

KSensorStatus k_get_humidity(float *hum)

Reads back humidity data from related sensor.

Return
KSensorStatus - SENSOR_OK on success, SENSOR_ERROR, SENSOR_READ_ERROR, SENSOR_WRITE_ERROR on error
Parameters
  • hum: pointer to relative humidity in percentage (0.0 - 100.0)