Wb-mqtt-serial driver/en: различия между версиями

Материал из Wiren Board
(Новая страница: «== The configuration file of the driver ==»)
(Новая страница: «To run the driver, edit the <code>/etc/wb-mqtt-serial.conf</code> file. An ordinary user can use the RS-485 method:RS-485:Настройка через веб-…»)
Строка 35: Строка 35:
== The configuration file of the driver ==
== The configuration file of the driver ==


Для работы драйвера нужно отредактировать файл <code>/etc/wb-mqtt-serial.conf</code>. Обычный пользователь может воспользоваться способом [[RS-485:Настройка через веб-интерфейс|RS-485:Настройка через веб-интерфейс]], который тоже приводит к правильному заполнению файла конфигурации. Однако отредактировать файл можно и вручную, для этого:
To run the driver, edit the  <code>/etc/wb-mqtt-serial.conf</code> file. An ordinary user can use the RS-485 method:[[RS-485:Настройка через веб-интерфейс|RS-485:configuration via the web interface]], which also leads to the correct filling of the configuration file. However, you can edit the file manually. To do this:
#Ознакомьтесь с инструкцией [[Special:MyLanguage/Просмотр файлов контроллера с компьютера|Просмотр файлов контроллера с компьютера]]
#Read the instructions[[Special:MyLanguage/Просмотр файлов контроллера с компьютера/en|How to view controller files from your computer]]
#Файл <code>/etc/wb-mqtt-serial.conf</code> имеет структуру ''порты (ports) -> устройства (devices)'': в файле есть описания физических портов контроллера, а внутри них - список устройств, которые подключены к этому порту.
#File <code>/etc/wb-mqtt-serial.conf</code> has the structure ''ports -> devices'': there are descriptions of the physical ports of the controller in the file, and inside them there is a list of devices that are connected to this port.
#:Для каждого порта указываются настройки (скорость, чётность и т.п.), а также протокол (Modbus, RTU, etc.)
#:Settings (speed, parity, etc.) and protocol (Modbus, RTU, etc.) are specified for each port.
#:Для каждого устройства обязательно указывается его уникальный адрес на шине - ''slave_id''. Также можно указать другие необязательные параметры - смотрите полное описание формата [https://github.com/contactless/wb-homa-drivers/tree/master/wb-mqtt-serial в описании драйвера на нашем Github].
#:Each device must have its unique address on the bus - slave_id. You can also specify other optional parameters - see the [https://github.com/contactless/wb-homa-drivers/tree/master/wb-mqtt-serial full description of the format in the driver description on our Github].
#Впишите конфигурацию для портов и подключённых устройств в файл, используя примеры ниже.
#Enter the configuration for the ports and connected devices in the file using the examples below.
#Перезагрузите устройство ИЛИ выполните из консоли команду
#Restart the device OR run the command from the console
#: <syntaxhighlight lang="bash">
#: <syntaxhighlight lang="bash">
service wb-mqtt-serial restart
service wb-mqtt-serial restart
</syntaxhighlight>
</syntaxhighlight>
#:Она перезапустит драйвер, и подключённое устройство появится в веб-интерфейсе.
#:It will restart the driver and the connected device will appear in the web interface.
#Если устройство не появилось, выполните команду <syntaxhighlight lang="bash">tail /var/log/messages</syntaxhighlight> или откройте файл <code>/var/log/messages</code> и промотайте его до конца. Если там будет строчка такого типа:
#If the device does not appear, run the following command<syntaxhighlight lang="bash">tail /var/log/messages</syntaxhighlight> or open file <code>/var/log/messages</code> and scroll to the end. If there is a line like this one:
#:<code>May  6 17:50:58 wirenboard user.notice modbus: FATAL: Error parsing config file: Failed to parse JSON: * Line <b>15</b>, Column 17</code>
#:<code>May  6 17:50:58 wirenboard user.notice modbus: FATAL: Error parsing config file: Failed to parse JSON: * Line <b>15</b>, Column 17</code>
#:- ищите ошибку в 15-й строке конфигурационного файла.
#:- look for the error in the 15th line of the configuration file.





Версия 19:28, 29 мая 2019

Другие языки:

Attention! Driver wb-mqtt-serial was formerly named wb-homa-modbus, configuration file /etc/wb-mqtt-serial.conf was previously named /etc/wb-homa-modbus.conf. Keep this in mind if you are using outdated firmware.


The wb-mqtt-serial driver is responsible for working with devices connected to the Wiren Board controller via RS-485 . It provides work with connected devices through the MQTT message system. This article provides a simplified description of the driver, see the full description of the driver on our Github.


Supported Devices

Currently, work with Modbus interface devices of our production, Mercury and Milur counters, as well as with some other devices, including those operating under the Modbus Protocol, is supported. Full list of tested devices: Supported devices#RS-485 connected. Supported devices#connected via RS-485 .

Support for multiple protocol devices on the same bus

It is possible to use devices with different protocols on the same bus, but it is necessary to take into account the features of specific protocols.

For example, Uniel device frames start with byte 0xff, IVTM devices start with byte 0x24 ('$'), and in the case of Modbus, Mercury 230, and Milur protocols, the first byte of the frame is the slave ID, so when you combine such devices, you should carefully choose the slave id of Milur devices, for example, the default slave ID is 0xff, which leads to a conflict with Uniel devices. Milur Devices require additional polling delays (defined in the template) and may reduce polling speed when used on the same bus with other devices. Some devices that support additional protocols may not be compatible with other protocols on the same bus, for example, it has been observed that devices supporting the A-BUS protocol produced by "razumdom.ru" can not work on the same bus with Uniel devices. The work of the IVTM devices on the same bus with devices operating on other protocols has not been tested. Proven working combination is: Modbus + Milur (slave_id != 0xff) + Uniel on one bus.


Driver revision to support new devices

As a starting point, see the article WB-homa-modbus Driver:Examples of writing templates, for further support, contact us.


Configuring and running the driver

The driver configuration is specified in the /etc/wb-mqtt-serial.conf file. If such a file is created, the driver starts automatically when the controller is loaded. You can also control the driver manually from the console:

service wb-mqtt-serial stop #stop the driver
service wb-mqtt-serial start #start the driver
service wb-mqtt-serial restart #restart the driver
wb-mqtt-serial -c /etc/wb-mqtt-serial.conf -d #start the driver in forced debug mode with specifying the path to the configuration file


The configuration file of the driver

To run the driver, edit the /etc/wb-mqtt-serial.conf file. An ordinary user can use the RS-485 method:RS-485:configuration via the web interface, which also leads to the correct filling of the configuration file. However, you can edit the file manually. To do this:

  1. Read the instructionsHow to view controller files from your computer
  2. File /etc/wb-mqtt-serial.conf has the structure ports -> devices: there are descriptions of the physical ports of the controller in the file, and inside them there is a list of devices that are connected to this port.
    Settings (speed, parity, etc.) and protocol (Modbus, RTU, etc.) are specified for each port.
    Each device must have its unique address on the bus - slave_id. You can also specify other optional parameters - see the full description of the format in the driver description on our Github.
  3. Enter the configuration for the ports and connected devices in the file using the examples below.
  4. Restart the device OR run the command from the console
    service wb-mqtt-serial restart
    
    It will restart the driver and the connected device will appear in the web interface.
  5. If the device does not appear, run the following command
    tail /var/log/messages
    
    or open file /var/log/messages and scroll to the end. If there is a line like this one:
    May 6 17:50:58 wirenboard user.notice modbus: FATAL: Error parsing config file: Failed to parse JSON: * Line 15, Column 17
    - look for the error in the 15th line of the configuration file.


Пример конфигурации для модуля реле WB-MRM2, подключённого к изолированному порту (RS-485-ISO) Wiren Board 4

{
     "ports": [
        {
            "path" : "/dev/ttyNSC0",  //псевдофайл, соответствующий порту
            "baud_rate": 9600, //скорость порта, 9600 почти для всех устройств, но проверьте документацию к ним
            "parity": "N", //четность
            "data_bits": 8, //битов данных в посылке
            "stop_bits": 2, //количество стоп-битов. Чётность, количество битов и стоп-битов тоже редко меняются
            "poll_interval": 10, //интервал опроса устройств на порту в миллисекундах
            "devices" : [
                {
                    "device_type" : "WB-MRM2", //тип устройства, распознаваемый драйвером
                    "slave_id": 25 //адрес устройства
                }
            ]
        }
    ]
}

Узнать файл, соответствующий порту для вашего контроллера - RS-485#Реализация портов в разных версиях Wiren Board .

Полный список поддерживаемых типов устройств см. в статье Поддерживаемые устройства, а также здесь.


Пример конфигурационного файла для нескольких подключённых устройств

// Configuration options
{
    "debug": false,
    "ports": [
        {
            "path" : "/dev/ttyNSC1",
            "baud_rate": 9600,
            "parity": "N",
            "data_bits": 8,
            "stop_bits": 2,
            "poll_interval": 0,
            "enabled": true,
            "devices" : [
                {
                    "name": "DRB88",
                    "id": "drb88",
                    "enabled": true,
                    "slave_id": "0x23",
		    "device_type" : "DRB88"
                },
                {
                    "slave_id": "0x26",
		    "device_type" : "MSU24"
                },
                {
                    "slave_id": "0x31",
		    "device_type" : "MSU34"
                },
                {
                    "slave_id": "0x04",
		    "device_type" : "LC-103"
                },
		{
		    "device_type" : "DDL24",
		    "slave_id" : "0x20"
		},	
                {
                   "enabled": true,
                  "slave_id": "0x06",
		    "device_type" : "WB-MRM2" 
               },
	       {
                 "slave_id" : 16,
		 "device_type" : "WB-MRGB"
	       }
            ]
        },
	{
	    "path" : "/dev/ttyNSC0",
	    "type": "uniel",
	    "poll_interval": 10,
	    "enabled": true,
	    "devices" : [
		{
		    "device_type" : "UCH-M141RC",
		    "slave_id": 1
		}
	    ]
	}
    ]
}