NAME

    RPi::DHT11 - Fetch the temperature/humidity from the DHT11 hygrometer
    sensor on Raspberry Pi

SYNOPSIS

        use RPi::DHT11;
    
        my $pin = 26;
    
        my $env = RPi::DHT11->new($pin);
    
        my $temp     = $env->temp;
        my $humidity = $env->humidity;

DESCRIPTION

    This module is an interface to the DHT11 temperature/humidity sensor
    when connected to a Raspberry Pi's GPIO pins.

    Due to the near-realtime access requirements of reading the input pin
    of the sensor, the core of this module is written in XS (C).

    This module requires the wiringPi <http://wiringpi.com/> library to be
    installed, and uses WiringPi's GPIO pin numbering scheme (see gpio
    readall at the command line).

METHODS

 new($pin)

    Parameters:

  $pin

    Mandatory. Pin number for the DHT11 sensor's DATA pin (values are
    0-40).

 temp($f)

    Fetches the current temperature (in Celcius).

    Returns an integer of the temperature, in celcius by default.

    Parameters:

  $f

    Send in the string char 'f' to receive the temp in Farenheit.

 humidity

    Fetches the current humidity.

    Returns the humidity as either an integer of the current humidity
    level.

 cleanup

    Returns the pin back to default state if it's not already. Called
    automatically by DESTROY().

C TYPEDEFS

 EnvData

    Stores the temperature and humidity float values.

        typedef struct env_data {
            int temp;
            int humidity;
        } EnvData;

C FUNCTIONS

 c_temp

        int c_temp(int spin);

    Called by the temp() method.

 c_humidity

        int c_humidity(int spin);

    Called by the humidity() method.

 c_cleanup

        int c_cleanup(int spin, int tpin, int hpin);

    Called by the cleanup() method, and is always called upon DESTROY().

 read_env()

        EnvData read_env(int spin);

    Not available to Perl.

    Polls the pin in a loop until valid data is fetched, then returns an
    EnvData struct containing the temp and humidity float values.

    If for any reason the poll of the DHT11 sensor fails (eg: the CRC is
    incorrect for either temp or humidity), we will loop and block until
    valid data is retrieved.

 noboard_test()

        bool noboard_test();

    Checks whether the RDE_NOBOARD_TEST environment variable is set to a
    true value. Returns true if so, and false if not. This bool is used for
    testing purposes only.

    Not available to Perl.

 sanity()

        void sanity();

    If we're on a system that isn't a Raspberry Pi, things break. We call
    this in new(), and if sanity checks fail, we exit (unless in
    RDE_NOBOARD_TEST environment variable is set to true).

    Called only from the new() method.

ENVIRONMENT VARIABLES

    There are a couple of env vars to help prototype and run unit tests
    when not on a RPi board.

 RDE_HAS_BOARD

    Set to 1 to tell the unit test runner that we're on a Pi.

 RDE_NOBOARD_TEST

    Set to 1 to tell the system we're not on a Pi. Most methods/functions
    will return default (ie. non-live) data when in this mode.

SEE ALSO

    - wiringPi <http://wiringpi.com/>

AUTHOR

    Steve Bertrand, <steveb@cpan.org<gt>

LICENSE AND COPYRIGHT

    Copyright 2016 Steve Bertrand.

    This program is free software; you can redistribute it and/or modify it
    under the terms of either: the GNU General Public License as published
    by the Free Software Foundation; or the Artistic License.

    See http://dev.perl.org/licenses/ for more information.

