Hauptmenü

DbLog Module

Begonnen von sijones, 27 Dezember 2013, 14:14:58

Vorheriges Thema - Nächstes Thema

sijones

Hi everyone,

I am trying to use the charting frontend, i have followed the example given, wrote a test script to make sure perl can connect to a database and it all works fine, but i cannot get the DbLog module to do the connection.

To me, looking at the code there is nothing copying the data from the db.conf file to the dbconfig varible, but am no perl programmer so i might be missing it!

This is my db.conf file:

%dbconfig= (
        connection => "mysql:database=fhem;host=10.10.10.2;port=3306",
        user => "fhemuser"
        password => "fhempassword",
);

and my fhem.cfg line
define myDbLog DbLog /opt/fhem/db.conf .*:.*

Could someone help me out please!

Thank you!

sijones

the error i get is:

Use of uninitialized value $dbconn in pattern match (m//) at ./FHEM/93_DbLog.pm line 522.
Use of uninitialized value $dbconn in pattern match (m//) at ./FHEM/93_DbLog.pm line 524.
Use of uninitialized value $dbconn in pattern match (m//) at ./FHEM/93_DbLog.pm line 526.
Use of uninitialized value $dbconn in pattern match (m//) at ./FHEM/93_DbLog.pm line 528.
Use of uninitialized value $dbconn in concatenation (.) or string at ./FHEM/93_DbLog.pm line 537.
Use of uninitialized value $dbuser in concatenation (.) or string at ./FHEM/93_DbLog.pm line 537.
Use of uninitialized value $dbconn in concatenation (.) or string at ./FHEM/93_DbLog.pm line 538.
Can't connect to data source 'dbi:' because I can't work out what driver to use (it doesn't seem to contain a 'dbi:driver:' prefix and the DBI_DRIVER env var is not set) at ./FHEM/93_DbLog.pm line 538

ph1959de

I've got a working dbLog configuration with the following difference: my entry in db.conf looks like this

connection => "SQLite:dbname=/opt/fhem/fhem.db",

because

  • I use SQLite as a database (you seem to use mysql?)
  • my database is running on the same system (BeagleBone) as Fhem, thus I do not specify any host/port parameters

Do the detected differences fit your system setup?

Peter
Aktives Mitglied des FHEM e.V. | Moderator im Forenbereich "Wiki"

sijones

Hi,

Thanks for the reply, i don't want to use sqlite as i have a server running 24/7 that has mysql and has lots of storage space so i can keep a long history of event data.

When looking at the code:

my $dbconn= $dbconfig{connection};
  my $dbuser= $dbconfig{user};
  my $dbpassword= $dbconfig{password};

these lines here don't seem to assign anything from dbconfig, which further down leads to the if else taking the last case of else...

  #check the database model
  if($dbconn =~ m/pg:/i) {
    $hash->{DBMODEL}="POSTGRESQL";
  } elsif ($dbconn =~ m/mysql:/i) {
    $hash->{DBMODEL}="MYSQL";
  } elsif ($dbconn =~ m/oracle:/i) {
    $hash->{DBMODEL}="ORACLE";
  } elsif ($dbconn =~ m/sqlite:/i) {
    $hash->{DBMODEL}="SQLITE";
  } else {
    $hash->{DBMODEL}="unknown";
    Log3 $hash->{NAME}, 3, "Unknown dbmodel type in configuration file $configfilename.";
    Log3 $hash->{NAME}, 3, "Only Mysql, Postgresql, Oracle, SQLite are fully supported.";
    Log3 $hash->{NAME}, 3, "It may cause SQL-Erros during generating plots.";
  }

wish i knew more about Perl!

ChrisD

The variables are assigned in the lines preceding the ones you mentioned:

  my $configfilename= $hash->{CONFIGURATION};
  if(!open(CONFIG, $configfilename)) {
    Log3 $hash->{NAME}, 1, "Cannot open database configuration file $configfilename.";
    return 0; }
  my @config=<CONFIG>;
  close(CONFIG);

  my %dbconfig;
  eval join("", @config);


Your db.conf file doesn't work because there is a comma missing on the line
Zitatuser => "fhemuser"

Regards,

ChrisD

sijones

Thanks ChrisD,

How bloody stupid of me! the old saying, can't see the wood for the trees!