Voici le script qui se place ici : /usr/share/nginx/www/jeedom/plugins/script/core/ressources/
Code : Tout sélectionner
#!/bin/bash
action=$1
ip=$2
login=admin
password=admin
#ip=192.168.1.57
div () # Fonction division
{
if [ $2 -eq 0 ]; then echo division by 0; exit; fi
local p=12 # precision
local c=${c:-0} # precision counter
local d=. # decimal separator
local r=$(($1/$2)); echo -n $r # result of division
local m=$(($r*$2))
[ $c -eq 0 ] && [ $m -ne $1 ] && echo -n $d
[ $1 -eq $m ] || [ $c -eq $p ] && return
local e=$(($1-$m))
let c=c+1
div $(($e*10)) $2
}
if ping -c 1 $ip &> /dev/null
then
#Allumer
if [[ $action == "on" ]];
then
#echo "prise on"
wget -O - -q --post-data="command=GpioForCrond%201&SystemCommandSubmit=Apply" http://$login:$password@$ip/goform/SystemCommand
status=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep -oP '(?<=\[)\d+'`;
echo $status
fi
#Eteindre
if [[ $action == "off" ]];
then
#echo "prise off"
wget -O - -q --post-data="command=GpioForCrond%200&SystemCommandSubmit=Apply" http://$login:$password@$ip/goform/SystemCommand
status=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep -oP '(?<=\[)\d+'`;
echo $status
fi
#Status
if [[ $action == "status" ]];
then
#echo "prise status"
status=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep -oP '(?<=\[)\d+'`;
echo $status
fi
#-------------------------------------
#GetInfo W : Consommation courante en centi-Watts
if [[ $action == "watt" ]];
then
wget -O - -q --post-data="command=GetInfo%20W&SystemCommandSubmit=Apply" http://$login:$password@$ip/goform/SystemCommand
watt=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep '$01W00' | cut -d' ' -f2 | sed 's/^0*//'`;
#echo $watt
echo $(div $watt 100)
fi
#)GetInfo I : Intensite courante
if [[ $action == "intensite" ]];
then
wget -O - -q --post-data="command=GetInfo%20I&SystemCommandSubmit=Apply" http://$login:$password@$ip/goform/SystemCommand
intensite=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep '$01I00' | cut -d' ' -f2 | sed 's/^0*//'`;
#echo $intensite
echo $(div $intensite 10000)
fi
##GetInfo V : Tension courante en milli-Volts
if [[ $action == "tension" ]];
then
wget -O - -q --post-data="command=GetInfo%20V&SystemCommandSubmit=Apply" http://$login:$password@$ip/goform/SystemCommand
tension=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep '$01V00' | cut -d' ' -f2 | sed 's/^0*//'`;
#echo $tension
echo $(div $tension 1000)
fi
#GetInfo E : Conso depuis le dernier reset, en mWatts/h
if [[ $action == "conso" ]];
then
wget -O - -q --post-data="command=GetInfo%20E&SystemCommandSubmit=Apply" http://$login:$password@$ip/goform/SystemCommand
conso=`wget -O - -q "http://"$login:$password@$ip"/adm/system_command.asp" 2>/dev/null | grep '$01E00' | cut -d' ' -f2 | sed 's/^0*//'`;
#echo $conso
echo $(div $conso 1000)
fi
else
echo "ping KO"
fi
Action : On et Off
Info : watt (mW), tension(mA), intensitée(mV) et conso (mW/h)
Le rendu dans le dashborard :