RPi-SysInfo

 view release on metacpan or  search on metacpan

lib/RPi/SysInfo.pm  view on Meta::CPAN


sub new {
    return bless {}, shift;
}
sub core_temp {
    shift if $_[0] && $_[0] =~ /RPi::/;

    my ($degree) = @_;

    $degree //= 'c';

    my $temp = _core_temp_c();

    return '' if ! defined $temp;

    if ($degree eq 'f' || $degree eq 'F'){
        $temp = ($temp * 1.8) + 32;
    }

    chomp $temp;
    return $temp;
}
sub cpu_percent {
    return _format(cpuPercent());
}
sub gpio_info {
    shift if $_[0] && $_[0] =~ /RPi::/;

    my ($pins) = @_;

    $pins = ! defined $pins
        ? ''
        : join ",", @$pins;

    # raspi-gpio was removed from current Raspberry Pi OS in favour of pinctrl,
    # and never existed for the Pi 5 / RP1. Prefer pinctrl, falling back to
    # raspi-gpio on older systems that still ship it. Both accept the same
    # "get [pin[,pin...]]" invocation.

    my $tool = _gpio_tool();

    return '' if ! defined $tool;

    my $info = _run("$tool get $pins");

    chomp $info;
    return $info;
}
sub file_system {
    my $fs_info = _run('df') . "\n";
    $fs_info .= _slurp('/proc/swaps') // '';
    return $fs_info;
}
sub mem_percent {
    return _format(memPercent());
}
sub network_info {

    # ifconfig (net-tools) is the legacy default, but modern Raspberry Pi OS
    # Lite ships without it, so fall back to `ip addr`, which is always present.
    # Both forms carry inet/inet6 lines.

    my $tool = _net_tool();

    return '' if ! defined $tool;

    my $netinfo = _run($tool);

    chomp $netinfo;
    return $netinfo;
}
sub pi_details {

    my $details;

    $details = "\n"
             . _run('cat /sys/firmware/devicetree/base/model')
             . "\n\n"
             . _run('cat /etc/os-release | head -4')
             . "\n"
             . _run('uname -a')
             . "\n"
             . _run('cat /proc/cpuinfo | tail -3')
             . "Board           : " . pi_model() . "\n"
             . "SoC / RAM       : " . _board_summary() . "\n"
             . "Throttled flag  : " . _run('vcgencmd get_throttled')
             . "Camera          : " . _camera_info() . "\n";

    return $details;
}
sub pi_model {
    shift if $_[0] && $_[0] =~ /RPi::/;

    # Normalized Raspberry Pi marketing name, e.g. "Raspberry Pi 5 Model B Rev
    # 1.1". The devicetree model is authoritative on the Pi 0-5, so prefer it,
    # falling back to a /proc/cpuinfo Revision-code decode, then to 'Unknown'.

    my $model = _slurp('/sys/firmware/devicetree/base/model');

    if (defined $model){
        $model =~ s/\0//g;              # Devicetree strings are NUL-terminated.
        $model =~ s/^\s+|\s+$//g;
        return $model if length $model;
    }

    my $info = _decode_revision(_cpuinfo_field('Revision'));

    return $info->{name} if defined $info->{name};

    return 'Unknown';
}
sub raspi_config {
    my $config = _run('vcgencmd get_config int');
    $config .= _run('vcgencmd get_config str');

    # config.txt moved from /boot to /boot/firmware on Bookworm and later (the
    # old path now holds only a "this file has moved" stub), so resolve the
    # real location before appending the user's non-comment directives.

    my $config_file = _config_file();



( run in 1.608 second using v1.01-cache-2.11-cpan-9581c071862 )