mirror of
https://dev.iopsys.eu/feed/iopsys.git
synced 2025-12-10 07:44:50 +01:00
usp-js: 1.2.0
This commit is contained in:
parent
4350dad6ca
commit
06ac881ea8
4 changed files with 146 additions and 24 deletions
|
|
@ -6,18 +6,17 @@
|
|||
include $(TOPDIR)/rules.mk
|
||||
|
||||
PKG_NAME:=usp-js
|
||||
PKG_VERSION:=1.1.0
|
||||
PKG_VERSION:=1.2.0
|
||||
|
||||
PKG_SOURCE_PROTO:=git
|
||||
PKG_SOURCE_URL:=https://dev.iopsys.eu/websdk/usp-js.git
|
||||
PKG_SOURCE_VERSION:=e9c2af99615a840784f896cea8d58a44c0a4a22e
|
||||
PKG_SOURCE_VERSION:=0dde613f8e84e751ec9f5514301c7d58172e31a5
|
||||
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
|
||||
PKG_MIRROR_HASH:=skip
|
||||
|
||||
PKG_LICENSE:=BSD-3-Clause
|
||||
PKG_LICENSE_FILES:=LICENSE
|
||||
|
||||
#PKG_BUILD_DEPENDS:=node-yarn/host
|
||||
include $(INCLUDE_DIR)/package.mk
|
||||
|
||||
define Package/usp-js/default
|
||||
|
|
@ -38,34 +37,15 @@ define Package/usp-js-quickjs
|
|||
DEFAULT_VARIANT:=1
|
||||
endef
|
||||
|
||||
define Package/usp-js-nodejs
|
||||
$(Package/usp-js/default)
|
||||
TITLE += (NodeJS)
|
||||
DEPENDS:=+node
|
||||
VARIANT:=nodejs
|
||||
endef
|
||||
|
||||
ifeq ($(BUILD_VARIANT),nodejs)
|
||||
define Build/Compile
|
||||
cd $(PKG_BUILD_DIR) && yarn install && yarn build
|
||||
endef
|
||||
else
|
||||
define Build/Compile
|
||||
cd $(PKG_BUILD_DIR) && yarn install && yarn qjs
|
||||
endef
|
||||
endif
|
||||
|
||||
define Package/usp-js-quickjs/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/usp-js
|
||||
$(INSTALL_DIR) $(1)/etc
|
||||
$(CP) $(PKG_BUILD_DIR)/qjs/* $(1)/usr/lib/usp-js/
|
||||
$(CP) ./files/etc/* $(1)/etc/
|
||||
endef
|
||||
|
||||
define Package/usp-js-nodejs/install
|
||||
$(INSTALL_DIR) $(1)/usr/lib/node_modules/usp-js
|
||||
$(INSTALL_DIR) $(1)/usr/lib/node_modules/usp-js/node_modules
|
||||
$(CP) $(PKG_BUILD_DIR)/node/* $(1)/usr/lib/node_modules/usp-js/
|
||||
$(CP) $(PKG_BUILD_DIR)/node_modules/* $(1)/usr/lib/node_modules/usp-js/node_modules/
|
||||
endef
|
||||
|
||||
$(eval $(call BuildPackage,usp-js-nodejs))
|
||||
$(eval $(call BuildPackage,usp-js-quickjs))
|
||||
|
|
|
|||
73
usp-js/files/etc/init.d/uspjs
Executable file
73
usp-js/files/etc/init.d/uspjs
Executable file
|
|
@ -0,0 +1,73 @@
|
|||
#!/bin/sh /etc/rc.common
|
||||
|
||||
START=99
|
||||
STOP=01
|
||||
USE_PROCD=1
|
||||
|
||||
log()
|
||||
{
|
||||
echo "$*"|logger -t usp-js -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
|
||||
|
||||
# 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 uspjs
|
||||
procd_close_instance
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
publish_endpoint
|
||||
}
|
||||
|
||||
service_triggers() {
|
||||
procd_add_reload_trigger "obuspa" "network" "mosquitto"
|
||||
}
|
||||
22
usp-js/files/etc/uci-defaults/10-add-mosquitto-usptest-config
Executable file
22
usp-js/files/etc/uci-defaults/10-add-mosquitto-usptest-config
Executable file
|
|
@ -0,0 +1,22 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
if [ ! -f "/etc/config/mosquitto" ]; then
|
||||
echo "Local mosquitto broker not available"
|
||||
return 0
|
||||
fi
|
||||
|
||||
add_obuspa_config()
|
||||
{
|
||||
if ! uci_get mosquitto obuspa >/dev/null 2>&1; then
|
||||
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'
|
||||
fi
|
||||
}
|
||||
|
||||
uci_load mosquitto
|
||||
add_obuspa_config
|
||||
47
usp-js/files/etc/uci-defaults/10-add-obuspa-test-config
Executable file
47
usp-js/files/etc/uci-defaults/10-add-obuspa-test-config
Executable file
|
|
@ -0,0 +1,47 @@
|
|||
#!/bin/sh
|
||||
|
||||
. /lib/functions.sh
|
||||
|
||||
if [ ! -f "/etc/config/obuspa" ]; then
|
||||
echo "Local obuspa not available"
|
||||
return 0
|
||||
fi
|
||||
|
||||
add_obuspa_test_mtp()
|
||||
{
|
||||
if ! uci_get obuspa test_mtp >/dev/null 2>&1; then
|
||||
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'
|
||||
fi
|
||||
}
|
||||
|
||||
add_obuspa_test_mqtt()
|
||||
{
|
||||
# Adds Device.MQTT.Client.
|
||||
if ! uci_get obuspa testmqtt >/dev/null 2>&1; then
|
||||
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'
|
||||
fi
|
||||
}
|
||||
|
||||
add_obuspa_test_controller()
|
||||
{
|
||||
# Adds Device.LocalAgent.Controller.
|
||||
if ! uci_get obuspa testcontroller >/dev/null 2>&1; then
|
||||
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'
|
||||
fi
|
||||
}
|
||||
|
||||
uci_load obuspa
|
||||
add_obuspa_test_mtp
|
||||
add_obuspa_test_mqtt
|
||||
add_obuspa_test_controller
|
||||
Loading…
Add table
Reference in a new issue