2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

Utils.pm: add getUniqueId, getKeyValue, setKeyValue (Forum #30528)

fheminfo.om: report modules updated from thirdparty sites


git-svn-id: https://svn.fhem.de/fhem/trunk@7346 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
rudolfkoenig 2014-12-29 08:38:52 +00:00
parent 5a79dfdbab
commit 230fecb292
3 changed files with 148 additions and 282 deletions

View File

@ -1,5 +1,7 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # 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. # Do not insert empty lines here, update check depends on it.
- feature: fheminfo: report third-party modules
- feature: 99_Utils.pm: add getUniqueID, getKeyValue, setKeyValue
- feature: SMARTMON: additional parameters for smartctl - feature: SMARTMON: additional parameters for smartctl
- added: 00_HXB / 10_HXBDevice for Hexabus devices - added: 00_HXB / 10_HXBDevice for Hexabus devices
- feature: HUEbridge: added group handling - feature: HUEbridge: added group handling
@ -12,7 +14,8 @@
- feature: HUEDevice: allow ct presets in webCmd - feature: HUEDevice: allow ct presets in webCmd
new subTypes extcolordimer and ctdimer new subTypes extcolordimer and ctdimer
start support for Lightify bulbs start support for Lightify bulbs
- added: SONOS and SONOSPLAYER to support Sonos Multiroom Audiosystems (Reinerlein) - added: SONOS and SONOSPLAYER to support Sonos Multiroom Audiosystems
(Reinerlein)
- change: 64_ESA2000.pm: add batterystate - change: 64_ESA2000.pm: add batterystate
- added: 42_SMARTMON: Frontend to smartctl (maintainer: hexenmeister) - added: 42_SMARTMON: Frontend to smartctl (maintainer: hexenmeister)
- feature: 70_PushNotifier added line break in Messages (xusader) - feature: 70_PushNotifier added line break in Messages (xusader)
@ -22,7 +25,8 @@
- bugfix: FB_CALLMONITOR: fixing not working company numbers - bugfix: FB_CALLMONITOR: fixing not working company numbers
reverse search for search.ch reverse search for search.ch
- bugfix: 70_PushNotifier repair set function (xusader) - bugfix: 70_PushNotifier repair set function (xusader)
- bugfix: PRESENCE: fixing not working timer, when using set [...] statusRequest - bugfix: PRESENCE: fixing not working timer, when using set [...]
statusRequest
- bugfix: FB_CALLMONITOR: fixing reverse search for klicktel.de - bugfix: FB_CALLMONITOR: fixing reverse search for klicktel.de
- feature: new module 52_I2C_MCP342x.pm added (klausw) - feature: new module 52_I2C_MCP342x.pm added (klausw)
- feature: SYSMON: read cpu temp on FritzBox - feature: SYSMON: read cpu temp on FritzBox
@ -36,7 +40,8 @@
- feature: new module 98_logProxy.pm added (justme1968) - feature: new module 98_logProxy.pm added (justme1968)
- change: 66_ECMD: ReadyFn added (fixes issue under Windows) - change: 66_ECMD: ReadyFn added (fixes issue under Windows)
- change: 02_RSS: use a GUID in RSS; urlq source for img command - change: 02_RSS: use a GUID in RSS; urlq source for img command
- feature: 70_PushNotifier improve usebility, configuration without cURL (xusader) - feature: 70_PushNotifier improve usebility, configuration without cURL
(xusader)
- bugfix: SYSMON: prevent empty line im log by userReadings - bugfix: SYSMON: prevent empty line im log by userReadings
- feature: 10_IT empfang (by bjoernh) - feature: 10_IT empfang (by bjoernh)
- bugfix: PRESENCE: fix race condition, when delete disabled attribute and - bugfix: PRESENCE: fix race condition, when delete disabled attribute and
@ -51,26 +56,32 @@
- feature: 15_CUL_EM added attribute maxPeak (arnoaugustin) - feature: 15_CUL_EM added attribute maxPeak (arnoaugustin)
- bugfix: 10_IT changed "setstate" to avoid eventMap errors (arnoaugustin) - bugfix: 10_IT changed "setstate" to avoid eventMap errors (arnoaugustin)
- feature: new module 37_harmony.pm added (justme1968) - feature: new module 37_harmony.pm added (justme1968)
- change: WMBUS: use _ instead of : as readings separator, better support for EnergyCam - change: WMBUS: use _ instead of : as readings separator, better support for
EnergyCam
- feature: new module 23_KOSTALPIKO added (john) - feature: new module 23_KOSTALPIKO added (john)
- feature: new module 98_HourCounter added, 99_UtilsHourCounter.pm added to contrib (john) - feature: new module 98_HourCounter added, 99_UtilsHourCounter.pm added to
contrib (john)
- added: MYSENSORS: connect to serial or Ethernet MySensors Gateway - added: MYSENSORS: connect to serial or Ethernet MySensors Gateway
- added: MYSENSORS_DEVICE: represent a MySensors sensor- or actor node - added: MYSENSORS_DEVICE: represent a MySensors sensor- or actor node
- feature: global ATTR/DELETEATTR/MODIFIED events - feature: global ATTR/DELETEATTR/MODIFIED events
- feature: 55_GDS.pm - attr disable added - feature: 55_GDS.pm - attr disable added
- bugfix: SYSMON: prevent endless loop at startup with 'disable' attribute - bugfix: SYSMON: prevent endless loop at startup with 'disable' attribute
- feature: SYSMON: added FritzBox informations: DSL rate, DSLAM sync time, count of CRC an FEC - feature: SYSMON: added FritzBox informations: DSL rate, DSLAM sync time,
count of CRC an FEC
- bugfix: SYSMON: unwanted characters in dsl info lines - bugfix: SYSMON: unwanted characters in dsl info lines
- change: 57_Calendar: process continuation lines, get/set syntax checks - change: 57_Calendar: process continuation lines, get/set syntax checks
- bugfix: SYSMON: fix availability of cpu/kernel_max - bugfix: SYSMON: fix availability of cpu/kernel_max
- bugfix: SYSMON: numeric check - bugfix: SYSMON: numeric check
- change: 59_Weather: change icons for conditions 31, 34, 36 - change: 59_Weather: change icons for conditions 31, 34, 36
- added: MQTT: connect fhem with mqtt - added: MQTT: connect fhem with mqtt
- added: MQTT_BRIDGE: bidirectional mapping of existing fhem-device to mqtt-topic - added: MQTT_BRIDGE: bidirectional mapping of existing fhem-device to
- added: MQTT_DEVICE: fhem-device that can be controlled by and publishes to mqtt mqtt-topic
- added: MQTT_DEVICE: fhem-device that can be controlled by and publishes to
mqtt
- added: I2C_LCD: module to drive PCF8574T based LCD connected via I2C - added: I2C_LCD: module to drive PCF8574T based LCD connected via I2C
- added: I2C_DS1307: module to read time and date from DS1307 connected by i2c - added: I2C_DS1307: module to read time and date from DS1307 connected by i2c
- added: OWX_ASYNC: asynchronous, non-blocking version of OWX for DS2480, DS9097 and FRM - added: OWX_ASYNC: asynchronous, non-blocking version of OWX for DS2480,
DS9097 and FRM
- feature FRM: work as physical IODev for I2C_XXX modules - feature FRM: work as physical IODev for I2C_XXX modules
added: FRM_ROTENC: read rotary-encoders with FRM added: FRM_ROTENC: read rotary-encoders with FRM
added: FRM_RGB: control rgb-leds with FRM added: FRM_RGB: control rgb-leds with FRM
@ -89,15 +100,16 @@
- feature: 57_Calendar: deal with non-existent end times - feature: 57_Calendar: deal with non-existent end times
- bugfix: SOMFY: fix non-working on/off-for-timer methods - bugfix: SOMFY: fix non-working on/off-for-timer methods
made positioning attributes optional made positioning attributes optional
- feature: SOMFY: support for exact positioning (one-time setup of run times required) - feature: SOMFY: support for exact positioning (one-time setup of run times
support for parse()-function, requires newest CULFW. required) support for parse()-function, requires newest CULFW.
- feature: userattr is now also device attribute - feature: userattr is now also device attribute
- feature: ZWave: Fibaro_FGRM222 MANUFACTURER_PROPRIETARY class - feature: ZWave: Fibaro_FGRM222 MANUFACTURER_PROPRIETARY class
- feature: sequence: reportEvents attribtue added - feature: sequence: reportEvents attribtue added
- feature: SYSMON: RAM and SWAP Readings on OSX - feature: SYSMON: RAM and SWAP Readings on OSX
- change: 34_NUT: removed calculation of values. Use userReadings instead. - change: 34_NUT: removed calculation of values. Use userReadings instead.
removed autogeneration of attr model and serNo. removed autogeneration of attr model and serNo.
- feature: SYSMON: improvement: support network information (IP, IPv6) on german linux - feature: SYSMON: improvement: support network information (IP, IPv6) on
german linux
- feature: Synology DiskStation NAS basic spk file creation - feature: Synology DiskStation NAS basic spk file creation
- change: 34_NUT: readingFnAttributes added; creation of units deleted; - change: 34_NUT: readingFnAttributes added; creation of units deleted;
changed attr asReadings to use comma instead of space changed attr asReadings to use comma instead of space

View File

@ -26,8 +26,8 @@ use strict;
use warnings; use warnings;
use Config; use Config;
sub CommandFheminfo($$); sub CommandFheminfo($$);
my %UPDATE;
######################################## ########################################
sub sub
@ -37,11 +37,6 @@ fheminfo_Initialize($$)
Fn => "CommandFheminfo", Fn => "CommandFheminfo",
Hlp => "[send],show or send Fhem statistics", Hlp => "[send],show or send Fhem statistics",
); );
$UPDATE{server} = "http://fhem.de";
$UPDATE{path} = "fhemupdate4";
$UPDATE{packages} = "FHEM";
$UPDATE{FHEM}{control} = "controls_fhem.txt";
$cmds{fheminfo} = \%hash; $cmds{fheminfo} = \%hash;
} }
@ -72,86 +67,35 @@ CommandFheminfo($$)
return "Unknown argument $args[0], usage: fheminfo [send]" return "Unknown argument $args[0], usage: fheminfo [send]"
if(@args && lc($args[0]) ne "send"); if(@args && lc($args[0]) ne "send");
return "Argument 'send' is not useful, if global attribute 'sendStatistics' is set to 'never'."
if(@args && lc($args[0]) eq "send" && lc(AttrVal("global","sendStatistics","")) eq "never");
my $branch = "DEVELOPMENT"; return "Won't send, as sendStatistics is set to 'never'."
if(@args &&
lc($args[0]) eq "send" &&
lc(AttrVal("global","sendStatistics","")) eq "never");
my $branch = "DEVELOPMENT"; # UNUSED
my $release = "5.6"; my $release = "5.6";
my $os = $^O; my $os = $^O;
my $arch = $Config{"archname"}; my $arch = $Config{"archname"};
my $perl = $^V; my $perl = $^V;
my $uniqueID = AttrVal("global","uniqueID",undef); my $uniqueID = getUniqueId();
my $sendStatistics = AttrVal("global","sendStatistics",undef); my $sendStatistics = AttrVal("global","sendStatistics",undef);
my $moddir = $attr{global}{modpath}."/FHEM"; my $moddir = $attr{global}{modpath}."/FHEM";
my $uidFile = $moddir."/FhemUtils/uniqueID"; my $upTime = fhemUptime();
my $upTime;
$upTime = fhemUptime(); my %official_module;
if(defined($uniqueID) && $uniqueID eq $uidFile) { opendir(DH, $moddir) || return("$moddir: $!");
my $fh; foreach my $file (grep /^controls.*.txt$/, readdir(DH)) {
if(open($fh,"<".$uidFile)) { open(FH, "$moddir/$file") || next;
Log 5, "fheminfo get uniqueID from $uidFile"; while(my $l = <FH>) {
while (my $line = <$fh>) { $official_module{$1} = 1 if($l =~ m+^UPD.* FHEM/\d\d_(.*).pm+);
chomp $line;
if($line =~ m/^uniqueID:[\da-fA-F]{32}$/) {
(undef,$uniqueID) = split(":",$line);
}
}
close $fh;
} }
close(FH);
} }
closedir(DH);
if(!defined($uniqueID) || $uniqueID !~ m/^[\da-fA-F]{32}$/ || !-e $uidFile) { return "Can't read FHEM/controls_fhem.txt, execute update first."
my $fh; if(!%official_module);
if(!open($fh,">".$uidFile)) {
return "Can't open $uidFile: $!";
}
if(!defined($uniqueID) || defined($uniqueID) && $uniqueID !~ m/^[\da-fA-F]{32}$/) {
$uniqueID = join "",map { unpack "H*", chr(rand(256)) } 1..16;
}
print $fh "################################################################\n";
print $fh "# IMPORTANT NOTE:\n";
print $fh "# This file is auto generated from the fheminfo command.\n";
print $fh "# Please do not modify, move or delete this file!\n";
print $fh "#\n";
print $fh "# This file contains an unique ID for this installation. It is\n";
print $fh "# to be used for statistical purposes only.\n";
print $fh "# Based on this unique ID, no conclusions can be drawn to any\n";
print $fh "# personal information of this installation.\n";
print $fh "################################################################\n";
print $fh "\n";
print $fh "uniqueID:$uniqueID\n";
close $fh;
Log 5, "fheminfo 'uniqueID' generated and stored in file '$uidFile'";
}
$attr{global}{uniqueID} = $uidFile;
my $ret = checkConfigFile($uidFile);
return $ret if($ret);
# get list of files
my $fail;
my $control_ref = {};
my $pack = "FHEM";
if(!-e "$moddir/$UPDATE{$pack}{control}") {
my $server = $UPDATE{server};
my $BRANCH = "SVN";
my $srcdir = $UPDATE{path}."/".lc($BRANCH);
Log 5, "fheminfo get $server/$srcdir/$UPDATE{$pack}{control}";
my $controlFile = GetFileFromURL("$server/$srcdir/$UPDATE{$pack}{control}");
return "Can't get '$UPDATE{$pack}{control}' from $server" if (!$controlFile);
# parse remote controlfile
($fail,$control_ref) = parseControlFile($pack,$controlFile,$control_ref,0);
return "$fail\nfheminfo canceled..." if ($fail);
} else {
Log 5, "fheminfo get $moddir/$UPDATE{$pack}{control}";
# parse local controlfile
($fail,$control_ref) = parseControlFile($pack,"$moddir/$UPDATE{$pack}{control}",$control_ref,1);
}
foreach my $d (sort keys %defs) { foreach my $d (sort keys %defs) {
my $n = $defs{$d}{NAME}; my $n = $defs{$d}{NAME};
@ -159,8 +103,7 @@ CommandFheminfo($$)
my $m = "unknown"; my $m = "unknown";
$m = $defs{$d}{model} if( defined($defs{$d}{model}) ); $m = $defs{$d}{model} if( defined($defs{$d}{model}) );
$m = AttrVal($n,"model",$m); $m = AttrVal($n,"model",$m);
if(exists $control_ref->{$t}) { if($official_module{$t} && !$defs{$d}{TEMPORARY}) {
Log 5, "fheminfo name:$n type:$t model:$m";
$info{modules}{$t}{$n} = $m; $info{modules}{$t}{$n} = $m;
} }
} }
@ -170,7 +113,6 @@ CommandFheminfo($$)
my $str; my $str;
$str = "Fhem info:\n"; $str = "Fhem info:\n";
$str .= sprintf(" Release%*s: %s\n",2," ",$release); $str .= sprintf(" Release%*s: %s\n",2," ",$release);
$str .= sprintf(" Branch%*s: %s\n",3," ",$branch);
$str .= sprintf(" OS%*s: %s\n",7," ",$os); $str .= sprintf(" OS%*s: %s\n",7," ",$os);
$str .= sprintf(" Arch%*s: %s\n",5," ",$arch); $str .= sprintf(" Arch%*s: %s\n",5," ",$arch);
$str .= sprintf(" Perl%*s: %s\n",5," ",$perl); $str .= sprintf(" Perl%*s: %s\n",5," ",$perl);
@ -185,7 +127,6 @@ CommandFheminfo($$)
my $length = (reverse sort { $a <=> $b } map { length($_) } @modules)[0]; my $length = (reverse sort { $a <=> $b } map { length($_) } @modules)[0];
$str .= "Defined modules:\n"; $str .= "Defined modules:\n";
foreach my $t (sort keys %{$info{modules}}) { foreach my $t (sort keys %{$info{modules}}) {
my $c = scalar keys %{$info{modules}{$t}}; my $c = scalar keys %{$info{modules}{$t}};
my @models; my @models;
@ -197,7 +138,8 @@ CommandFheminfo($$)
} }
$str .= sprintf(" %s%*s: %d\n",$t,$length-length($t)+1," ",$c); $str .= sprintf(" %s%*s: %d\n",$t,$length-length($t)+1," ",$c);
if(@models != 0) { if(@models != 0) {
$modStr .= sprintf(" %s%*s: %s\n",$t,$length-length($t)+1," ",join(",",sort @models)); $modStr .= sprintf(" %s%*s: %s\n",
$t,$length-length($t)+1," ", join(",",sort @models));
$contModels .= join(",",sort @models)."|"; $contModels .= join(",",sort @models)."|";
} }
$contModules .= "$t:$c|"; $contModules .= "$t:$c|";
@ -209,12 +151,12 @@ CommandFheminfo($$)
$str .= $modStr; $str .= $modStr;
} }
my $transmitData = ($attr{global}{sendStatistics}) ? $attr{global}{sendStatistics} : "not set"; my $td = (lc(AttrVal("global", "sendStatistics", "")) eq "onupdate") ?
$str .= "\n"; "yes" : "no";
$str .= "Transmitting this information during an update:\n";
$str .= " $transmitData (Note: You can change this via the global attribute sendStatistics)\n";
$ret = $str; $str .= "\n";
$str .= "Transmitting this information during an update: $td\n";
$str .= "You can change this via the global attribute sendStatistics\n";
if(@args != 0 && $args[0] eq "send") { if(@args != 0 && $args[0] eq "send") {
my $uri = "http://fhem.de/stats/statistics.cgi"; my $uri = "http://fhem.de/stats/statistics.cgi";
@ -239,125 +181,15 @@ CommandFheminfo($$)
timeout => 60); timeout => 60);
my $res = $ua->request($req); my $res = $ua->request($req);
$ret .= "\nserver response: "; $str .= "\nserver response: ";
if($res->is_success) { if($res->is_success) {
$ret .= $res->content."\n"; $str .= $res->content."\n";
} else { } else {
$ret .= $res->status_line."\n"; $str .= $res->status_line."\n";
}
}
return $ret;
}
########################################
sub parseControlFile($$$$) {
my ($pack,$controlFile,$control_ref,$local) = @_;
my %control = %$control_ref if ($control_ref && ref($control_ref) eq "HASH");
my $from = ($local ? "local" : "remote");
my $ret;
if ($local) {
my $str = "";
# read local controlfile in string
if (open FH, "$controlFile") {
$str = do { local $/; <FH> };
}
close(FH);
$controlFile = $str
}
# parse file
if ($controlFile) {
foreach my $l (split("[\r\n]", $controlFile)) {
chomp($l);
Log 5, "fheminfo $from controls_".lc($pack).".txt: $l";
my ($ctrl,$date,$size,$file,$move) = "";
if ($l =~ m/^(UPD) (20\d\d-\d\d-\d\d_\d\d:\d\d:\d\d) (\d+) (\S+)$/) {
$ctrl = $1;
$date = $2;
$size = $3;
$file = $4;
} elsif ($l =~ m/^(DIR) (\S+)$/) {
$ctrl = $1;
$file = $2;
} elsif ($l =~ m/^(MOV) (\S+) (\S+)$/) {
$ctrl = $1;
$file = $2;
$move = $3;
} elsif ($l =~ m/^(DEL) (\S+)$/) {
$ctrl = $1;
$file = $2;
} else {
$ctrl = "ESC"
}
if ($ctrl eq "ESC") {
Log 1, "fheminfo File 'controls_".lc($pack).".txt' ($from) is corrupt";
$ret = "File 'controls_".lc($pack).".txt' ($from) is corrupt";
}
last if ($ret);
if ($l =~ m/^UPD/ && $file =~ m/^FHEM/) {
if ($file =~ m/^.*(\d\d_)(.*).pm$/) {
my $modName = $2;
$control{$modName} = $file;
}
}
}
}
return ($ret, \%control);
}
########################################
sub checkConfigFile($) {
my $uidFile = shift;
my $name = "fheminfo";
my $configFile = AttrVal("global","configfile","");
if($configFile && !configDBUsed()) {
my $fh;
if(!open($fh,"<".$configFile)) {
return "Can't open $configFile: $!";
}
my @currentConfig = <$fh>;
close $fh;
my @newConfig;
my $done = 0;
if(grep {$_ =~ /uniqueID/} @currentConfig) {
Log 5, "fheminfo uniqueID in configfile";
foreach my $line (@currentConfig) {
if($line =~ m/uniqueID/ && $line =~ m/[\da-fA-F]{32}/) {
Log 5, "fheminfo uniqueID in configfile and hex";
$line = "attr global uniqueID $uidFile\n";
$done = 1;
}
push(@newConfig,$line);
}
} else {
Log 5, "fheminfo uniqueID not in configfile";
foreach my $line (@currentConfig) {
push(@newConfig,$line);
if($line =~ /modpath/ && $done == 0) {
push(@newConfig,"attr global uniqueID $uidFile\n");
$done = 1;
}
}
}
if($done) {
if(!open($fh,">".$configFile)) {
return "Can't open $configFile: $!";
}
foreach (@newConfig) {
print $fh $_;
}
close $fh;
Log 1, "$name global attributes 'uniqueID' added to configfile $configFile";
} }
} }
return $str;
} }
######################################## ########################################
@ -372,25 +204,29 @@ sub checkModule($) {
} }
} }
sub fhemUptime { sub
my $diff = time - $fhem_started; fhemUptime()
my ($d,$h,$m,$ret); {
my $diff = time - $fhem_started;
($d,$diff) = _myDiv($diff,86400); my ($d,$h,$m,$ret);
($h,$diff) = _myDiv($diff,3600);
($m,$diff) = _myDiv($diff,60); ($d,$diff) = _myDiv($diff,86400);
($h,$diff) = _myDiv($diff,3600);
($m,$diff) = _myDiv($diff,60);
$ret = ""; $ret = "";
$ret .= "$d days, " if($d > 1); $ret .= "$d days, " if($d > 1);
$ret .= "1 day, " if($d == 1); $ret .= "1 day, " if($d == 1);
$ret .= sprintf("%02s:%02s:%02s", $h, $m, $diff); $ret .= sprintf("%02s:%02s:%02s", $h, $m, $diff);
return $ret; return $ret;
} }
sub _myDiv($$) { sub
my ($p1,$p2) = @_; _myDiv($$)
return (int($p1/$p2), $p1 % $p2); {
my ($p1,$p2) = @_;
return (int($p1/$p2), $p1 % $p2);
} }
1; 1;
@ -420,7 +256,7 @@ sub _myDiv($$) {
<li>Operating System Information</li> <li>Operating System Information</li>
<li>Hardware architecture</li> <li>Hardware architecture</li>
<li>Installed Perl version</li> <li>Installed Perl version</li>
<li>Installed FHEM release and branch</li> <li>Installed FHEM release</li>
<li>Defined modules (only official FHEM Modules are counted)</li> <li>Defined modules (only official FHEM Modules are counted)</li>
<li>Defined models per module</li> <li>Defined models per module</li>
</ul> </ul>
@ -430,7 +266,6 @@ sub _myDiv($$) {
fhem&gt; fheminfo fhem&gt; fheminfo
Fhem info: Fhem info:
Release : 5.3 Release : 5.3
Branch : DEVELOPMENT
OS : linux OS : linux
Arch : i686-linux-gnu-thread-multi-64int Arch : i686-linux-gnu-thread-multi-64int
Perl : v5.14.2 Perl : v5.14.2
@ -477,31 +312,6 @@ sub _myDiv($$) {
<br> <br>
<br> <br>
<ul> <ul>
<li>uniqueID<br>
A randomly generated ID (16 pairs of hash values), e.g.
<code>87c5cca38dc75a4f388ef87bdcbfbf6f</code> which is assigned to the transmitted
data to prevent duplicate entries.
<br>
The <code>uniqueID</code> is stored automatically in a file named <code>FhemUtils/uniqueID</code>
in FHEM's modules path.
<br>
<strong>IMPORTANT NOTE:</strong>
<br>
Every installation of FHEM should have to have his own unique ID.
<br>
Please do not modify, move or delete this file! You should always backup this file
(this is normally done by the <code>update</code> command automatically) and please restore
this file to the same path (<code>FhemUtils</code> in FHEM's modules path), if you plan to
reinstall your FHEM installation. This prevents duplicate entries for identical
installations on the same hardware in the statistics.
<br>
Otherwise, please use different unique IDs for each installation of FHEM on different
hardware, e.g. one randomly generated unique ID for FRITZ!Box, another one for the first
Raspberry Pi, another one for the second Raspberry Pi, etc.
<br>
Thanks for your support!
</li>
<br>
<li>sendStatistics<br> <li>sendStatistics<br>
This attribute is used in conjunction with the <code>update</code> command. This attribute is used in conjunction with the <code>update</code> command.
<br> <br>
@ -540,7 +350,7 @@ sub _myDiv($$) {
<li>Eingesetztes Betriebssystem</li> <li>Eingesetztes Betriebssystem</li>
<li>Hardware Architektur</li> <li>Hardware Architektur</li>
<li>Installierte Perl Version</li> <li>Installierte Perl Version</li>
<li>Installierte FHEM release und "branch"</li> <li>Installierte FHEM release</li>
<li>Definierte Module (nur offizielle FHEM Module werden ermittelt)</li> <li>Definierte Module (nur offizielle FHEM Module werden ermittelt)</li>
<li>Definierte Modelle je Modul</li> <li>Definierte Modelle je Modul</li>
</ul> </ul>
@ -550,7 +360,6 @@ sub _myDiv($$) {
fhem&gt; fheminfo fhem&gt; fheminfo
Fhem info: Fhem info:
Release : 5.3 Release : 5.3
Branch : DEVELOPMENT
OS : linux OS : linux
Arch : i686-linux-gnu-thread-multi-64int Arch : i686-linux-gnu-thread-multi-64int
Perl : v5.14.2 Perl : v5.14.2
@ -597,31 +406,6 @@ sub _myDiv($$) {
<br> <br>
<br> <br>
<ul> <ul>
<li>uniqueID<br>
Eine zuf&auml;llig generierte ID (16 Paare aus Hash Werten), z.B.
<code>87c5cca38dc75a4f388ef87bdcbfbf6f</code> welche den &uuml;bertragenen Daten
zur Vermeidung von doppelten Eintr&auml;ge zugewiesen wird.
<br>
Die <code>uniqueID</code> wird automatisch in einer Datei namens <code>FHemUtils/uniqueID</code>
im FHEM Modulverzeichnis gespeichert.
<br>
<strong>WICHTIGER HINWEIS:</strong>
<br>
Jede Installation von FHEM sollte seine eigene eindeutige ID haben.
<br>
Bitte diese Datei nicht ver&auml;ndern, verschieben oder l&ouml;schen! Diese Datei sollte
immer gesichert (wird normalerweise automatisch durch den <code>update</code> Befehl
erledigt) und bei einer Neuinstallation auf der gleichen Hardware im gleichen Verzeichnis
(<code>FhemtUtils</code> im FHEM Modulverzeichnis) wieder hergestellt werden. Dies verhindert
doppelte Eintr&auml;ge identischer Installationen auf der gleichen Hardware in der Statistik.
<br>
Anderfalls, sollten bitte f&uuml;r jede Installation auf unterschiedlicher Hardware eigene
IDs genutzt werden, z.B. eine zuf&auml;llig erzeugte ID f&uuml;r FRITZ!Box, eine weitere f&uuml;r
den ersten Raspberry Pi, eine weitere f&uuml;r einen zweiten Raspberry Pi, usw.
<br>
Vielen Dank f&uuml;r die Unterst&uuml;tzung!
</li>
<br>
<li>sendStatistics<br> <li>sendStatistics<br>
Dieses Attribut wird in Verbindung mit dem <code>update</code> Befehl verwendet. Dieses Attribut wird in Verbindung mit dem <code>update</code> Befehl verwendet.
<br> <br>

View File

@ -12,6 +12,58 @@ Utils_Initialize($$)
my ($hash) = @_; my ($hash) = @_;
} }
sub
getUniqueId()
{
my ($err, $uniqueID) = getKeyValue("uniqueID");
return $uniqueID if(!$err);
srand(time);
$uniqueID = join "",map { unpack "H*", chr(rand(256)) } 1..16;
setKeyValue("uniqueID", $uniqueID);
return $uniqueID;
}
sub
getKeyValue($)
{
my ($key) = @_;
my $fName = $attr{global}{modpath}."/FHEM/FhemUtils/uniqueID";
my ($err, @l) = FileRead($fName);
return ($err, undef) if($err);
for my $l (@l) {
return (undef, $1) if($l =~ m/^$key:(.*)/);
}
return ("Key not found", undef);
}
sub
setKeyValue($$)
{
my ($key,$value) = @_;
my $fName = $attr{global}{modpath}."/FHEM/FhemUtils/uniqueID";
my ($err, @old) = FileRead($fName);
my @new;
if($err) {
push(@new, "# This file is auto generated.",
"# Please do not modify, move or delete it.",
"");
@old = ();
}
my $fnd;
foreach my $l (@old) {
if($l =~ m/^$key:/) {
$fnd = 1;
push @new, "$key:$value" if(defined($value));
} else {
push @new, $l;
}
}
push @new, "$key:$value" if(!$fnd && defined($value));
return FileWrite($fName, @new);
}
sub sub
time_str2num($) time_str2num($)
{ {
@ -336,8 +388,26 @@ myUtils_Initialize($$)
nc replacement. nc replacement.
</li></br> </li></br>
<li><b>getUniqueId()</b><br>
return the FHEM uniqueID used by the fheminfo command. Uses the
getKeyValue / setKeyValue functions.
</li></br>
<li><b>setKeyValue(keyName, value)</b><br>
store the value in the file $modpath/FHEM/FhemUtils/uniqueID (the name is
used for backward compatibility), or in the database, if using configDB.
value may not contain newlines, and only one value per key is stored.
The file/database entry will be written immediately, no explicit save is
required. If the value is undef, the entry will be deleted.
Returns an error-string or undef.
</li></br>
<li><b>getKeyValue(keyName)</b><br>
return ($error, $value), stored previously by setKeyValue.
$error is undef if there was no error, otherwise $value is undef.
</li></br>
</ul> </ul>
</ul> </ul>
=end html =end html
=cut =cut