dht

package
v2.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 11, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HostInit

func HostInit() error

HostInit calls periph.io host.Init(). This needs to be done before DHT can be used.

Types

type DHT

type DHT struct {
	// contains filtered or unexported fields
}

DHT struct to interface with the sensor. Call NewDHT to create a new one.

func NewDHT

func NewDHT(pinName string, temperatureUnit TemperatureUnit, sensorType string) (*DHT, error)

NewDHT to create a new DHT struct. sensorType is dht11 for DHT11, anything else for AM2302 / DHT22.

func (*DHT) Read

func (dht *DHT) Read() (humidity float64, temperature float64, err error)

Read reads the sensor once, returing humidity and temperature, or an error. Note that Read will sleep for at least 2 seconds between last call. Each reads error adds a half second to sleep time to max of 30 seconds.

func (*DHT) ReadBackground

func (dht *DHT) ReadBackground(humidity *float64, temperature *float64, sleepDuration time.Duration, stop chan struct{}, stopped chan struct{})

ReadBackground it meant to be run in the background, run as a Goroutine. sleepDuration is how long it will try to sleep between reads. If there is ongoing read errors there will be no notice except that the values will not be updated. Will continue to read sensor until stop is closed. After it has been stopped, the stopped chan will be closed. Will panic if humidity, temperature, or stop are nil.

func (*DHT) ReadRetry

func (dht *DHT) ReadRetry(maxRetries int) (humidity float64, temperature float64, err error)

ReadRetry will call Read until there is no errors or the maxRetries is hit. Suggest maxRetries to be set around 11.

type TemperatureUnit

type TemperatureUnit int

TemperatureUnit is the temperature unit wanted, either Celsius or Fahrenheit

const (
	// Celsius temperature unit
	Celsius TemperatureUnit = iota
	// Fahrenheit temperature unit
	Fahrenheit
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL