All Products
Search
Document Center

:Sample drivers

Last Updated:May 13, 2024

Link IoT Edge provides two sample drivers: Light and LightSensor. This topic describes how to use the two drivers.

The Light driver is a driver that is designed for smart lamps. You can use the Light driver to simulate and control smart lamps.

The LightSensor driver is a driver that is designed for light sensors. You can use this driver to simulate light sensors. This driver allows the simulated light sensors to repeat light intensity data based on a specified cycle.

Prerequisites

An edge instance is created and a gateway is connected to Link IoT Edge. For more information, see Set up environments.

Method of using sample drivers

  1. Log on to the Link IoT Edge console.
  2. In the left-side navigation pane, click Edge Instances. On the Edge Instances page, find the edge instance that you want to use and click View in the Actions column.
  3. Assign the Light driver and a sub-device to the edge instance.
    1. On the Instance Details page, click the Devices & Drivers tab and click the + icon next to All Drivers. In the Assign Driver panel, select Official Drivers from the drop-down list and assign the Light driver to the edge instance. Assign Driver panel
    2. Optional. Configure the Light driver. To do this, click the assigned Light driver and click Driver Configurations next to Devices. In the Driver Configurations panel, you can configure the Light driver. After you complete the configuration, click OK.
      In this example, you do not need to configure the Light driver. Configure the sample driver
      Table 1. Parameters of driver configurations
      ParameterDescription
      Configuration FormatThe configuration method. Valid values:
      • Key-value Configuration
      • JSON Format
      • Configuration File
      Configuration Format: Key-value ConfigurationIf you select Key-value Configuration, click Add Configuration. Then, set the Configuration Name, Value, and Description parameters to configure the driver.

      You can add a maximum of 100 key-value pairs.

      Configuration Format: JSON FormatIf you select JSON Format, enter JSON-formatted data to configure the driver. The data size cannot exceed 1 KB. Link IoT Edge automatically verifies the format. If the format is invalid, modify the JSON-formatted data as prompted.
      Configuration Format: Configuration FileIf you select Configuration File, edit a configuration file on your computer and upload it to the Link IoT Edge console.
    3. Optional. On the right side of Devices, click Container Configurations. On the Container Configurations page, configure the container for the driver. Click Save.
      Note You can configure the container only when the Instance Type parameter of the edge instance is set to Pro Edition.

      Parameter

      Description

      Host Mode

      Specifies whether to isolate the container network from the host network. Valid values:

      • Yes: The container network is the same as the host network.

      • No: The container network is isolated from the host network. If you select this option, you must set the Network Port Mapping parameter.

      Network Port Mapping

      The mappings between host network ports and container network ports. This parameter is available only when you set the Host Mode parameter to No. The network where the function runs is isolated from the host network. You can map the listening port of the function in the container to a host network port. This allows client programs on various hosts to access the services that are provided by the function. You can specify a maximum of 10 entries.

      For example, the fc-http-server function runs in a host container, and provides services by using Port 80. The client programs on other hosts cannot access the fc-http-server function by accessing Port 80 on the current host. To enable the client programs on other hosts to access the fc-http-server function, you must map Port 80 in the container where the function runs to a host network port, such as Port 8080. Then, the client programs on other hosts can access IP address:port 8080 on the host network, and use the services provided by the fc-http-server function.

      Privilege Mode

      Specifies whether to enable the privilege mode. Root users of containers can access host services only as regular users. If you need to change the system time or run the mount command in containers, you must be granted the required root permissions. In this scenario, you must enable the privilege mode for the containers.

      Note

      If you enable the privilege mode, applications and programs in the containers are granted the host root permissions, and all the host devices are mapped to the containers. Therefore, you do not need to set the Device Mapping parameter.

      Device Mapping

      The device mappings. This parameter is available only when you set the Privilege Mode parameter to No. The network where the device management system resides is isolated from the host network. To enable a function to access a host device such as a serial port, you must map the device to the container where the function runs. You can specify a maximum of 10 entries.

      Volume Mapping

      The volume mappings. The network where the file system resides is isolated from the host network. To enable a function to access a host file, you must map the file to the container where the function runs. You can specify a maximum of 10 entries.

    4. In the Devices section, click Assign Sub-device and assign a sub-device to the edge instance for the Light driver. Assign a sub-device to the sample driver
      In the Assign Sub-device panel, click Add Sub-device. Add Sub-device button
    5. In the Add Device dialog box, click Create Product and create a product that is named Living_Room_Lamp. Create a Living_Room_Lamp product
      In the Create Product dialog box, set the parameters as required and click OK.
      Table 2. Parameter description
      ParameterDescription
      Product NameThe name of the product. In this example, enter Living_Room_Lamp.
      Gateway Connection ProtocolThe communication protocol that is used by the gateway. In this example, select Custom.
      Authentication ModeThe authentication method. Select an authentication method that is suitable for your devices. For more information, see Authenticate devices.
    6. In the Add Device dialog box, the Product parameter is automatically set to Living_Room_Lamp. Then, set the DeviceName parameter to Light and click OK.
      Add Device dialog box
    7. In the Assign Sub-device panel, assign the Light device of the Living_Room_Lamp product to the edge instance.
      Assign Sub-device panel
    8. Assign the LightSensor driver to the edge instance. For the LightSensor driver, create a product that is named Light_Sensor and a device that is named LightSensor and assign the LightSensor device of the Light_Sensor product to the edge instance. The procedures are similar to those that are used to assign the Light driver and the Light device of the Living_Room_Lamp product to the edge instance.

      When you create a product, set the Product Name parameter to Light_Sensor.

      After you perform the preceding steps, the LightSensor and Light devices are assigned to the edge instance.

    9. Optional. Configure the devices. After a device is assigned to the edge instance, find the assigned device and click Device Configurations in the Actions column. In the Device Configurations panel, you can configure the device. For example, you can configure the device serial number, which allows the driver to process the information from the specified device.
      In this example, you do not need to configure the devices. Device Configurations panel

      The size of the specified JSON-formatted data cannot exceed 1 KB. Click Validation Format to verify the format of the specified data. After the specified data passes the verification, click OK.

  4. Deploy the edge instance.
    On the Instance Details page, click Deploy in the upper-right corner. In the message that appears, click OK to deploy the edge instance.
  5. Check whether the devices are in the Online state.
    On the Devices & Drivers tab, click All Drivers. In the Devices section, you can find that the Light and LightSensor devices are in the Online state, as shown in the following figure. Online
  6. View the status of the devices.
    Find the LightSensor or Light device and click View in the Actions column. You are navigated to the Device Details page of the IoT Platform console. On the Device Details page, click the TSL Data tab and then the Status tab on which you can view device data.

    The following figure shows the status of the LightSensor device.

    Status of the LightSensor device

    The following figure shows the status of the Light device.

    Status of the Light device

After you perform the preceding steps, the devices are connected to the sample drivers. For more information about official drivers and driver development, see Official drivers and Develop drivers. For more information about business logic and frameworks, see Edge applications and Scene orchestration.