SHT4X (sht4x v0.3.2)

View Source

Use Sensirion SHT4X humidity and temperature sensors in Elixir

Summary

Types

Compensation callback function

SHT4X GenServer start_link options

How "fresh" is the sample we fetched from the sensor's GenServer?

Functions

Returns a specification to start this module under a supervisor.

Fetches the latest sample from the sensor's GenServer

Return the sensor's serial number

Send a soft reset command to the sensor

Start a new GenServer for interacting with a SHT4X.

Types

compensation_callback()

@type compensation_callback() :: (SHT4X.Measurement.t() -> SHT4X.Measurement.t())

Compensation callback function

option()

@type option() ::
  {:debug, GenServer.debug()}
  | {:name, GenServer.name()}
  | {:timeout, timeout()}
  | {:spawn_opt, [Process.spawn_opt()]}
  | {:hibernate_after, timeout()}
  | {:bus_name, binary()}
  | {:retries, pos_integer()}
  | {:compensation_callback, compensation_callback()}
  | {:measurement_interval, pos_integer()}
  | {:repeatability, :low | :medium | :high}
  | {:stale_threshold, pos_integer()}

SHT4X GenServer start_link options

  • :name - a name for the GenServer
  • :bus_name - which I2C bus to use (e.g., "i2c-1")
  • :retries - the number of retries before failing (defaults to 2 retries)
  • :compensation_callback - a function that takes in a SHT4X.Measurement.t() and returns a potentially modified SHT4X.Measurement.t()
  • :measurement_interval - how often data will be read from the sensor (defaults to 5_000 ms)
  • :repeatability - accuracy of the requested sensor read (:low, :medium, or :high)
  • :stale_threshold - number of milliseconds a sample can remain the current sample before it is marked stale
  • Also accepts all other standard GenServer start_link options

options()

@type options() :: [option()]

quality()

@type quality() :: :fresh | :stale | :unusable | :converging

How "fresh" is the sample we fetched from the sensor's GenServer?

In the event that the sensor fails to report back a measurement during a polling interval, we re-use the last sample. If this continues to happen over a time period that exceeds the :stale_threshold, we mark the re-used "current" sample as stale.

The possible values can be:

  • :fresh - This is a recent sample. See the :stale_threshold.
  • :stale - This is an old sample that should be used with caution.
  • :unusable - This is a default sample when no measurements are available, or, the sensor is giving know bad values (see: https://github.com/elixir-sensors/sht4x/issues/29)
  • :converging - This is optionally set by the temperature compensation algorithm to indicate that it was recently restarted without historic state information and needs more time to give accurate values

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get_sample(sensor_ref)

@spec get_sample(GenServer.server()) :: SHT4X.Measurement.t()

Fetches the latest sample from the sensor's GenServer

This does not cause an on-demand read from the sensor. Check the :quality field for a quick assessment of how much to trust the measurement.

serial_number(sensor_ref)

@spec serial_number(GenServer.server()) :: {:ok, 0..4_294_967_295} | {:error, any()}

Return the sensor's serial number

soft_reset(sensor_ref)

@spec soft_reset(GenServer.server()) :: :ok | {:error, any()}

Send a soft reset command to the sensor

start_link(opts \\ [])

@spec start_link(options()) :: GenServer.on_start()

Start a new GenServer for interacting with a SHT4X.