NAME
RPi::PIGPIO::Device::DHT22 - Read temperature and humidity from a DHT22 sensor
DESCRIPTION
Uses the pigpiod to read temperature and humidity from a local or remote DHT22 sensor
SYNOPSIS
use RPi::PIGPIO;
use RPi::PIGPIO::Device::DHT22;
my $pi = RPi::PIGPIO->connect('192.168.1.10');
my $dht22 = RPi::PIGPIO::Device::DHT22->new($pi,4);
$dht22->trigger(); #trigger a read
print "Temperature : ".$dht22->temperature."\n";
print "Humidity : ".$dht22->humidity."\n";
METHODS
new
Create a new object
Usage:
my $dht22 = RPi::PIGPIO::Device::DHT22->new($pi,$gpio);
Arguments:
$pi - an instance of RPi::PIGPIO
$gpio - GPIO number to which the sensor is connected
temperature
Return the last read temperature
humidity
Return the last read humidity
last_read
When was the last read done (unix timestamp)
trigger
Trigger a new read from the sensor.
Note: The read is not imediate, it's done asyncronyous. After calling trigger you shoud sleep for a second and than you should get the values received by calling temperature() and humidity() .
You should always chek the timestamp of the last read to make sure we were actually able to read the data after you called trigger()
DHT22 can freeze if you call trigger too often. Don't call it more than every 3 seconds and you should be fine
PRIVATE METHODS
receive_data
Callback method used to read and put together the data received from the sensor
reset_readings
Reset internal counters that help us put together data received from the sensor