Device Parameters Download (CSV / emulator XML)
Overview
The endpoint POST /iot-webservice/iotw/Device/parameters/download returns the parameter tree of one device as a file.
The Angular portal uses it for the Save parameters button in Device update > Advanced view (DEV-2786, backend part DEV-3621).
The file holds the values that the ACS has stored. These are the same values that the Advanced view shows. The endpoint does not read the device.
Two formats exist:
-
CSV, for every protocol.
-
XML, in the format of the Friendly emulator that matches the protocol of the device.
|
The file contains secret parameters as decrypted plaintext. The Advanced view shows the same plaintext. An emulator that loads the file receives the credentials of the device. Every user who can open the device page can take these credentials away in a file. Handle the file as a secret. Exception: the values of an LwM2M multi-instance (array) parameter are written as stored. An encrypted value in such an array stays encrypted. |
Request and response
| Item | Value |
|---|---|
Method and path |
|
Header |
The authentication header, the same as for |
Request body |
JSON with the fields in the next table. |
Access |
An authenticated user whose domain contains the device. This is the rule of the device page. |
| Field | Type | Required | Description |
|---|---|---|---|
|
number |
yes |
Identifier of the device. |
|
string |
yes |
|
Example request:
{ "deviceId": 123, "format": "CSV" }
A successful response has status 200 and these headers:
| Header | Value |
|---|---|
|
|
|
|
The body holds the file bytes in UTF-8, without a byte order mark.
The browser can read Content-Disposition because the security configuration exposes it.
Errors
An error response has the status below and a JSON body in the standard ErrorDetails shape.
The service checks the conditions in the order of the table.
The service reads no device data before the format is valid.
The service reveals no protocol for a device outside the domain of the user.
| Order | Status and code | Name | Cause and content |
|---|---|---|---|
1 |
400 / 9117 |
|
|
2 |
400 / 9250 |
|
|
3 |
500 / 9018 |
|
The device is outside the domain of the user. The |
3 |
404 / 9024 |
|
The device identifier is unknown. |
4 |
400 / 9251 |
|
The format is |
Notes:
-
The i18n texts of 9250 and 9251 have no placeholder. The variable value travels only in
description. -
The Russian texts are in
service_errors_ru.properties. -
A missing or malformed JSON body returns status 500 with the code
INTERNAL_ERROR. The global exception handler does this, and this feature adds no mapping. -
A missing or invalid authentication token returns status 403 from the security filter. The body is not an
ErrorDetailsJSON.
CSV format
The CSV file follows the layout of the .NET portal export.
-
The file has no header row.
-
Each row is
<name>,<value>. -
An object row has an empty value:
<name>,. The name of an object ends with a dot. -
A row ends with an LF character, including the last row.
-
The separator is a comma. You cannot configure it.
-
Rows are sorted by full name, case-insensitive. Names that differ only in case keep a fixed order by their exact characters.
-
A null value is an empty cell.
-
An empty tree gives a file of 0 bytes.
Quoting
A cell is wrapped in " if it contains a quote, CR, LF, TAB, a space, a comma or a semicolon.
A quote inside a quoted cell is doubled.
The rule applies to the name cell and to the value cell.
Formula neutralization
A spreadsheet can run a cell that starts with a formula character. The service therefore changes both cells before it quotes them.
| Condition | Change |
|---|---|
The cell starts with |
The service adds a leading |
The cell starts with U+FEFF (the byte order mark character). |
The service adds a leading |
The cell contains |
The service inserts |
The cell contains CR or LF followed by |
The service inserts |
The cell contains TAB followed by |
The service inserts |
A plain number is a value such as -5, -0.5, 1e5 or -.5.
It stays unchanged in a value cell.
A parameter name cell never gets this exception: a name that starts with =, +, -, @, TAB or CR always gets the leading ', even if it looks like a number.
A value such as -1+1 or =1+1 is not a plain number and gets the '.
A changed cell is therefore not identical to the stored value: the ' can be at the start of the cell or after a ;, TAB, CR or LF inside it.
Keep this in mind if you import the CSV into another system.
The service checks only the characters in the table. It does not protect a reader that skips leading spaces, NUL characters or other zero-width characters, for example U+200B, before it looks for a formula character. A cell such as ` -1.5` with a leading space stays unchanged.
The ' is a literal character in the opened spreadsheet cell, not a hidden text prefix.
A value such as +15551234 or -70 dBm therefore appears with a leading apostrophe.
The service never writes a BOM itself.
A spreadsheet drops U+FEFF at the very start of a file and reads the next character as the start of the first cell, so a cell that starts with U+FEFF gets the leading '.
| The file is comma-separated UTF-8 without a BOM, as the old .NET export. Excel in RU or DE locales may put each row into one column when you open the file by double-click. It may also show non-ASCII text wrongly. Use Data > From Text/CSV, then select UTF-8 and the comma delimiter. |
Example for a TR-181 device:
Device.,
Device.DeviceInfo.,
Device.DeviceInfo.Manufacturer,"My Company"
Device.DeviceInfo.UpTime,8640
XML format
The XML file is a device tree for one of four Friendly emulators. The device protocol selects the format.
| Device protocol | XML format | Target |
|---|---|---|
TR-098, TR-181, or no stored protocol |
|
TR-069 emulator, "Parameter Trees Directory" |
USP |
|
IoT emulator, "Device tree (XML)" |
LwM2M |
|
IoT emulator, "Device tree (XML)" |
MQTT |
|
IoT emulator, "Device tree (XML)" |
OMA, UNKNOWN, NOT_SET, TR-069 |
none |
Error 9251 |
A device with no stored protocol is treated as TR-098, the same as in the Advanced view.
The writer uses these rules for every format:
-
A character outside the XML 1.0 character set becomes U+FFFD. The service counts these characters in its log line.
-
In element text,
&,<,>and CR are escaped. -
In an attribute,
&,<,>,",', TAB, LF and CR are escaped. -
A null value gives an empty value.
TR069
The file has the root element <device>.
It lists leaf parameters only.
An object with no parameters does not appear.
Each leaf has the name, the value, the stored type and the writable flag.
If the type is empty, the type is string.
<?xml version="1.0" encoding="UTF-8"?>
<device>
<parameter><name>Device.DeviceInfo.Manufacturer</name><value>My Company</value><type>string</type><writable>false</writable></parameter>
<parameter><name>Device.DeviceInfo.UpTime</name><value>8640</value><type>unsignedInt</type><writable>false</writable></parameter>
</device>
An empty tree gives <device></device>.
Rows keep the tree order.
IoT emulator formats
All three IoT formats use the root element <parameters> and one <parameter> element per row.
Rows keep the tree order.
An empty tree gives <parameters></parameters>.
IOT_USP
The file lists objects and leaves.
An object name keeps its trailing dot and has an empty value.
The attribute acs_name is _.
The type of a leaf is the stored type, unchanged.
The type of an object, an empty type or a blank type is string.
<?xml version="1.0" encoding="UTF-8"?>
<parameters>
<parameter name="Device.DeviceInfo." type="string" acs_name="_" value=""/>
<parameter name="Device.DeviceInfo.UpTime" type="unsignedInt" acs_name="_" value="8640"/>
</parameters>
IOT_MQTT
The file lists leaves only.
The attributes name and acs_name both hold the full dotted name.
The writer maps the stored type with the table in Stored type mapping for IoT formats.
The default type is STRING.
<?xml version="1.0" encoding="UTF-8"?>
<parameters>
<parameter name="Root.Sensor.Temperature" type="FLOAT" acs_name="Root.Sensor.Temperature" value="21.5"/>
</parameters>
The names in this example are illustrative.
IOT_LWM2M
The file lists leaves and array headers, with the instances of an array.
The file does not list object rows and object instance rows.
The attribute acs_name holds the full stored name.
The attribute name holds the numeric path.
| Row | Path in name |
|---|---|
Leaf |
|
Resource instance of an array |
|
Array header |
|
The writer reads the stored name with this grammar:
Root.<objectName>.<instance>.<resourceName>[.<resourceInstance>][.]
-
<objectName>is the text betweenRoot.and the first.<digits>.segment. -
<instance>and<resourceInstance>are digits. The writer copies them as text and never converts them to a number. -
<resourceName>is the rest, without a final.<digits>and without a final dot. -
A final dot marks an array header.
<?xml version="1.0" encoding="UTF-8"?>
<parameters>
<parameter name="/3/0/0" type="STRING" acs_name="Root.Device.0.Manufacturer" value="My Company"/>
</parameters>
The names in this example are illustrative.
Skip rule. The writer resolves the object identifier and the resource identifier in the ACS LwM2M model tables lwm2m_coap_objects and lwm2m_coap_resources.
A row is left out of the file in these cases:
-
The name does not follow the grammar.
-
The model has no object with this name, or it has more than one object identifier for it.
-
The model has no resource with this name in the object, or it has more than one resource identifier for it.
The writer never guesses.
The service counts the skipped rows.
The service writes a WARN line with the count and the first 5 names.
If the file looks incomplete, search the log for unresolved LwM2M names.
Type. If the model has exactly one value type for the resource, the row uses it.
The value types map as follows: STRING, FLOAT, BOOLEAN, INTEGER, TIME and OPAQUE keep their name.
OBJLINK becomes OBJLNK.
UNSIGNED_INTEGER becomes INTEGER.
OPAQUE_STRING, OBJECT, NONE, METHOD and an unknown value become STRING.
Otherwise, a plain leaf uses the mapped stored type, and an array header or an array instance uses STRING.
Stored type mapping for IoT formats
The comparison is not case-sensitive.
| Stored type | IoT type |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Any other type, or no type |
|
The stored type is the data model type of the parameter.
It is not the category that the Advanced view shows.
For example, the Advanced view shows unsignedInt as int, and the file keeps unsignedInt.
Consumer rule for the user interface
The portal requests the file with the response type blob.
If the request fails, HttpErrorResponse.error is a Blob.
The global error interceptor cannot read the code and the message from a Blob.
The user would then see the raw "Http failure response" text.
The interceptor must handle this case in one place:
-
Detect that the error is a
Blobwith a JSON type. -
Read it with
text()and parse the result withJSON.parse. -
Continue with the normal handling of
messageandcode. This includes the redirect for 9024 and 9018.
If the Blob is not JSON, the interceptor shows its generic message.
The portal can offer XML for every device, because 9251 is the defined answer for a protocol without an emulator format.
Take the file name from Content-Disposition, or build the same pattern in the browser.
For developers
The code is in services/src/main/java/com/friendly/services/device/parameterstree/export.
| Class | Role |
|---|---|
|
Handler for |
|
Validates the request in the fixed order 9117, 9250, domain 9018 or 9024, protocol 9251. Then it loads the tree with |
|
Flattens the tree depth first. An LwM2M |
|
CSV layout and formula neutralization. |
|
The four XML formats and the XML escaping. |
|
Resolves a stored LwM2M name to a numeric path. It is built per export from |
|
Builds the file name. |
-
The request record is
DeviceParametersDownloadBodyin thecommonsmodule. -
The service reads the LwM2M model tables only for
IOT_LWM2M. It makes no write. -
The service writes one INFO line per export with the fields
deviceId,serial,format,variant,rows,skippedandreplacedChars. The line has no parameter value. -
The whole file is built in memory. Memory use is about 3 to 4 times the file size.
-
The cost of an export is the cost of one Advanced view load. The per-device lock of
ParameterServiceserializes it with other reads of the same tree. -
The
value_typecolumn oflwm2m_coap_resourcesstores the ordinal of theResourceValueTypeenum.
Manual QA steps that no automated test covers:
-
Export a TR-181 device as XML and upload the file to the TR-069 emulator.
-
Export a USP, an LwM2M and an MQTT device as XML and select each file as "Device tree (XML)" in the IoT emulator.
-
Call the endpoint with an expired token and with no token. Expect status 403.
-
Call the endpoint as a user whose domain excludes the device. Expect the 9018 handling of the device page.
-
Repeat the LwM2M export on an install with MySQL and on an install with Oracle.