mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
obuspa: Config to enable test controller
This commit is contained in:
parent
ee283c2e1b
commit
dc0b80097b
4 changed files with 154 additions and 4 deletions
|
|
@ -1,7 +1,4 @@
|
|||
if PACKAGE_obuspa
|
||||
|
||||
menu "Configuration"
|
||||
|
||||
config OBUSPA_DB_PATH
|
||||
string "Configure path for usp.db file"
|
||||
default "/tmp/"
|
||||
|
|
@ -25,5 +22,8 @@ config OBUSPA_MTP_ENABLE_COAP
|
|||
config OBUSPA_CONTROLLER_MTP_VERIFY
|
||||
bool "Enable verification of controller MTP before processing the message"
|
||||
default n
|
||||
endmenu
|
||||
|
||||
config OBUSPA_ENABLE_TEST_CONTROLLER
|
||||
bool "Adds a test controller by default"
|
||||
default n
|
||||
endif
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ define Package/obuspa
|
|||
CATEGORY:=Utilities
|
||||
SUBMENU:=TRx69
|
||||
TITLE:=USP agent
|
||||
MENU:=1
|
||||
DEPENDS:=+libopenssl +libuci +libblobmsg-json +libcurl +libsqlite3 +libubox +libubus +libmosquitto-ssl +libwebsockets-openssl
|
||||
endef
|
||||
|
||||
|
|
@ -113,6 +114,10 @@ define Package/obuspa/install
|
|||
$(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-upgrade-uci $(1)/etc/uci-defaults/
|
||||
$(INSTALL_BIN) ./files/etc/uci-defaults/02-obuspa-dhcp-option $(1)/etc/uci-defaults/
|
||||
$(INSTALL_BIN) $(PKG_BUILD_DIR)/files/etc/udhcpc.user.d/udhcpc_obuspa_opt125.user $(1)/etc/udhcpc.user.d/udhcpc_obuspa_opt125.user
|
||||
ifeq ($(CONFIG_OBUSPA_ENABLE_TEST_CONTROLLER),y)
|
||||
$(INSTALL_BIN) ./files/etc/init.d/usptest $(1)/etc/init.d/
|
||||
$(INSTALL_BIN) ./files/etc/uci-defaults/55-test-usp-controller $(1)/etc/uci-defaults/
|
||||
endif
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,obuspa))
|
||||
|
|
|
|||
75
obuspa/files/etc/init.d/usptest
Executable file
75
obuspa/files/etc/init.d/usptest
Executable file
|
|
@ -0,0 +1,75 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
STOP=01
|
||||
USE_PROCD=1
|
||||
|
||||
log()
|
||||
{
|
||||
echo "$*"|logger -t usptest -p debug
|
||||
}
|
||||
|
||||
get_oui_from_db()
|
||||
{
|
||||
db -q get device.deviceinfo.ManufacturerOUI
|
||||
}
|
||||
|
||||
get_serial_from_db()
|
||||
{
|
||||
db -q get device.deviceinfo.SerialNumber
|
||||
}
|
||||
|
||||
publish_endpoint()
|
||||
{
|
||||
local AgentEndpointID serial oui user pass
|
||||
|
||||
if ! uci -q get obuspa.testmqtt; then
|
||||
return 0;
|
||||
fi
|
||||
|
||||
# return if mosquitto_pub is not present
|
||||
if [ ! "$(command -v mosquitto_pub)" ]; then
|
||||
log "mosquitto_pub not present can't publish EndpointID"
|
||||
return 0;
|
||||
fi
|
||||
|
||||
sleep 2
|
||||
# Get endpoint id from obuspa config first
|
||||
config_load obuspa
|
||||
config_get AgentEndpointID localagent EndpointID ""
|
||||
if [ -z "${AgentEndpointID}" ]; then
|
||||
serial=$(get_serial_from_db)
|
||||
oui=$(get_oui_from_db)
|
||||
AgentEndpointID="os::${oui}-${serial//+/%2B}"
|
||||
fi
|
||||
|
||||
config_get user testmqtt Username ""
|
||||
config_get pass testmqtt Password ""
|
||||
|
||||
# publish Agent's EndpointID in mosquito broker for discovery by usp-js
|
||||
# This is a work around till obuspa adds supports for mDNS discovery
|
||||
if [ -n "${user}" ] && [ -n "${pass}" ]; then
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker with username, password"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" -u "${user}" -P "${pass}"
|
||||
elif [ -n "${user}" ]; then
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker with username only"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}" -u "${user}"
|
||||
else
|
||||
log "Publishing EndpointID ${AgentEndpointID} to local mqtt broker"
|
||||
mosquitto_pub -r -t "obuspa/EndpointID" -m "${AgentEndpointID}"
|
||||
fi
|
||||
}
|
||||
|
||||
start_service() {
|
||||
procd_open_instance usptest
|
||||
publish_endpoint
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
publish_endpoint
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "mosquitto" "obuspa"
|
||||
}
|
||||
70
obuspa/files/etc/uci-defaults/55-test-usp-controller
Normal file
70
obuspa/files/etc/uci-defaults/55-test-usp-controller
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
if [ ! -f "/etc/config/obuspa" ]; then
|
||||
echo "Local obuspa not available"
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ ! -f "/etc/config/mosquitto" ]; then
|
||||
echo "Local mosquitto broker not available"
|
||||
return 0
|
||||
fi
|
||||
|
||||
add_obuspa_test_mtp()
|
||||
{
|
||||
uci_add obuspa mtp test_mtp
|
||||
uci_set obuspa test_mtp Protocol 'MQTT'
|
||||
uci_set obuspa test_mtp ResponseTopicConfigured '/usp/endpoint'
|
||||
uci_set obuspa test_mtp mqtt 'testmqtt'
|
||||
}
|
||||
|
||||
add_obuspa_test_mqtt()
|
||||
{
|
||||
# Adds Device.MQTT.Client.
|
||||
uci_add obuspa mqtt testmqtt
|
||||
uci_set obuspa testmqtt BrokerAddress '127.0.0.1'
|
||||
uci_set obuspa testmqtt BrokerPort '1883'
|
||||
uci_set obuspa testmqtt TransportProtocol 'TCP/IP'
|
||||
}
|
||||
|
||||
add_obuspa_test_controller()
|
||||
{
|
||||
# Adds Device.LocalAgent.Controller.
|
||||
uci_add obuspa controller testcontroller
|
||||
uci_set obuspa testcontroller EndpointID 'proto::interop-usp-controller'
|
||||
uci_set obuspa testcontroller Protocol 'MQTT'
|
||||
uci_set obuspa testcontroller Topic '/usp/controller'
|
||||
uci_set obuspa testcontroller mqtt 'testmqtt'
|
||||
uci_set obuspa testcontroller assigned_role_name 'full_access'
|
||||
}
|
||||
|
||||
add_usp_test()
|
||||
{
|
||||
uci_add mosquitto listener usptest
|
||||
uci_set mosquitto usptest enabled 1
|
||||
uci_set mosquitto usptest port '9001'
|
||||
uci_set mosquitto usptest protocol 'websockets'
|
||||
uci_set mosquitto usptest require_certificates '0'
|
||||
uci_set mosquitto usptest auth_plugin '/usr/lib/mosquitto_auth_shadow.so'
|
||||
}
|
||||
|
||||
add_obuspa_config()
|
||||
{
|
||||
uci_add mosquitto listener obuspa
|
||||
uci_set mosquitto obuspa enabled 1
|
||||
uci_set mosquitto obuspa port '1883'
|
||||
uci_set mosquitto obuspa no_remote_access '1'
|
||||
uci_set mosquitto obuspa allow_anonymous '1'
|
||||
}
|
||||
|
||||
# Install test usp controller config
|
||||
uci_load mosquitto
|
||||
add_usp_test
|
||||
add_obuspa_config
|
||||
|
||||
uci_load obuspa
|
||||
add_obuspa_test_mtp
|
||||
add_obuspa_test_mqtt
|
||||
add_obuspa_test_controller
|
||||
Loading…
Add table
Reference in a new issue