GrovePi v0.3.2 GrovePi.DHT11 View Source

Listen for events from a GrovePi DHT (Digital Humidity and Temparature) sensor. This module is configured for the DHT11, the blue one, that comes with the GrovePi+ Starter Kit. There is only one type of event by default; :changed. When registering for an event the DHT11 will send a message in the form of {pin, :changed, %{temp: 11.3, humidity: 45.5} with the temp and humidty being floats. The GrovePi.DHT11 module works by polling the pin that you have registered to a DHT sensor.

Example usage:

iex> {:ok, dht} = GrovePi.DHT11.start_link(7)
:ok
iex> GrovePi.DHT11.subscribe(7, :changed)
:ok

The GrovePi.DHT11.DefaultTrigger is written so when the value of the either the temp or humidity changes, the subscribed process will receive a message in the form of {pid, :changed, %{temp: 11.3, humidity: 45.5}. The message should be received using GenServer handle_info/2.

For example:

def handle_info({_pid, :changed, %{temp: temp, humidity: humidity}}, state) do
  # do something with temp and/or humidity
  {:noreply, state}
end

Link to this section Summary

Link to this section Functions

Link to this function change_polling(pin, interval, prefix \\ Default) View Source
change_polling(GrovePi.pin, integer, atom) :: :ok

Stops the current scheduled polling event and starts a new one with the new interval.

Link to this function read(pin, prefix \\ Default) View Source
read(GrovePi.pin, atom) :: Digital.level

Callback implementation for GrovePi.Poller.read_value/2.

Link to this function start_link(pin, opts \\ []) View Source

Options

  • :poll_interval - The time in ms between polling for state.i If set to 0 polling will be turned off. Default: 100
  • :trigger - This is used to pass in a trigger to use for triggering events. See specific poller for defaults
  • :trigger_opts - This is used to pass options to a trigger init1. The default is []
Link to this function stop_polling(pin, prefix \\ Default) View Source
stop_polling(GrovePi.pin, atom) :: :ok

Stops polling immediately

Link to this function subscribe(pin, event, prefix \\ Default) View Source
subscribe(GrovePi.pin, GrovePi.Trigger.event, atom) ::
  {:ok, pid} |
  {:error, {:already_registered, pid}}