#!/bin/bash

cd /opt/domoticz/scripts/
withings=`php withingjd.php`
#poids=$withings |awk -F "," '{print $3}'
#seche=php jd.php |awk -F "," '{print $5}'
#mg=php jd.php |awk -F "," '{print $7}'

arr=$(echo $withings | tr "," "\n")
i=0
j=7
mg=0.0
pds=0.0
for x in $arr
do
    #echo "> [$x]"
    i=$((i+1))
    if [ "$j" -eq "$i" ]
    then
       mg=$x
       echo "mg> [$x]"
    fi
    if [ 3 -eq "$i" ]
    then
       pds=$x
       echo "pds > [$x]"
    fi
done
#echo $mg

if [ "$withings" != "" ]
then
   json="http://localhost:81/json.htm?type=command&param=udevice&idx=327&nvalue=$mg&svalue=$mg"
   json2="http://localhost:81/json.htm?type=command&param=udevice&idx=326&nvalue=$mg&svalue=$pds"
   #echo $json
   curl -s -i -H "Accept: application/json" $json >/dev/null
   curl -s -i -H "Accept: application/json" $json2 >/dev/null
else 
   echo "echec de recuperation"
fi

