Template tester
Edit and Test energy saver template.
Edit and Test
To help with creating optimized translation templates for your needs to meet best energy and data saving expectation 1NCE OS provides:
- an interface to Edit and Test the desired template.
- API endpoint to test the template.
Template tester is a tool that processes the given Binary payload in Base64 string format using the template in template editor and returns the JSON output, translating the Base64 binary payload into readable format.
Note that Base64 string binary representation is used only for testing purpose, the actual translation of message is done from Binary into JSON.
Also, until changes are saved and template is in active state the template changes does not affect the flow of CoAP or UDP messages.

Edit and Test template interface
Example templates
There are 3 example templates provided to start with or just create your own template from scratch.
To try example templates just expand the list of example templates, select any desired template and press Use this template button. It will insert example template into template editor, provide example payload into input field. Now you are ready to do the template testing.

Example templates
Location template
{
"sense": [
{
"asset": "longitude",
"custom_type": "location_long",
"value": {
"byte": 0,
"bytelength": 8,
"type": "float",
"byteorder": "little"
}
},
{
"asset": "latitude",
"custom_type": "location_lat",
"value": {
"byte": 8,
"bytelength": 8,
"type": "float",
"byteorder": "little"
}
}
]
}
If custom types location_long and location_lat are available the position will be forwarded to the Location Service. Longitude and latitude both have to be float64.
Deep JSON
{
"sense": [
{
"asset": "car.running",
"value": {
"byte": 0,
"type": "boolean"
}
},
{
"asset": "car.fuel",
"value": {
"byte": 1,
"bytelength": 4,
"type": "uint"
}
},
{
"asset": "car.driver",
"value": {
"byte": 5,
"bytelength": 4,
"type": "string"
}
}
]
}
By including dots in the asset name, deep JSON objects can be created.
Switch statement
{
"sense": [
{
"switch": {
"byte": 0,
"bytelength": 1,
"type": "int"
},
"on": [
{
"case": 0,
"do": [
{
"asset": "data_type",
"value": "environment"
},
{
"asset": "temperature",
"value": {
"byte": 1,
"bytelength": 4,
"type": "float"
}
}
]
},
{
"case": 1,
"do": [
{
"asset": "data_type",
"value": "device"
},
{
"asset": "on",
"value": {
"byte": 1,
"type": "boolean"
}
}
]
}
]
}
]
}
The statements inside do will be executed if the value of case (within the same object as do) and the switch match.
Test results
Test failed
When template is incorrect and template tester can't process the payload, the error message appears under the edit field describing the error:

Template expects 17 bytes while only 16 bytes are provided
Test succeeded
Output field below template editor provides the translated template value in readable format.
As an additional template performance metrics the Reduced Bytes is provided that represents payload size difference between OUTPUT and INPUT of template as well as Energy Saved value that is calculated according to our research described in Energy Saving Calculation article.
Reduced bytes and Energy saved metrics represents savings on every message that is sent by device

Test succeeded
Updated 1 day ago