mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
32_speedtest: added ookla attribute
git-svn-id: https://svn.fhem.de/fhem/trunk@22919 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
d9540f601a
commit
086c89a2ff
@ -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: 32_speedtest: added ookla attribute
|
||||
- feature: 31_HUEDevice: added lastseen attribute
|
||||
- change: 57_SSCal: integrate SMUtils lib, minor fixes
|
||||
- bugfix: 02_FTUISRV: fix empty loop includes results
|
||||
- feature: 31_HUEDevice: added gesture reading for Aqara Cube
|
||||
|
@ -7,6 +7,9 @@ use strict;
|
||||
use warnings;
|
||||
use Blocking;
|
||||
|
||||
my $speedtest_hasJSON = 1;
|
||||
|
||||
|
||||
sub
|
||||
speedtest_Initialize($)
|
||||
{
|
||||
@ -17,8 +20,12 @@ speedtest_Initialize($)
|
||||
$hash->{SetFn} = "speedtest_Set";
|
||||
$hash->{AttrList} = "checks-till-disable ".
|
||||
"disable:0,1 ".
|
||||
"ookla:1,0 ".
|
||||
"path ".
|
||||
$readingFnAttributes;
|
||||
|
||||
eval "use JSON";
|
||||
$speedtest_hasJSON = 0 if($@);
|
||||
}
|
||||
|
||||
#####################################
|
||||
@ -123,17 +130,33 @@ speedtest_DoSpeedtest($)
|
||||
my ($string) = @_;
|
||||
my ($name, $server) = split("\\|", $string);
|
||||
|
||||
my $cmd = AttrVal($name, "path", "/usr/local/speedtest-cli" );
|
||||
my $ookla = AttrVal($name, "ookla", undef);
|
||||
|
||||
my $cmd;
|
||||
if( $ookla ) {
|
||||
$cmd = AttrVal($name, "path", "/usr/local/bin" );
|
||||
$cmd .= "/speedtest --accept-license --accept-gdpr -f json";
|
||||
$cmd .= " -s $server" if( $server );
|
||||
|
||||
} else {
|
||||
$cmd = AttrVal($name, "path", "/usr/local/speedtest-cli" );
|
||||
$cmd .= "/speedtest-cli --simple";
|
||||
$cmd .= " --server $server" if( $server );
|
||||
|
||||
}
|
||||
|
||||
Log3 $name, 5, "starting speedtest";
|
||||
my $speedstr = qx($cmd);
|
||||
Log3 $name, 5, "speedtest done";
|
||||
|
||||
if( $ookla ) {
|
||||
$speedstr =~ s/\n//g;
|
||||
return "$name|$speedstr";
|
||||
}
|
||||
|
||||
my @speedarr = split(/\n/, $speedstr);
|
||||
|
||||
for( my $i = 0; $i < 3; ++$i )
|
||||
{
|
||||
for( my $i = 0; $i < 3; ++$i ) {
|
||||
$speedarr[$i] = $1 if( $speedarr[$i] && $speedarr[$i] =~ m/^\w+: (.*)/i );
|
||||
}
|
||||
|
||||
@ -143,11 +166,11 @@ sub
|
||||
speedtest_SpeedtestDone($)
|
||||
{
|
||||
my ($string) = @_;
|
||||
|
||||
return unless(defined($string));
|
||||
|
||||
my @a = split("\\|",$string);
|
||||
my $hash = $defs{$a[0]};
|
||||
my $name = $a[0];
|
||||
my $hash = $defs{$name};
|
||||
|
||||
delete($hash->{helper}{RUNNING_PID});
|
||||
|
||||
@ -155,6 +178,38 @@ speedtest_SpeedtestDone($)
|
||||
|
||||
Log3 $hash, 5, "speedtest_SpeedtestDone: $string";
|
||||
|
||||
if( $a[1] =~ m/^\{.*\}$/ ) {
|
||||
if( !$speedtest_hasJSON ) {
|
||||
Log3 $name, 1, "json needed for ookla speedtest";
|
||||
return;
|
||||
}
|
||||
|
||||
my $decoded = eval { decode_json($a[1]) };
|
||||
|
||||
readingsBeginUpdate($hash);
|
||||
if( $decoded->{message} ) {
|
||||
readingsBulkUpdate($hash,"state", "failed" );
|
||||
readingsBulkUpdate($hash,"lastError", $decoded->{message} );
|
||||
|
||||
} else {
|
||||
readingsBulkUpdate($hash,"ping",$decoded->{ping}{latency}) if( defined( $decoded->{ping}) );
|
||||
readingsBulkUpdate($hash,"upload",round($decoded->{upload}{bandwidth}*8/1024/1024,1)) if( defined( $decoded->{upload}) );
|
||||
readingsBulkUpdate($hash,"download",round($decoded->{download}{bandwidth}*8/1024/1024,1)) if( defined( $decoded->{download}) );
|
||||
|
||||
readingsBulkUpdate($hash,"packetLoss",$decoded->{packetLoss}) if( defined( $decoded->{packetLoss}) );
|
||||
|
||||
readingsBulkUpdate($hash,"id",$decoded->{server}{id}) if( defined( $decoded->{server}) );
|
||||
readingsBulkUpdate($hash,"name",$decoded->{server}{name}) if( defined( $decoded->{server}) );
|
||||
readingsBulkUpdate($hash,"location",$decoded->{server}{location}) if( defined( $decoded->{server}) );
|
||||
|
||||
readingsBulkUpdate($hash,"state","ok");
|
||||
|
||||
}
|
||||
readingsEndUpdate($hash,1);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if( $a[1] eq "Invalid server ID" ) {
|
||||
readingsSingleUpdate($hash,"state", "failed", 1);
|
||||
return;
|
||||
@ -242,6 +297,9 @@ speedtest_SpeedtestAborted($)
|
||||
how often the speedtest should be run before it is automaticaly set to disabled. the value will be decreased by 1 for every run.</li>
|
||||
<li>disable<br>
|
||||
set to 1 to disable the test.</li>
|
||||
|
||||
<li>ookla<br>
|
||||
set to 1 to use the official ookla speedtest cli binary. will be searched in /usr/local/bin if path is not set.</li>
|
||||
</ul>
|
||||
</ul>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user