Configure the Modbus package in Liota to enroll a Modbus Thing device and collect metrics.

Prerequisites

Ensure that you have:
  • Created a Liota gateway template on VMware Pulse IoT Center.
  • Enrolled a gateway using the Liota gateway template.
  • Created a Thing template to enroll the Modbus Thing device.

Procedure

  1. Copy the Liota packages from the installer location to the packages folder in your gateway. Run the following command:
    root@photon-machine [ /opt/vmware/liota/data/packages ]# cp ~/mirrors_github_liota/example/pulsev2/* .
    The Liota packages are copied to the packages folder in your gateway.
  2. Edit the Modbus device package that you want to configure. In this example, we configure the Modbus Humidifier package to collect metrics. Run the following command:
    root@photon-machine [ /opt/vmware/liota/data/packages ]# vi modbus_humidifier.py
  3. The modbus.humidifier.py package contains definitions for collecting metrics and for running commands.
    1. Configure the following parameters:
      Parameter Description
      device_props Enter the IP address of your Modbus Thing device. For example,
      device_props = {"ip":"10.197.99.43"}
      comms Enter the Ethernet name and port number. For example,
      comms = ModbusDeviceComms({"iface":"eth3", "port":"47808"})
      device_name Enter the device name that is registered on VMware Pulse IoT Center. For example,
      device_name = "ModbusHumiditySensor"
      d Enter the device template name that you have created on VMware Pulse IoT Center. For example,
      d = PulseConnectedDevice(device_name, "HumiditySensorTemplate",
                                               self.iotcc_edge_system.reg_entity_id,
                                               device_context)
      metricName The name of the metric that is collected in VMware Pulse IoT Center. Ensure that you provide the same metric name and value type when creating a Thing template. For example,
      metricName = "Humidity"
      args To configure your humidity sensor device to send metrics to VMware Pulse IoT Center, update the entity type to InputRegister and specify the value type as float 32. The following entity types are available:
      • Coil
      • DiscreteInput
      • HoldingRegister
      • InputRegister
      For example,
      args = [self.reg_device.reg_entity_id,
                              "humidity_sensor",
                              {"entity": "InputRegister",
                               "address": 1, "type": "float32"}]
      d_metric Define the type of metric that is sent to VMware Pulse IoT Center. For example:
      d_metric = Metric(
                          name=metric_name,
                          mtype='double',
                          unit=None,
                          interval=10,
                          sampling_function=collect_metrics,
                          sampling_args=args
                      )
      client_id The ID for sending the commands. For example,
      client_id = "com.liota.modbus"
      interval The time interval in seconds to check for the commands. For example,
      interval=10
  4. After configuring the package, register it by running the following command:
    root@photon-machine [ /opt/vmware/liota/data/packages ]# python3 reg.py modbus_humidifier

Results

The Modbus humidifier device is enrolled to VMware Pulse IoT Center. The Metrics tab of the device publishes the metrics every 10 seconds.

What to do next

Send a command to the enrolled humidifier device:
  1. In the VMware Pulse IoT Center console, go to Inventory > Devices.
  2. Click the thermostat device that you have enrolled, click the drop-down menu, and click Commands.
  3. Click SEND COMMAND.
  4. In the Send Command window:
    1. Under Select Command, select the set-temperature command.
    2. Under Arguments, make sure that the argument name is the same as in the configuration package.
    3. Under Address, enter the entity type, address, and value type. This address is to identify the device register to be set. For example,
      {"entity": "HoldingRegister", "address": 1, "type": "float32"}
    4. Under Value, enter the temperature value.
  5. Click SEND COMMAND.
  6. Refresh the Command History table. The status of the command must change to EXECUTED.
  7. Verify the update from the Metrics tab.