scripts Ping smartphone connecté reseau wifi
Publié : 22 oct. 2014, 21:52
salut a tous
sur le forum domoticz.com j'ai vue un scripte qui permait de faire un ping tous les x temps et d'utilisé la présence ou non du smartphone comme switch virtuel.
Qui peut-étre pratique pour couplé au chauffage pour le coupé quand on est pas présent ou activé l'alarme ou je ne sais quoi.
ici
http://www.domoticz.com/wiki/Domoticz_P ... using_Perl
et la discussion sur le forum
http://www.domoticz.com/forum/viewtopic ... =17#p13294
moi j'ai une erreur a la ligne 21
elle
mon ping_by_ip.pl
si quelqu'un a une idée 
sur le forum domoticz.com j'ai vue un scripte qui permait de faire un ping tous les x temps et d'utilisé la présence ou non du smartphone comme switch virtuel.
Qui peut-étre pratique pour couplé au chauffage pour le coupé quand on est pas présent ou activé l'alarme ou je ne sais quoi.
ici
http://www.domoticz.com/wiki/Domoticz_P ... using_Perl
et la discussion sur le forum
http://www.domoticz.com/forum/viewtopic ... =17#p13294
moi j'ai une erreur a la ligne 21
Code : Tout sélectionner
Could not get http://192.168.1.6:8080/json.htm?type=devices&filter=all&used=true&order=Name! at ./ping_by_ip.pl line 21.Code : Tout sélectionner
die "Could not get $domo_cmd!" unless defined $json;Code : Tout sélectionner
#!/usr/bin/perl
use v5.14;
use LWP::Simple; # From CPAN
use JSON qw( decode_json ); # From CPAN
use Data::Dumper; # Perl core module
use strict; # Good practice
use warnings; # Good practice
use utf8;
use feature qw< unicode_strings >;
# Configuration section, please update to your values
my $domoticz = "192.168.1.6:8080"; # ip and port of your Domoticz server
my $domo_cmd = "http://$domoticz/json.htm?type=devices&filter=all&used=true&order=Name";
# Array of (device idx, IP)
my %IP=(872=>'192.168.1.12', # Ip 1
873=>'192.168.1.8', # Ip 2
681=>'192.168.5.24'); # Ip 3
my $debug=0;
# Get the JSON url
my $json = get( $domo_cmd );
die "Could not get $domo_cmd!" unless defined $json;
# Decode the entire JSON
my $decoded = JSON->new->utf8(0)->decode( $json );
my @results = @{ $decoded->{'result'} };
#Put JSON switch and status in a Table
my @tab;
foreach my $f ( @results ) {
if ($f->{"SwitchType"}) {
$tab[$f->{"idx"}]=$f->{"Status"};
}
}
# Now we go all over the IP to check if they are alive
foreach my $k (keys %IP) {
my $ip=$IP{$k};
my $res=system("sudo ping $ip -w 3 2>&1 > /dev/null");
#print $k." ".$res."\n";
if (($res==0)&&($tab[$k] eq 'Off')) {
#If device answered to ping and device status is Off, turn it On in Domoticz
if ($debug) {print "$k is On\n"};
`curl -s "http://$domoticz/json.htm?type=command¶m=switchlight&idx=$k&switchcmd=On"`;
} elsif (($res!=0)&&($tab[$k] eq 'On')) {
#If device did NOT answer to ping and device status is On, turn it Off in Domoticz
if ($debug) {print "$k is Off\n"};
`curl -s "http://$domoticz/json.htm?type=command¶m=switchlight&idx=$k&switchcmd=Off"`;
} else {
if ($debug) {print "do nothing: $k is ".$tab[$k]."\n";}
}
}