Delving the depths of computing,
hoping not to get eaten by a wumpus

By Timm Murray

Device::WebIO::RaspberryPi 0.900, now with AnyEvent and RPi::WiringPi backend


Device::WebIO::RaspberryPi 0.900 has been released. The big changes are to change the backend from HiPi to RPi::WiringPi, as well as put in a new input event system based on AnyEvent. There’s also some slight updates to interrupt handling in Device::WebIO in version 0.022 to support this.

It works by having a condvar with a subref. You can get the pin number and its value out of $cv->recv:

use v5.14;
use Device::WebIO;
use Device::WebIO::RaspberryPi;
use AnyEvent;

use constant INPUT_PIN  => 2;

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

my $input_cv = AnyEvent->condvar;
$input_cv->cb( sub {
    my ($cv) = @_;
    my ($pin, $setting) = $cv->recv;
    say "Pin $pin set to $setting";
$webio->set_anyevent_condvar( 'rpi', INPUT_PIN, $input_cv );

say "Waiting for input";
my $cv = AE::cv;

This is one part of a series of updates to support an upcoming Device::WebIO::MQTT. The original versions of the Device::WebIO family were meant to an HTTP interface (like the one in Device::WebIO::Dancer). Where HTTP pulls data, MQTT is push. The new AnyEvent system should integrate easily with AnyEvent::MQTT.

MQTT is also part of our stretch goals for the Raspberry Pi Perl eBook. Don’t worry though–I’ll be working on Device::WebIO::MQTT regardless of the funding level on the book.

Copyright © 2024 Timm Murray

Opinions expressed are solely my own and do not express the views or opinions of my employer.