X-Git-Url: https://git.rvb.name/openhab-process.git/blobdiff_plain/0d4dd2a297fe44d645e64a1e5d48c1f37294c571..26d1617608ea0272ebb1373e6f489bc771091b21:/mqtt-mpd/mqmpdj?ds=sidebyside diff --git a/mqtt-mpd/mqmpdj b/mqtt-mpd/mqmpdj index 70603f2..b8c935a 100755 --- a/mqtt-mpd/mqmpdj +++ b/mqtt-mpd/mqmpdj @@ -2,6 +2,8 @@ . /opt/mqtt-mpd/mqmpd.cfg +id=`hostname`-$$ + host=$1 passwd=$2 @@ -18,9 +20,6 @@ fi while : do - $command idle - if [ $? = 0 ] - then # current=`mpc -h $host -P $passwd current | sed 's/"/\"/g'` # volume=`mpc -h $host -P $passwd volume | cut -d: -f2 | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//'` @@ -41,37 +40,57 @@ do single=${str3[7]} consume=${str3[9]} else - current='-' - status='stopped' - current_track_num='0' - tracks_in_list='0' - current_pos='-' - track_length='-' - str3=( ${array[0]}) - volume=`echo ${str3[1]} | sed 's/%//'` - if [ "$volume" = "n/a" ] + if [ ${#array[@]} = 1 ] then + current='-' + status='stopped' + current_track_num='0' + tracks_in_list='0' + current_pos='-' + track_length='-' + str3=( ${array[0]}) + volume=`echo ${str3[1]} | sed 's/%//'` + if [ "$volume" = "n/a" ] + then + volume="0" + fi + repeat=${str3[3]} + random=${str3[5]} + single=${str3[7]} + consume=${str3[9]} + else + # not responding or error + current='-' + status='failed' + current_track_num='0' + tracks_in_list='0' + current_pos='-' + track_length='-' volume="0" - fi - repeat=${str3[3]} - random=${str3[5]} - single=${str3[7]} - consume=${str3[9]} + repeat="off" + random="off" + single="off" + consume="off" + fi fi + + sleep 0.2 + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/nowplaying -m "$current" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/volume -m "$volume" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/status -m "$status" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/currentnum -m "$current_track_num" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/tracks -m "$tracks_in_list" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/currentpos -m "$current_pos" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/tracklen -m "$track_length" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/repeat -m "$repeat" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/random -m "$random" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/single -m "$single" -u $mquser -P $mqpassword + mosquitto_pub -i mqtt-mpd-$id -h $mqhost -p $mqport -t $mqtopic/$host/consume -m "$consume" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/nowplaying -m "$current" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/volume -m "$volume" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/status -m "$status" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/currentnum -m "$current_track_num" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/tracks -m "$tracks_in_list" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/currentpos -m "$current_pos" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/tracklen -m "$track_length" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/repeat -m "$repeat" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/random -m "$random" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/single -m "$single" -u $mquser -P $mqpassword - mosquitto_pub -h $mqhost -p $mqport -t $mqtopic/$host/consume -m "$consume" -u $mquser -P $mqpassword - - else - sleep 30 - fi + $command idle + if [ $? != 0 ] + then + sleep 60 + fi + done