The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

    Device::WebIO::Dancer - REST API on top of Device::WebIO

DESCRIPTION

Provides a REST-based interface for controlling Device::WebIO over HTTP. The API is in line with the WebIOPi API (https://code.google.com/p/webiopi/).

DEPLOYMENT

Apache2/mod_perl2

Set the root Location directive in your VirtualHost to point the PSGI script you want:

        <Location />
                SetHandler perl-script
                PerlResponseHandler Plack::Handler::Apache2
                PerlSetVar psgi_app /var/www/raspberrypi.psgi
        </Location>

Create the raspberrypi.psgi file pointed to above:

    use Dancer;
    use Device::WebIO::Dancer;
    use Device::WebIO;
    use Device::WebIO::RaspberryPi;
    use Plack::Builder;

    my $webio = Device::WebIO->new;
    my $rpi = Device::WebIO::RaspberryPi->new;
    $webio->register( 'rpi', $rpi );

    Device::WebIO::Dancer::init( $webio, 'rpi' );
     
    builder {
        dance;
    };

If you would like to use the still image interface on the Raspberry Pi, add the user www-data to the group video.

Copy the public/ directory from the Device::WebIO::Dancer distribution into its own directory in your VirtualHost's docroot. If you copied it to app/, then add to your VirtualHost config:

        <Location /app>
                SetHandler None
        </Location>

This needs to come after the "<Location />" section above.

If you're using Device::WebIO::RaspberryPi, note that the underlying Wiring library needs to be init'd before the Apache startup drops its root privileges. To make sure you do this, create a mod_perl_config.pl file in your Apache2 config dir:

    use Device::WebIO::RaspberryPi;
    my $rpi = Device::WebIO::RaspberryPi->new;
    1;

And run that from the Apache2 config with:

    PerlConfigRequire /etc/apache2/mod_perl_config.pl

Finally, load up the modules you need in mod_perl_post_config.pl:

    use Device::WebIO;
    use Device::WebIO::RaspberryPi;
    use Device::WebIO::Dancer;
    1;

And call that with:

    PerlPostConfigRequire /etc/apache2/mod_perl_post_config.pl

At this point, you should be able to startup Apache. Calling http://example.com/* should get you a JSON dump of the pins. Calling http://example.com/app/app/gpio-header/index.html should get you a layout of the pins with their current values.

LICENSE

Copyright (c) 2014 Timm Murray All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice, this list of 
      conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice, this list of
      conditions and the following disclaimer in the documentation and/or other materials 
      provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 561:

=cut found outside a pod block. Skipping to next block.