WebSocket driver
IoT Edge provides drivers to connect devices that use the WebSocket communication protocol. IoT Edge offers a variety of WebSocket drivers for different gateway device architectures. You can deploy WebSocket drivers directly from the console to your gateway.
To connect a device using a WebSocket driver, you must follow the IoT Edge WebSocket access protocol. For more information, see IoT Edge Device Access Protocol (WebSocket Edition).


This topic provides an example of how to use the official WebSocket driver.
Prerequisites
An edge instance is created and a gateway is connected to Link IoT Edge. For more information, see Set up environments.
Step 1: Assign the driver
- Log on to the Link IoT Edge console.
- 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.
- On the Instance Details page, click the
+icon next to Devices & Drivers. - In the Assign Driver panel, select Official Drivers. Find the WebSocket driver that matches your gateway's CPU architecture and click Assign in the Actions column. Then, click Close.Note The WebSocket driver is supported only on IoT Edge v2.0.0 and later.

Step 2: Configure the driver
- Click the assigned WebSocket driver. On the page that appears, click Driver Configuration to the right of the Device ListSet the parameters as required and then click OK.

Table 1. Parameter description Parameter Description IP address The listening IP address for the WebSocket driver. The default value is the IP address of the machine where the driver is located. Port number The listening port for the WebSocket driver. The value ranges from 1 to 65535. The default port is 17682. Enable encryption Specifies whether to use TLS encryption. By default, encryption is disabled. If you select Yes, you must upload a public key file and a private key file. - Public key file: Upload the public key certificate file. The file must be in .cer format. The file name cannot contain Chinese characters.
- Private key file: Upload the private key file. The file must be in .pvk format. The file name cannot contain Chinese characters.
- Optional. On the right side of Devices, click Container Configurations. On the Container Configurations page, configure the container for the driver based on the parameters that are described in the following table. 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 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.
Step 3: Associate the driver with a sub-device
- In the Device List area, click Assign Sub-device to assign a sub-device to the edge instance.You can assign an existing WebSocket device or create a new one.
- In the Assign Sub-device panel, click Add Sub-device.

- In the Add Device dialog box, click New Product to create a product for the WebSocket device.

- In the Create Product dialog box, set the parameters and then click Done.

Table 2. Parameter description Parameter Description Product Name Set a name for the product. The product name must be unique within your account. The name can contain letters, digits, underscores (_), hyphens (-), at signs (@), and parentheses (()). It must be 4 to 30 characters in length. Category Select a category to define a Thing Specification Language model for the product. In this example, select Custom Category. Gateway Protocol You must select Custom. Authentication Method Select an authentication method suitable for your device. For more information, see Device security authentication. Product Description Add a description for the product. This can be empty. (Maximum 100 characters.) - In the Add Device dialog box, enter a DeviceName for the WebSocket device.
- Assign the newly created WebSocket device to the edge instance.
- After you assign the device, click Device Configuration in its Actions column to associate it with the WebSocket driver.

Device IP: The IP address of the connected device or its gateway.
Note If you configure this parameter, IoT Edge validates the IP address. Connections for this device will be accepted only from the specified IP address.
Step 4: Deploy the edge instance
On the Instance Details page, click Deploy in the upper-right corner to redeploy the instance.


