wb_editors
14 355
правок
(Новая страница: «Other device parameters are either added to the section when the template is included in the wb-mqtt-serial general configuration, or default values are used. The…») |
FuzzyBot (обсуждение | вклад) м (FuzzyBot переименовал страницу Драйвер wb-mqtt-serial:Примеры написания шаблонов/en в Wb-mqtt-serial templates/en без оставления перенаправления: Часть переводимой страницы Драйвер wb-mqtt-serial:Примеры написания шаблонов.) |
||
(не показано 35 промежуточных версий 1 участника) | |||
Строка 1: | Строка 1: | ||
<languages/> | <languages/> | ||
=== The general structure of the device template | === The general structure of the device template=== | ||
A device template file is a [https://en.wikipedia.org/wiki/JSON JSON] structure that describes device parameters. The template allows comments. The JSON structure is written inside the space between the opening and closing braces:<code> { ... }</code> | A device template file is a [https://en.wikipedia.org/wiki/JSON JSON] structure that describes device parameters. The template allows comments. The JSON structure is written inside the space between the opening and closing braces:<code> { ... }</code> | ||
Строка 55: | Строка 54: | ||
Other device parameters are either added to the section when the template is included in the wb-mqtt-serial general configuration, or default values are used. The full list can be found in the [https://github.com/contactless/wb-mqtt-serial/blob/master/wb-mqtt-serial.schema.json wb-mqtt-serial.schema.json] file (a copy is also stored on the controller: <code>/usr/share/wb-mqtt-confed/schemas/wb-mqtt-serial.schema.json</code>). See "device" object properties: <code>"device" -> "properties"</code>. | Other device parameters are either added to the section when the template is included in the wb-mqtt-serial general configuration, or default values are used. The full list can be found in the [https://github.com/contactless/wb-mqtt-serial/blob/master/wb-mqtt-serial.schema.json wb-mqtt-serial.schema.json] file (a copy is also stored on the controller: <code>/usr/share/wb-mqtt-confed/schemas/wb-mqtt-serial.schema.json</code>). See "device" object properties: <code>"device" -> "properties"</code>. | ||
=== | === Device channels === | ||
[[File:Channel_properties_mqtt_serial.png|450px|thumb|right| | [[File:Channel_properties_mqtt_serial.png|450px|thumb|right|Channel parameters are described in wb-mqtt-serial.schema.json (made in app [http://www.bodurov.com/JsonFormatter/ Collapsible JSON Formatter])]] | ||
Channel description is a structure | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
"channels": [ | "channels": [ | ||
{ | { | ||
"name": " | "name": "Channel name1", | ||
... | ... | ||
}, | }, | ||
{ | { | ||
"name": " | "name": "Channel name2", | ||
... | ... | ||
}, | }, | ||
Строка 73: | Строка 72: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The structure contains the following set of fields. | |||
[[File:Vartype_properties_mqtt_serial.png|450px|thumb|right| | [[File:Vartype_properties_mqtt_serial.png|450px|thumb|right|the format of data representation in Modbus-registers is described in wb-mqtt-serial.schema.json (made in app [http://www.bodurov.com/JsonFormatter/ Collapsible JSON Formatter])]] | ||
* '''name''' — имя канала, уникальное для устройство имя канала | * '''name''' — имя канала, уникальное для устройство имя канала | ||
Строка 84: | Строка 83: | ||
* '''format''' — тип переменной, описывающей значение, см. рис. | * '''format''' — тип переменной, описывающей значение, см. рис. | ||
*'''name''' — the channel name that is unique to the device | |||
*'''reg_type''' — type of Modbus register, one of "coil", "discrete", "holding", "holding_single", "holding_multi", "input", "direct" types | |||
*'''address''' — the address of the Modbus register associated with the channel. | |||
*'''type''' — type of control, a virtual element for data representation in the Web-interface of the controller: "switch", "pushbutton", "range", "rgb" and others; fully listed in the scheme wb-mqtt-serial.schema.json. | |||
*'''readonly''' — "true" if the values can only be read. | |||
*'''format''' — '''type''' of the variable describing the value, see figure. | |||
In the simplest case, the fields "name", "reg_type", "address" and "type"are sufficient. Descriptions of other parameter types are fully listed in the wb-mqtt-serial.schema.json scheme. | |||
=== Examples of device templates=== | |||
The following are sample template files for some Wiren Board devices, covering a basic list of options used when creating templates. | |||
---- | ---- | ||
Строка 94: | Строка 100: | ||
==== WB-MS-THLS v.2 ==== | ==== WB-MS-THLS v.2 ==== | ||
The [[WB-MS_Modbus_Sensor/en|WB-MS]] device is a universal combined Modbus sensor for temperature, humidity, lighting and sound pressure. The device provides access to data via Modbus input registers. The initial settings of the device are recorded in the holding registers, but are not used to obtain data and control the device, so the template is not included.You can see the full template code via the following link. | |||
<div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | <div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | ||
Строка 167: | Строка 172: | ||
</div> | </div> | ||
There is an interesting parameter in the settings of the device: <syntaxhighlight lang="JSON"> "max_read_registers": 0,</syntaxhighlight> This parameter describes the maximum number of registers that can be read from the device when requested. The default value is 1, in our case we specify to read all registers in one pass (bulk read). | |||
In the settings of the channel "Temperature" there are three parameters that are worth paying attention to: | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
"format": "s16", | "format": "s16", | ||
Строка 174: | Строка 179: | ||
"error_value": "0x7FFF" | "error_value": "0x7FFF" | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Parameter'''"format": "s16"''' indicates that the number in the registers is represented as a signed 16-bit integer, '''"scale": 0.1''' — indicates that the value obtained from the registers should be multiplied by the scaling factor 0.1 to obtain the temperature value, and the parameter '''"error_value": "0x7FFF"''' sets the value sent from the register, indicating that an error occurred during the sensor poll. This parameter will be highlighted in red in the web interface of the controller. You should use this option if you know what value your device sends in case of an error. | |||
---- | ---- | ||
==== WB-MRGBW-D ==== | ==== WB-MRGBW-D ==== [[WB-MRGBW-D/en|WB-MRGBW-D]] is a four channel dimmer to control the led strip. Can control RGB+W tape or four single color tapes independently. Brightness settings are stored in holding registers; the template describes which registers can be changed to get the desired brightness of the channels, track the dimmer button presses and get the value of the number of clicks.You can see the full template code via the following link. | ||
<div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | <div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | ||
Строка 271: | Строка 274: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
</div> | </div> | ||
In this template, the RGB composite channel sets the brightness of three color ribbon components stored in three holding registers at the same time and is described as follows: | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
{ | { | ||
Строка 293: | Строка 296: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The white channel is controlled separately, | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
{ | { | ||
Строка 303: | Строка 306: | ||
}, | }, | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The maximum value that can be set for the white brightness slider is 255: | |||
<syntaxhighlight lang="JSON">"max": 255</syntaxhighlight> | |||
The serial number of the device (channel "Serial NO") is read as an unsigned 32-bit integer: | |||
<syntaxhighlight lang="JSON">"format": "u32"</syntaxhighlight> | |||
---- | ---- | ||
==== WBIO-DO-R10A-8 ==== | ==== WBIO-DO-R10A-8 ==== | ||
Устройство [[WBIO-DO-R10A-8_Relay_Module|WBIO-DO-R10A-8]] — | Устройство [[WBIO-DO-R10A-8_Relay_Module/en|WBIO-DO-R10A-8]] — is a relay side module that connects directly to the controller's WBIO connector and is not Modbus controlled. But when it is connected via a WB-MIO or WB-MIO-E expansion device, it becomes a full-fledged Modbus device for which there is a corresponding template.You can see the full template code via the following link. | ||
<div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | <div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | ||
Строка 417: | Строка 421: | ||
In this template, you should pay attention to the following device settings. | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
"protocol": "modbus_io", | "protocol": "modbus_io", | ||
Строка 426: | Строка 430: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Option ''' ''protocol'': ''modbus_io'' ''' indicates that the device connects to the extension module via special protocol. The parameters '''"stride": 1000''' and '''"shift":500''' set the shift of registers depending on the order in which the modules are connected to the extension module. | |||
Shift = (((SlaveId.Secondary - 1) % 4) + 1) * DeviceConfig()->Stride + DeviceConfig()->Shift; | |||
Here stride — DeviceConfig()->Stride, a shift — DeviceConfig()->Shift. | |||
Register shift (the number to be added to the base register number) is calculated by the formula:<syntaxhighlight lang="C++">Shift = (((SlaveId.Secondary - 1) % 4) + 1) * DeviceConfig()->Stride + DeviceConfig()->Shift;</syntaxhighlight> Здесь stride — ''DeviceConfig()->Stride'', a shift — ''DeviceConfig()->Shift''. Each connected device has a serial number (''SlaveId.Secondary'') starting with 1 for the first device. (Here the sign "%" shows modulу division.) | |||
For example, substituting the values of shift and stride in the formula: <syntaxhighlight lang="C++">Shift = ((( 1 - 1) % 4) + 1) * 500 + 1000 = (0 + 1) * 500 + 1000 = 1500</syntaxhighlight> So, you need to add 1500 to all registers specified in the template. | |||
Another important parameter — setup-section, array | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
"setup": [ { | "setup": [ { | ||
Строка 442: | Строка 451: | ||
...] | ...] | ||
</syntaxhighlight> | </syntaxhighlight> | ||
It describes the registers and values that are entered once in these registers when the device is initialized (when WB-mqtt-serial is started or restarted). It can be used to configure devices to operate in a particular mode, set the initial values of brightness, servo position, relay status, mode of operation with the inputs of relay modules, etc. | |||
---- | ---- | ||
Строка 448: | Строка 457: | ||
==== WB-MAP3H ==== | ==== WB-MAP3H ==== | ||
[[WB-MAP3H_Power_Meter/en|WB-MAP3H]] — three-channel electricity meter. It measures a large number of electrical network parameters. Since it can take quite a long time to poll all registers of such a device, there are several templates that contain the optimal set of parameters for the current task. We'll look at the basic pattern. You can see the full template code via the following link. | |||
<div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | <div class="mw-collapsible mw-collapsed" style="width:500px; overflow: hidden;" > | ||
Строка 860: | Строка 869: | ||
</div> | </div> | ||
What is so important in this template? First of all, we specify in the device parameters that no more than 60 registers should be read at the same time, so as not to stop for a long time the polling of other devices: | |||
'''"max_read_registers" : 60'''. Also the parameter describing the accumulated reactive energy in the phase L1 is indicative: | |||
<syntaxhighlight lang="JSON"> | <syntaxhighlight lang="JSON"> | ||
{ | { | ||
Строка 875: | Строка 884: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Here you should pay attention to the fact that the address of the register can be set in hexadecimal form:''' "address": "0x1224" ''', the real scaling factor can be set in the exponential notation:''' "scale": 3.125 e-05'''', when reading the value round it to the desired order:''' "round_to": 0.0001''', and also take into account that the number in the Modbus-registers is stored in order from the youngest to the oldest: '''"word_order": "little_endian"'''. Storage formats for 16-bit Modbus registers are described as follows: | |||
<pre> | <pre> | ||
big-endian : ( [0xAA 0xBB] [0xCC 0xDD] => 0xAABBCCDD ) | big-endian : ( [0xAA 0xBB] [0xCC 0xDD] => 0xAABBCCDD ) | ||
little-endian : ( [0xAA 0xBB] [0xCC 0xDD] => 0xCCDDAABB ) | little-endian : ( [0xAA 0xBB] [0xCC 0xDD] => 0xCCDDAABB ) | ||
</pre> | </pre> | ||
The default format is big-endian. | |||
The types of variables used in the templates are listed in the following table: | |||
{| class="wikitable" | {| class="wikitable" | ||
! | ! Designation !! Type | ||
|- | |- | ||
| s16 || Signed 16-bit integer | | s16 || Signed 16-bit integer | ||
Строка 922: | Строка 930: | ||
|} | |} | ||
=== | === Information resources === | ||
This article describes the basic rules for creating device templates for Wiren Board controllers. The information changes and is updated as the SOFTWARE is updated and new products are released. The most complete and up-to-date information can be found in the following sources: | |||
* | *in the WB-mqtt-serial service description on GitHub; | ||
* | *in the template files | ||
in the [https://github.com/contactless/wb-mqtt-serial/blob/master/wb-mqtt-serial.schema.json wb-mqtt-serial.schema.json] file on GitHub. |