Documentation ¶
Index ¶
- func ReadDHTxx(sensorType SensorType, pin int, boostPerfFlag bool) (temperature float32, humidity float32, err error)
- func ReadDHTxxWithContextAndRetry(parent context.Context, sensorType SensorType, pin int, boostPerfFlag bool, ...) (temperature float32, humidity float32, retried int, err error)
- func ReadDHTxxWithRetry(sensorType SensorType, pin int, boostPerfFlag bool, retry int) (temperature float32, humidity float32, retried int, err error)
- type Pulse
- type SensorType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadDHTxx ¶
func ReadDHTxx(sensorType SensorType, pin int, boostPerfFlag bool) (temperature float32, humidity float32, err error)
ReadDHTxx send activation request to DHTxx sensor via specific pin. Then decode pulses sent back with asynchronous protocol specific for DHTxx sensors.
Input parameters: 1) sensor type: DHT11, DHT22 (aka AM2302); 2) pin number from GPIO connector to interact with sensor; 3) boost GPIO performance flag should be used for old devices such as Raspberry PI 1 (this will require root privileges).
Return: 1) temperature in Celsius; 2) relative humidity in percent; 3) error if present.
func ReadDHTxxWithContextAndRetry ¶
func ReadDHTxxWithContextAndRetry(parent context.Context, sensorType SensorType, pin int, boostPerfFlag bool, retry int) (temperature float32, humidity float32, retried int, err error)
ReadDHTxxWithContextAndRetry send activation request to DHTxx sensor via specific pin. Then decode pulses sent back with asynchronous protocol specific for DHTxx sensors. Retry n times in case of failure.
Input parameters:
- parent context; could be used to manage life-cycle of sensor request session from code outside;
- sensor type: DHT11, DHT22 (aka AM2302);
- pin number from gadget GPIO to interact with sensor;
- boost GPIO performance flag should be used for old devices such as Raspberry PI 1 (this will require root privileges);
- how many times to retry until success either counter is zeroed.
Return: 1) temperature in Celsius; 2) relative humidity in percent; 3) number of extra retries data from sensor; 4) error if present.
func ReadDHTxxWithRetry ¶
func ReadDHTxxWithRetry(sensorType SensorType, pin int, boostPerfFlag bool, retry int) (temperature float32, humidity float32, retried int, err error)
ReadDHTxxWithRetry send activation request to DHTxx sensor via specific pin. Then decode pulses sent back with asynchronous protocol specific for DHTxx sensors. Retry n times in case of failure.
Input parameters: 1) sensor type: DHT11, DHT22 (aka AM2302); 2) pin number from gadget GPIO to interact with sensor; 3) boost GPIO performance flag should be used for old devices such as Raspberry PI 1 (this will require root privileges); 4) how many times to retry until success either counter is zeroed.
Return: 1) temperature in Celsius; 2) relative humidity in percent; 3) number of extra retries data from sensor; 4) error if present.
Types ¶
type Pulse ¶
Pulse keep pulse signal state with how long it lasted.
type SensorType ¶
type SensorType int
SensorType signify what sensor in use.
const ( // SensorTypeDHT11 is the most popular sensor SensorTypeDHT11 SensorType = iota + 1 // SensorTypeDHT12 is more precise than DHT11 (has scale parts) SensorTypeDHT12 // SensorTypeDHT22 is more expensive and precise than DHT11 SensorTypeDHT22 // SensorTypeAM2302 aka SensorTypeDHT22 SensorTypeAM2302 = SensorTypeDHT22 )
func (SensorType) GetHandshakeDuration ¶
func (v SensorType) GetHandshakeDuration() time.Duration
GetHandshakeDuration specify signal duration necessary to initiate sensor response.
func (SensorType) GetRetryTimeout ¶
func (v SensorType) GetRetryTimeout() time.Duration
GetRetryTimeout return recommended timeout necessary to wait before new round of data exchange.