#!/bin/bash
i=0

cd /opt/domoticz/scripts/
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games:/usr/local/lib/
while ["$temp" -eq ""] 
do 
   rm /tmp/digiterm.tmp
   /opt/domoticz/scripts/digiterm --raw --no-info >/tmp/digiterm.tmp 2>>/var/log/syslog

   temp=`cat /tmp/digiterm.tmp |awk -F "," '{ print $2 }'|awk -F "@" '{print $1}'`
   hum=`cat /tmp/digiterm.tmp |awk -F "," '{ print $1 }'|awk -F "#" '{print $2}'`

   echo "HUM " $temp "--" $hum >>/var/log/syslog

   if [ -z "$temp" -a -z "$hum" ];
   then
       echo "Error: Value variable empty"
   else
       echo "HUM " $temp "--" $hum
       json="http://localhost:81/json.htm?type=command&param=udevice&idx=68&svalue=$temp;$hum;0"
       echo "HUM " $json >>/var/log/syslog
       curl -s -i -H "Accept: application/json" $json >/dev/null 2>>/var/log/syslog
       exit 0
   fi
   sleep 1
   i+=1 
   if [[ "$i" -ge 3 ]];
   then
      exit 0
   fi
done

exit 0
