From a76170ccffe72d04f1bd47016a75811b37b9ec13 Mon Sep 17 00:00:00 2001 From: "H.Plato" Date: Sun, 18 Sep 2022 15:15:11 -0600 Subject: [PATCH] A more robust method to test if RRD modules are installed --- lib/Tasmota_HTTP_Item.pm | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Tasmota_HTTP_Item.pm b/lib/Tasmota_HTTP_Item.pm index 013dc1be0..a3b5056d5 100755 --- a/lib/Tasmota_HTTP_Item.pm +++ b/lib/Tasmota_HTTP_Item.pm @@ -463,10 +463,18 @@ sub new { $self->{RRD} = 0; $self->{RRD} = 1 if ( $options =~ m/rrd/i ); + + eval { + require RRD::Simple; + require RRDs; + }; + if ($@) { + &main::print_log("[Tasmota_HTTP::Switch_PowerMon] Warning, RRD specified but RRD::Simple and/or RRDs are not found. Disabling RRD functionality"); + $self->{RRD} = 0; + } if ($self->{RRD}) { - use RRD::Simple; - use RRDs; + mkdir($$::config_parms{data_dir} . "/rrd") unless (-d $::config_parms{data_dir} . "/rrd"); $self->set_rrd($::config_parms{data_dir} . "/rrd/" . $self->{address} . ".rrd","power,current"); unless ( -e $self->get_rrd()) {