-
Notifications
You must be signed in to change notification settings - Fork 2
SolarNode Placeholders
SolarNode supports placeholders in some setting values, such as datum data source IDs. These allow you to define a set of parameters that can be consistently applied to many settings.
For example, imagine you manage many SolarNode devices across different buildings or sites, You'd
like to follow a naming convention for your datum data source ID values that include a code for the
building the node is deployed in, along the lines of /BUILDING/DEVICE
. You could define a
placeholder building
and then configure the source IDs like /{building}/device
. On each node
you'd define the building
placeholder with a building-specific value, so at runtime the nodes
would resolve actual source ID values with those names replacing the {building}
placeholder.
Placeholders are written in this form: {name:default}
where name
is the placeholder name and
default
is an optional default value to apply if no placeholder value exists for the given name
(if no default is needed the :
should be omitted).
For example, imagine a set of placeholder values like
Name | Value |
---|---|
building | OFFICE1 |
room | BREAK |
Here are some example settings with placeholders with what they would resolve to:
Input | Resolved value | Note |
---|---|---|
/{building}/meter |
/OFFICE1/meter |
|
/{building}/{room}/temp |
/OFFICE1/BREAK/temp |
Two placeholders. |
/{building}/{floor:1}/{room}/lux |
/OFFICE1/1/BREAK/lux |
Floor default value used. |
SolarNode will look for placeholder values defined in properties files stored in the
conf/placeholders.d
directory by default. In SolarNodeOS this is the
/etc/solarnode/placeholders.d
directory. These files are only loaded once, when SolarNode starts
up. If you make changes to any of them then SolarNode must be restarted.
The properties file names must have a .properties
extension and follow Java properties file
syntax. Put simply, each file contains lines like
name = value
where name
is the placeholder name and value
is its associated value. The example set of
placeholder values could be defined in a /etc/solarnode/placeholders.d/mynode.properties
file with
this content:
building = OFFICE1
room = BREAK
SolarNode also supports storing placeholder values as settings using the key placeholder
.
The SolarUser /instruction/add API can be used with the
UpdateSetting topic to modify the placeholder
values as needed. The type
value is the placeholder name and the value
the placeholder
value. Placeholders defined this way have priority over any similarly-named placeholders
defined statically. Changes take effect as soon as SolarNode receives and processes the
instruction.
⚠️ Note that once a placeholder value is set via theUpdateSetting
instruction, the same value defined as a static placeholder will be overridden and changes to the static value will be ignored.
For example, to set the floor
placeholder to 2
on node 123, you could make a POST
request to
/solaruser/api/v1/sec/instr/add/UpdateSetting
with the following JSON body:
{
"nodeId": 123,
"topic": "UpdateSetting",
"params":{
"key": "placeholder",
"type": "floor",
"value": "2"
}
}
Multiple settings can be updated as well, using a different syntax. Here's a request that sets
both floor
to 2
and room
to MEET
:
{"nodeId":123, "topic":"UpdateSetting","parameters":[
{"name":"key", "value":"placeholder"},
{"name":"type", "value":"floor"},
{"name":"value", "value":"2"},
{"name":"key", "value":"placeholder"},
{"name":"type", "value":"room"},
{"name":"value", "value":"MEET"}
]}