#!/bin/sh /etc/rc.common

START=80

USE_PROCD=1
PROG=/usr/sbin/ucentral-mqtt

service_triggers() {
	procd_add_reload_trigger ucentral umqtt
}

start_service() {
	. /lib/functions.sh

	config_load 'ucentral'
	config_get serial 'config' 'serial'
	config_get venue 'config' 'venue'

	config_load 'umqtt'
	config_get username 'mqtt' 'username'
	config_get password 'mqtt' 'password'
	config_get server 'mqtt' 'server'
	config_get port 'mqtt' 'port'
	config_get debug 'mqtt' 'debug' 0
	config_get debug 'mqtt' 'enable' 0

	[ "$enable" -eq 1 ] || return 0
	procd_open_instance
	procd_set_param command "$PROG"
	[ -n "$serial" ] && procd_append_param command -S $serial
	[ -n "$username" ] && procd_append_param command -u $username
	[ -n "$password" ] && procd_append_param command -p $password
	[ -n "$server" ] && procd_append_param command -s $server
	[ -n "$port" ] && procd_append_param command -P $port
	[ -n "$venue" ] && procd_append_param command -v $venue
	[ "$debug" -eq 0 ] || procd_append_param command -d
	procd_set_param respawn
	procd_close_instance
}
