diff --git a/CHANGED b/CHANGED
index f1e173859..d5a6f7be0 100644
--- a/CHANGED
+++ b/CHANGED
@@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it.
+ - feature: 93_DbLog: V2.17.1, optional UTF-8 support for MySQL database
+ (additional parameter in db.conf neccesary for activation)
- feature: YAMAHA_AVR: new set commands / readings to control HDMI outputs
(only for models with two HDMI outputs)
- featere: exclude_from_update can check the source too (Forum #73275)
diff --git a/FHEM/93_DbLog.pm b/FHEM/93_DbLog.pm
index f18dd3a4a..a67ec0140 100644
--- a/FHEM/93_DbLog.pm
+++ b/FHEM/93_DbLog.pm
@@ -10,12 +10,14 @@
#
# reduceLog() created by Claudiu Schuster (rapster)
#
-# redesigned 2017 by DS_Starter with credits by
+# redesigned 2016/2017 by DS_Starter with credits by
# JoeAllb, DeeSpe
#
############################################################################################################################################
# Versions History done by DS_Starter & DeeSPe:
#
+# 2.17.1 17.06.2017 fix log-entries "utf8 enabled" if SVG's called, commandref revised, enable UTF8 for DbLog_get
+# 2.17.0 15.06.2017 enable UTF8 for MySQL (entry in configuration file necessary)
# 2.16.11 03.06.2017 execmemcache changed for SQLite avoid logging if deleteOldDaysNbl or reduceLogNbL is running
# 2.16.10 15.05.2017 commandref revised
# 2.16.9.1 11.05.2017 set userCommand changed -
@@ -128,8 +130,9 @@ eval "use DBI;1" or my $DbLogMMDBI = "DBI";
use Data::Dumper;
use Blocking;
use Time::HiRes qw(gettimeofday tv_interval);
+use Encode qw(encode_utf8);
-my $DbLogVersion = "2.16.11";
+my $DbLogVersion = "2.17.1";
my %columns = ("DEVICE" => 64,
"TYPE" => 64,
@@ -230,7 +233,7 @@ sub DbLog_Define($@)
$hash->{cache}{index} = 0;
# read configuration data
- my $ret = _DbLog_readCfg($hash);
+ my $ret = DbLog_readCfg($hash);
return $ret if ($ret); # return on error while reading configuration
# set used COLUMNS
@@ -490,7 +493,7 @@ sub DbLog_Set($@) {
$dbh->commit() if(!$dbh->{AutoCommit});
$dbh->disconnect();
}
- $ret = _DbLog_readCfg($hash);
+ $ret = DbLog_readCfg($hash);
return $ret if $ret;
DbLog_ConnectPush($hash);
$ret = "Rereadcfg executed.";
@@ -1653,6 +1656,7 @@ sub DbLog_PushAsync(@) {
my $dbpassword = $attr{"sec$name"}{secret};
my $DbLogType = AttrVal($name, "DbLogType", "History");
my $supk = AttrVal($name, "noSupportPK", 0);
+ my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
my $errorh = 0;
my $errorc = 0;
my $error = 0;
@@ -1666,7 +1670,7 @@ sub DbLog_PushAsync(@) {
# Background-Startzeit
my $bst = [gettimeofday];
- eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1 });};
+ eval {$dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, RaiseError => 1, mysql_enable_utf8 => $utf8 });};
if ($@) {
$error = encode_base64($@,"");
@@ -2049,7 +2053,7 @@ sub DbLog_implode_datetime($$$$$$) {
###################################################################################
# Verbindungen zur DB aufbauen
###################################################################################
-sub _DbLog_readCfg($){
+sub DbLog_readCfg($){
my ($hash)= @_;
my $name = $hash->{NAME};
@@ -2082,6 +2086,11 @@ sub _DbLog_readCfg($){
Log3 $hash->{NAME}, 3, "Only Mysql, Postgresql, Oracle, SQLite are fully supported.";
Log3 $hash->{NAME}, 3, "It may cause SQL-Erros during generating plots.";
}
+
+ if($hash->{DBMODEL} eq "MYSQL") {
+ $hash->{UTF8} = defined($dbconfig{utf8})?$dbconfig{utf8}:0;
+ }
+
return;
}
@@ -2092,9 +2101,10 @@ sub DbLog_ConnectPush($;$$) {
my $dbconn = $hash->{dbconn};
my $dbuser = $hash->{dbuser};
my $dbpassword = $attr{"sec$name"}{secret};
+ my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
Log3 $hash->{NAME}, 3, "DbLog $name: Creating Push-Handle to database $dbconn with user $dbuser" if(!$get);
- my $dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0 });
+ my $dbhp = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, mysql_enable_utf8 => $utf8 });
if(!$dbhp) {
RemoveInternalTimer($hash, "DbLog_ConnectPush");
@@ -2106,6 +2116,7 @@ sub DbLog_ConnectPush($;$$) {
}
Log3 $hash->{NAME}, 3, "DbLog $name: Push-Handle to db $dbconn created" if(!$get);
+ Log3 $hash->{NAME}, 3, "DbLog $name: UTF8 support enabled" if($utf8 && $hash->{DBMODEL} eq "MYSQL" && !$get);
readingsSingleUpdate($hash, 'state', 'connected', 1) if(!$get);
$hash->{DBHP}= $dbhp;
@@ -2127,9 +2138,10 @@ sub DbLog_ConnectNewDBH($) {
my $dbconn = $hash->{dbconn};
my $dbuser = $hash->{dbuser};
my $dbpassword = $attr{"sec$name"}{secret};
+ my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
my $dbh;
- eval { $dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0 }); };
+ eval { $dbh = DBI->connect("dbi:$dbconn", $dbuser, $dbpassword, { PrintError => 0, mysql_enable_utf8 => $utf8 }); };
if($@) {
Log3($name, 2, "DbLog $name: - $@");
@@ -2191,11 +2203,10 @@ sub DbLog_ExecSQL1($$$)
# outfile: [-|ALL|INT|WEBCHART]
#
################################################################
-sub
-DbLog_Get($@)
-{
+sub DbLog_Get($@) {
my ($hash, @a) = @_;
my $name = $hash->{NAME};
+ my $utf8 = defined($hash->{UTF8})?$hash->{UTF8}:0;
my $dbh;
return dbReadings($hash,@a) if $a[1] =~ m/^Readings/;
@@ -2701,6 +2712,8 @@ DbLog_Get($@)
return @ReturnArray;
} else {
+ $retval = Encode::encode_utf8($retval) if($utf8);
+ # Log3 $name, 5, "DbLog $name -> Result of get:\n$retval";
return $retval;
}
}
@@ -4035,8 +4048,50 @@ sub checkUsePK ($$){
Log events to a database. The database connection is defined in
- <configfilename>
(see sample configuration file
- contrib/dblog/db.conf
). The configuration is stored in a separate file
+ <configfilename>
+
+ In contrib/dblog
an example configuration and scripts to create needed tables in the
+ different databases are provided.
+
+ The configuration file should be copied e.g. to /opt/fhem and has the following structure you have to customize
+ suitable to your conditions (decomment the appropriate raws and adjust it):
+
+
+ #################################################################################### + # database configuration file + # + ## for MySQL + #################################################################################### + #%dbconfig= ( + # connection => "mysql:database=fhem;host=db;port=3306", + # user => "fhemuser", + # password => "fhempassword", + # # optional enable(1) / disable(0) UTF-8 support (at least V 4.042 is necessary) + # utf8 => 1, + #); + #################################################################################### + # + ## for PostgreSQL + #################################################################################### + #%dbconfig= ( + # connection => "Pg:database=fhem;host=localhost", + # user => "fhemuser", + # password => "fhempassword" + #); + #################################################################################### + # + ## for SQLite (username and password stay empty for SQLite) + #################################################################################### + #%dbconfig= ( + # connection => "SQLite:dbname=/opt/fhem/fhem.db", + # user => "", + # password => "" + #); + #################################################################################### ++
get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature
get myDbLog current ALL - - %:temperature
get myDbLog - - 2012-11-10_10 2012-11-10_20 KS300:temperature::int1
get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature
<configfilename>
. (Vergleiche
- Beipspielkonfigurationsdatei in contrib/dblog/db.conf
).<configfilename>
. contrib/dblog
sind eine Beispielkonfiguation und Scripts zum Anlegen der benötigten Tabellen
+ der verschiedenen Datenbanktypen bereitgestellt. + #################################################################################### + # database configuration file + # + ## for MySQL + #################################################################################### + #%dbconfig= ( + # connection => "mysql:database=fhem;host=db;port=3306", + # user => "fhemuser", + # password => "fhempassword", + # # optional enable(1) / disable(0) UTF-8 support (at least V 4.042 is necessary) + # utf8 => 1, + #); + #################################################################################### + # + ## for PostgreSQL + #################################################################################### + #%dbconfig= ( + # connection => "Pg:database=fhem;host=localhost", + # user => "fhemuser", + # password => "fhempassword" + #); + #################################################################################### + # + ## for SQLite (username and password stay empty for SQLite) + #################################################################################### + #%dbconfig= ( + # connection => "SQLite:dbname=/opt/fhem/fhem.db", + # user => "", + # password => "" + #); + #################################################################################### ++
get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature
get myDbLog current ALL - - %:temperature
get myDbLog current ALL - - %:temperature
get myDbLog - - 2012-11-10_10 2012-11-10_20 KS300:temperature::int1
get myDbLog - - 2012-11-10_10 2012-11-10_20 KS300:temperature::int1
get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature
get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature KS300:rain::delta-h KS300:rain::delta-d
get myDbLog - - 2012-11-10 2012-11-20 MyFS20:data:::$val=~s/(on|off).*/$1eq"on"?1:0/eg
get myDbLog - - 2012-11-10 2012-11-20 Bodenfeuchte:data:::$val=~s/.*B:\s([-\.\d]+).*/$1/eg
get myDbLog - all 2012-11-10 2012-11-20 KS300:temperature
get myDbLog - - 2012-11-10 2012-11-20 KS300:temperature KS300:rain::delta-h KS300:rain::delta-d
get myDbLog - - 2012-11-10 2012-11-20 MyFS20:data:::$val=~s/(on|off).*/$1eq"on"?1:0/eg
get myDbLog - - 2012-11-10 2012-11-20 Bodenfeuchte:data:::$val=~s/.*B:\s([-\.\d]+).*/$1/eg
"A: 49.527 % B: 66.647 % C: 9.797 % D: 0.097 V"
2012-11-20_10:23:54 66.647
get DbLog - - 2013-05-26 2013-05-28 Pumpe:data::delta-ts:$val=~s/on/hide/
get DbLog - - 2013-05-26 2013-05-28 Pumpe:data::delta-ts:$val=~s/on/hide/
-
zu setzen.webchart
zu setzen um die Charting Get Funktion zu nutzen.
YYYY-MM-DD_HH24:MI:SS
getreadings
um für ein bestimmtes device alle Readings zu erhaltengetdevices
um alle verfügbaren devices zu erhaltenmonthstats
um Statistiken für einen Wert (yaxis) für einen Monat abzufragen.yearstats
um Statistiken für einen Wert (yaxis) für ein Jahr abzufragen.get logdb - webchart "" "" "" getcharts
get logdb - webchart "" "" "" getdevices
get logdb - webchart "" "" "" getdevices
get logdb - webchart "" "" ESA2000_LED_011e getreadings
get logdb - webchart "" "" ESA2000_LED_011e getreadings
get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e timerange TIMESTAMP day_kwh
get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e timerange TIMESTAMP day_kwh
[{'TIMESTAMP':'2013-02-11 00:10:10','VALUE':'0.22431388090756'},{'TIMESTAMP'.....}]
get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e savechart TIMESTAMP day_kwh tageskwh
get logdb - webchart 2013-02-11_00:00:00 2013-02-12_00:00:00 ESA2000_LED_011e savechart TIMESTAMP day_kwh tageskwh
get logdb - webchart "" "" "" deletechart "" "" 7
get logdb - webchart "" "" "" deletechart "" "" 7