#!/system/bin/sh

if [ "$1" = "--on" ] ; then
	payload="1"
elif [ "$1" = "--off" ] ; then
	payload="0"
elif [ "$1" = "--toggle" ] ; then
	payload="2"
else
	echo "specify --on, --off or --toggle"
	exit 1
fi

interface=0
installation_id="$(config get installation/installation_id | sed 's/"//g')"
master="$(config get installation/master | sed 's/"//g')"
mosquitto_pub -p 1883 -h 127.0.0.1 -m "{\"d\":{\"payload\":\"${payload}\"}}" -t "forward-bridge/local/$installation_id/client@internal/${master}/request/DB/realtime/drivers/driver_baos/interfaces/${interface}/programming" -i "system"
ret=$?

if [ $ret -eq 0 ] ; then
	echo "succesfully set programming mode to ${payload} for installation_id ${installation_id} on master ${master}"
else
	echo "ERROR: failed to set programming mode to ${payload} for installation_id ${installation_id} on master ${master}"
	exit $ret
fi

