2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-04-20 07:16:03 +00:00

git-svn-id: https://svn.fhem.de/fhem/trunk@5005 2b470e98-0d58-463d-a4d8-8e2adae1ed80

This commit is contained in:
tpoitzsch 2014-02-20 21:13:02 +00:00
parent e40a6d1fc0
commit ef0e3c969d
2 changed files with 20 additions and 20 deletions

View File

@ -37,11 +37,10 @@ use warnings;
use Blocking;
use IO::Socket;
use Time::HiRes qw/ time /;
use POSIX;
use Net::Telnet;
# Modul Version for remote debugging
my $modulVersion = "2014-02-08";
my $modulVersion = "2014-02-20";
#List of firmware versions that are known to be compatible with this modul
my $testedFirmware = "#V1.54C#V1.60#V1.69#";
@ -800,9 +799,9 @@ LUXTRONIK2_UpdateDone($)
# Device and reading times, delays and durations
$value = strftime "%Y-%m-%d %H:%M:%S", localtime($a[22]);
readingsBulkUpdate($hash, "deviceTimeCalc", $value);
my $delayDeviceTimeCalc=floor($a[29]-$a[22]+0.5);
my $delayDeviceTimeCalc=sprintf("%.0f",$a[29]-$a[22]);
readingsBulkUpdate($hash, "delayDeviceTimeCalc", $delayDeviceTimeCalc);
my $durationFetchReadings = floor(($a[30]-$a[29]+0.005)*100)/100;
my $durationFetchReadings = sprintf("%.2f",$a[30]-$a[29]);
readingsBulkUpdate($hash, "durationFetchReadings", $durationFetchReadings);
#Remember min and max reading durations, will be reset when initializing the device
if ($hash->{fhem}{durationFetchReadingsMin} == 0 || $hash->{fhem}{durationFetchReadingsMin} > $durationFetchReadings) {

View File

@ -57,7 +57,7 @@ sub JSONMETER_ParseJsonFile($);
sub JSONMETER_UpdateAborted($);
# Modul Version for remote debugging
my $modulVersion = "2014-02-08";
my $modulVersion = "2014-02-20";
##############################################################
# Syntax: meterType => port URL-Path
@ -267,15 +267,18 @@ JSONMETER_Get($@)
if ($cmd eq "jsonFile") {
$result = JSONMETER_GetJsonFile $name;
my @a = split /\|/, $result;
if ($a[1] == 1) {
$message = decode_base64($a[2]);
if ($a[1]==0) {
return $a[2];
} else {
$message = $a[1];
return decode_base64($a[2]);
}
return $message;
} elsif ($cmd eq "jsonAnalysis") {
$hash->{fhem}{jsonInterpreter} = "";
$result = JSONMETER_GetJsonFile $name;
my @a = split /\|/, $result;
if ($a[1]==0) { return $a[2]; }
$result = JSONMETER_ParseJsonFile $result;
# my @a = split /\|/, $result;
$message = decode_base64($result); #$a[2]);
@ -307,7 +310,7 @@ JSONMETER_GetUpdate($)
{
Log3 $name,2,"$name - Error reading device: Please define the attribute 'pathString'";
$hash->{STATE} = "pathString missing";
return "$name|0|"."Error reading device: Please define the attribute 'pathString'.";
return "$name|0|Error reading device: Please define the attribute 'pathString'.";
}
$hash->{helper}{RUNNING_PID} = BlockingCall("JSONMETER_GetJsonFile", $name,
@ -330,8 +333,8 @@ JSONMETER_GetJsonFile ($)
my $urlPath = "";
$urlPath = $hash->{urlPath} if defined $hash->{urlPath};
return "$name|0|".encode_base64("Error: deviceType '$type' Please define the attribute 'pathString' first.")
if ($type eq "url" || $type eq "file") && ! defined($attr{$name}{"pathString"});
if (($type eq "url" || $type eq "file") && ! defined($attr{$name}{"pathString"}))
{return "$name|0|Error: deviceType is '$type' - Please define the attribute 'pathString' first.";}
my $pathString = "";
$pathString = $attr{$name}{"pathString"} if defined($attr{$name}{"pathString"});
@ -362,14 +365,13 @@ JSONMETER_ReadFromFile($)
Log3 $name, 4, "$name: Open file '$pathString'";
if (open(IN, "<" . $pathString)) {
my $message = join " ", <IN>;
# my @file = <IN>;
close(IN);
Log3 $name, 4, "$name: Close file";
$message = encode_base64($message,"");
return "$name|1|$message" ;
} else {
Log3 $name, 2, "$name Error: Cannot open file $pathString: $!";
return "$name|0|Error: Cannot open file";;
return "$name|0|Error: Cannot open file $pathString: $!";;
}
} # end JSONMETER_ReadFromFile
@ -410,19 +412,18 @@ JSONMETER_ReadFromUrl($)
Log3 $name, 5, "$name: received:\n $message";
$socket->close();
Log3 $name, 4, "$name: Socket closed";
if ($message =~ /^HTTP\/1.\d 404 Not Found/) {
return "$name|0|Error: URL 'http://$ip:$port/$pathString' returned 'Error 404: Page Not Found'";
}
$message = encode_base64($message,"");
return "$name|1|$message" ;
} else {
Log3 $name, 2, "$name: Cannot open socket to $ip:$port/$pathString";
return "$name|0|Error: Cannot open socket to $ip:$port/$pathString";
}
} # end JSONMETER_ReadFromUrl
sub ###########################
JSONMETER_ParseJsonFile($)
{