mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
sulu: Added init file to publish usp endpointid
This commit is contained in:
parent
78c895f23a
commit
ec3128865b
2 changed files with 64 additions and 1 deletions
|
|
@ -5,7 +5,7 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=sulu
|
||||
PKG_VERSION:=0.2.17
|
||||
PKG_VERSION:=0.2.18
|
||||
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/sulu.git
|
||||
|
|
|
|||
63
sulu/files/etc/init.d/sulu
Executable file
63
sulu/files/etc/init.d/sulu
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
STOP=10
|
||||
|
||||
USE_PROCD=1
|
||||
|
||||
log() {
|
||||
echo "${@}"|logger -t sulu.init -p debug
|
||||
}
|
||||
|
||||
publish_endpoint() {
|
||||
local AgentEndpointID serial oui user pass
|
||||
local opt=""
|
||||
|
||||
# return if mosquitto_pub is not present
|
||||
if ! which mosquitto_pub; then
|
||||
log "mosquitto_pub not present can't publish endpointid"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
ubus -t 10 wait_for usp.raw
|
||||
|
||||
# Get endpoint id from obuspa config first
|
||||
config_load obuspa
|
||||
config_get AgentEndpointID localagent EndpointID ""
|
||||
if [ -z "${AgentEndpointID}" ]; then
|
||||
serial=$(ubus -t 1 call usp.raw get '{"path":"Device.DeviceInfo.SerialNumber"}'|jsonfilter -e '@["parameters"][0].value')
|
||||
oui=$(ubus -t 1 call usp.raw get '{"path":"Device.DeviceInfo.ManufacturerOUI"}'|jsonfilter -e '@["parameters"][0].value')
|
||||
AgentEndpointID="os::${oui}-${serial}"
|
||||
fi
|
||||
|
||||
config_get user localmqtt Username
|
||||
if [ -n "${user}" ]; then
|
||||
opt="-u ${user}"
|
||||
fi
|
||||
config_get pass localmqtt Password
|
||||
if [ -n "${pass}" ]; then
|
||||
opt="${opt} -P ${pass}"
|
||||
fi
|
||||
|
||||
# publish Agent's EndpointID in mosquito broker for discovery
|
||||
# This is a work around till obuspa does not support advertising
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" ${opt}
|
||||
}
|
||||
|
||||
start_service() {
|
||||
procd_open_instance sulu
|
||||
publish_endpoint
|
||||
procd_close_instance
|
||||
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
start
|
||||
}
|
||||
|
||||
service_triggers()
|
||||
{
|
||||
procd_add_config_trigger "config.change" "obuspa" /etc/init.d/sulu reload
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue