Wb-mqtt-serial driver

Материал из Wiren Board
Это утверждённая версия страницы. Она же — наиболее свежая версия.
Другие языки:

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.


The example of configuration for relay module WB-MRM2 connected to the isolated Wiren Board 4 port (RS-485-ISO)

{
     "ports": [
        {
            "path" : "/dev/ttyNSC0",  //pseudofile corresponding to port
            "baud_rate": 9600, //the port speed is 9600 for almost all devices, but check the documentation first
            "parity": "N", //parity
            "data_bits": 8, //the number of data bits in the parcel
            "stop_bits": 2, //number of stop bits. Parity, bits, and stop bits are also rarely changed
            "poll_interval": 10,  //device polling interval on the port in milliseconds
            "devices" : [
                {
                    "device_type" : "WB-MRM2", ////device type recognized by driver
                    "slave_id": 25 //device address
                }
            ]
        }
    ]
}

For a complete list of supported device types, seeSupported devices, and also here.


An example of a configuration file for multiple connected devices

// 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
		}
	    ]
	}
    ]
}