IoT Edge provides two sample drivers: Light and LightSensor. These drivers help you quickly learn how to use the driver feature.
The Light driver is a simulated smart light driver provided by IoT Edge. It simulates a light device and supports on/off operations.
The LightSensor driver is a simulated light sensor driver provided by IoT Edge. It simulates a light sensor device and reports light intensity data at regular intervals.
Prerequisites
You have created an edge instance and published the gateway. For more information, see Set up the environment.
How to Use the Sample Driver
- Log on to the IoT Edge console.
- In the navigation pane on the left, click Edge Instances. In the Operation column of the edge instance that you created, click View.
- Assign drivers and sub-devices to the edge instance.
- On the Instance Details page, on the Devices & Drivers tab, click the
+icon to the right of All Drivers. Select Official Driver and assign the Light driver to the edge instance.
- (Optional) On the Light driver page, click Driver Configuration to the right of Device List to configure the driver. After you complete the configuration, click OK.This configuration is not required for this example.

Table 1. Driver configuration parameters Parameter Description Configuration format The configuration format can be one of the following: - Key-value pairs
- JSON format
- Configuration file
Key-value pair table Configuration format is set to Key-value pairs. Click Add Configuration and set Configuration Name, Value, and Comment to configure the driver.
You can add up to 100 key-value pairs.
Configuration content Configuration format is set to JSON format. Enter the configuration content in JSON format. The content size cannot exceed 1 KB. The system automatically validates the format as you type. If the format is incorrect, follow the system prompts to correct it.
Upload configuration file Configuration format is set to Configuration file. You must create a configuration file on your local machine and upload it. For information about how to create a configuration file, see Driver encoding.
- (Optional) To the right of Device List, click Container Configuration to configure the container for the driver. After you complete the configuration, click Save.Note The Container configuration option is available only for Professional EditionProfessional Edition
Parameter Description Use Host Network Specifies whether to isolate the container's network and use the host network environment directly. - Yes: The container's network is not isolated. The host network is used directly.
- No: The container's network is isolated. You must configure Port Mapping.
Port Mapping This parameter appears when Use Host Network is set to No. The network environment of the function is completely isolated from the host environment. Through port mapping, you can map the listening port of the function in the container to a port on the host. This allows client programs on different hosts to access the service provided by the function. You can map up to 10 network ports. For example, the
fc-http-serverfunction runs in a container on the host and provides services on port 80. In this case, client programs on other hosts cannot access thefc-http-serverfunction by accessing port 80 of the host. Therefore, you need to map the container port of thefc-http-serverfunction to a port on the host. For example, map port 80 in the container to port 8080 on the host. This allows client programs on other hosts to access thefc-http-serverfunction in the container by accessingHost IP address:8080.Enable Privileged Mode The root user in a container is actually a regular user on the host. To perform operations that require root permissions inside the container, such as modifying the system time or using the mount command, you must grant the container privileged mode.
Note In privileged mode, the container has root permissions on the host. All host devices are mapped to the container by default. You do not need to configure Device Mapping.Device Mapping This parameter appears when Enable Privileged Mode is set to No. The device management system is completely isolated from the host environment. When a function needs to access a host device, such as a serial port, you must map the device to the container where the function runs. You can add up to 10 device mappings. Volume Mapping The file system is completely isolated from the host environment. When a function needs to access a host file, you must map the file to the container where the function runs. You can add up to 10 volume mappings. Memory Limit Set the maximum memory for the container. - If the container's memory usage exceeds the limit, the container is restarted.
- If the memory limit is too small, the application in the container may fail to run.
The default memory is 1024 MB. Increase the memory limit based on the size of the application in the container.
- Click Assign Sub-device to assign a sub-device to the edge instance under the Light driver.
In the Assign Sub-devices panel, click the Add Sub-device button.
- In the Add Device dialog box, click Create Product to create a Living Room Light product.
In the Create Product dialog box, set the parameters and click Done.
Table 2. Parameter description Parameter Description Product Name Set this to Living Room Light. Category Select a category to define a Thing Specification Language model for the product. For this example, select . Gateway Protocol For this example, select Custom. Authentication Method Select an authentication method for your device. For more information, see Device security and authentication. - In the Add Device dialog box, the Living Room Light product that you created is automatically selected for the Product parameter. Enter Light for DeviceName and click OK.

- In the Assign Sub-device panel, assign the Light device under the Living Room Light product to the edge instance.

- Repeat the preceding steps to assign the official LightSensor sample driver to the edge instance. Then, create a Light Sensor product and a device named LightSensor under this driver. The parameters for creating the light sensor product are as follows.
Parameter Description Product Name Set to Light Sensor. Category For this example, select . You have now assigned the LightSensor and Light devices to the edge instance.
- (Optional) After you assign a device to the edge instance, you can click Device Configuration in the Operation column for the device to configure its settings. For example, you can configure the device serial number. This allows the driver to process information for the specified device. This configuration is not required for this example.

Enter the configuration content in JSON format. The content size cannot exceed 1 KB. Click Validate Format. After the format is validated, click OK to complete the configuration.
- On the Instance Details page, on the Devices & Drivers tab, click the
- Deploy the edge instance.Instance DetailsDeployOKOn the page, click in the upper-right corner. In the confirmation dialog box that appears, click to deploy the edge instance.
You can track the progress and results of the deployment in the Deployment Process section.
- Check the device status.After you deploy the instance, on the Devices and Drivers tab, click All Drivers. The Light and LightSensor devices are displayed as Online in the Device List

- View the device running status.In the Operation column for the LightSensor and Light devices, click View. You are redirected to the Device Details page in the IoT Platform console. Select to confirm that the device data has been sent to the cloud.
The running status of the LightSensor device is shown in the following figure.

The running status of the Light device is shown in the following figure.

You have now connected devices using the sample drivers. For more information about official drivers and driver development, see Official drivers and Driver development. For more information about developing business logic and running frameworks, see Edge applications, Scene orchestration, and Stream analytics.






