The content of this page has been automatically translated by AI. If you encounter any problems while reading, you can view the corresponding content in Chinese.

Calling H5 SDK Capabilities

Last updated: 2026-04-07 15:08:26

Support for Importing the SDK for HTML5

Directly access through Windows.
window.h5PanelSdk;
Or configure externals in webpack.
// webpack.config.js
module.exports = {
externals: {
'qcloud-iotexplorer-h5-panel-sdk': 'h5PanelSdk',
},
};

Retrieve Basic Parameters

H5 SDK provides basic parameters such as product information, device data, user information, and family information for use by the H5 panel and can be obtained through sdk.attribute name. For specific parameter list, see Basic Parameters.
console.log(sdk.deviceId);

Call the Application-Side API

For information about the application-side API, see Application-side API Introduction.
The calling procedure of the application-side API by the H5 SDK has been encapsulated. When sending a request, common parameters AccessToken and RequestId will be automatically included. The following example code takes calling the application-side API of Obtain Current Device Status as an example.
const action = 'AppGetDeviceStatuses'; // Action name for requesting application side API
const params = { // Parameters for requesting application side API
DeviceIds: [sdk.deviceId]
};
sdk.requestTokenApi(action, params).then(data = > {
// Request successful
console.log(data);
}).catch(err = > {
//Request failed
console.error(err);
});


Control Device

Calling the Control Device Attributes API of the H5 SDK can initiate control operations on the specified device.
// Attribute data of the device to be controlled
const deviceData = {
light_switch: 0
};

// Control the current device of the H5 panel
sdk.controlDeviceData(deviceData).then(data = > {
// Request successful
console.log(data);
}).catch(err = > {
//Request failed
console.error(err);
});

// Control the specified device
const deviceId = 'The ID of the device to control';
sdk.controlDeviceData(deviceData, deviceId).then(data = > {
// Request successful
console.log(data);
}).catch(err = > {
//Request failed
console.error(err);
});


Firmware Upgrade

The SDK encapsulates the API for checking firmware updates, as well as a firmware upgrade prompt with a default style. Developers can check if there is an upgrade for the device's firmware currently and perform firmware upgrade operations by calling the interface provided by the H5 SDK.

Check Firmware Upgrade

Call the Check if the Device Has an Upgradeable Firmware API of the H5 SDK to check if the specified device has an upgradeable firmware. Developers can directly use the default-style firmware upgrade prompt provided by the H5 SDK, or they can use the returned value of this API to implement a custom firmware upgrade prompt. Details are as follows.
Method one: Use the firmware upgrade prompt with the default style provided by the H5 SDK Perform the following command to call sdk.checkFirmwareUpgrade.
sdk.checkFirmwareUpgrade();
If the current device has an upgradable firmware and the device is online, a default-style firmware upgrade prompt will pop up.


Method two: Use a custom firmware upgrade prompt When calling sdk.checkFirmwareUpgrade, if the silent parameter value is set to true, the above default style firmware upgrade prompt will not pop up. Developers can use the firmware upgrade information returned by the API to display a custom firmware upgrade prompt. Among them, CurrentVersion is the current firmware version of the device, and DstVersion is the upgradable firmware version.
sdk.checkFirmwareUpgrade({
silent: true // If the silent parameter is true, the default firmware upgrade prompt of the H5 SDK will not pop up.
}).then(({ CurrentVersion, DstVersion }) = > {
if (DstVersion && CurrentVersion !== DstVersion) {
// Developers need to implement the display of custom firmware upgrade prompts here.
}
});

Performing Firmware Upgrade

Call the Perform Firmware Upgrade interface of the H5 SDK to perform firmware upgrade on the specified device. After calling this API, you will be redirected to the firmware upgrade page of the mini program to perform the firmware upgrade operation.
// Perform firmware upgrade on the current device
sdk.goFirmwareUpgradePage();

// Perform firmware upgrade on the specified device
sdk.goFirmwareUpgradePage({
deviceId: 'The ID of the device to perform firmware upgrade'
});


Long Connection Communication

The H5 SDK automatically connects to the WebSocket server by default during initialization and subscribes to the report data and status information of the current device.
// Listen for device-reported data push
sdk.on('wsReport', ({ deviceId, deviceData }) = > {
console.log('websocket device report', deviceId, deviceData);
});

// Listen for device online status change push
sdk.on('wsStatusChange', ({ deviceId, deviceStatus }) = > {
console.log('websocket device status change', deviceId, deviceStatus);
});

// Listen for device control push
sdk.on('wsControl', ({ deviceId, deviceData }) = > {
console.log('websocket device control', deviceId, deviceData);
});


Device Details

The H5 SDK provides developers with two kinds of device details pages, which developers can choose to use as needed.
Standard device details: Navigate to the device details page in the standard panel of the mini program.
H5 Custom Device Details: Show the device details page within the H5 panel, and add custom menus and buttons on the basis of the standard device details.

Calling Standard Device Details

After executing the following code, you will be navigated to the device details page in the standard panel of the mini program.
sdk.goDeviceDetailPage();

Calling H5 Custom Device Details

After executing the following code, the device details page will be shown in the H5 panel. For the description of API parameters for H5 custom device details, see Show H5 Custom Device Detail View.
sdk.showDeviceDetail({
labelWidth: 120, // Label width of device detail
margin-top: 8, // Padding-top of device detail
shareParams: { // Parameters for custom share when sharing devices
a: 'a',
b: 'b',
},
extendItems: [
{
labelIcon: 'https://main.qcloudimg.com/raw/be1d876d55ec2479d384e17c94****e69.svg',
label: 'custom menu'
content: 'Custom menu content (optional)'
onClick: () => console.log('Click custom menu')
},
],
extendButtons: [
{
text: 'Custom button'
type: 'warning',
onClick: () => console.log('click Custom button')
},
{
text: 'Custom button 2'
type: 'primary',
onClick: () => console.log('click Custom button 2')
},
{
text: 'Get custom share parameters'
onClick: async () = > {
const shareParams = await sdk.getShareParams();
console.log('Custom share parameters: ', shareParams);
}
},
{
text: 'Hide device detail',
type: '',
onClick: () = > sdk.hideDeviceDetail(),
},
],
});

Sub-Device Using Gateway Panel

The platform supports setting the panel configuration of the gateway to take effect on all subproducts. Once enabled, the subproducts under the gateway will use the panel configuration of the gateway. The configuration steps are as follows:
1. Log in to Tencent Cloud and enter the IoT Explorer console, select a project and a gateway product, and enter the product detail page of the gateway product.
2. Select Interactive Development > Panel Configuration, click Configure, and enter the panel configuration page.



3. Select "H5 Custom Dashboard" from the dashboard type.



4. Turn on the switch for Dashboard Configuration to Take Effect on ALL Sub-products in the gateway subdevice.




Listen for Page Display and Hide Events

The H5 SDK provides page display and hide event callbacks. When the H5 page or mini program switches to the foreground or background, corresponding events will be triggered. Developers can listen to these events and execute their own business logic when corresponding events are triggered.
// Listen for the H5 page to move to the foreground
sdk.on('pageShow', () = > {
console.log('on pageShow');
});

// Listen for the H5 page to switch to the background
sdk.on('pageHide', () = > {
console.log('on pageHide');
});

// Listen for the mini program to move to the foreground
sdk.on('appShow', () = > {
console.log('on appShow');
});

// Listen for the mini program to switch to the background
sdk.on('appHide', () = > {
console.log('on appHide');
});

// When the H5 page switches to the foreground, refresh the device name of the page title
sdk.on('pageShow', async () = > {
const deviceInfo = await sdk.getDeviceInfo();

// Device display name
const deviceDisplayName = deviceInfo.AliasName || sdk.productInfo.Name;
// Update page title
window.document.title = deviceDisplayName;
});


Bluetooth Device Communication

H5 panels cannot directly call the Bluetooth API of mini programs. The H5 SDK has encapsulated the Bluetooth protocol communication mechanism between the H5 panel and the mini program. To use Bluetooth communication capabilities in the H5 panel, you must use the Bluetooth module provided by the H5 SDK. For H5 panel development related to Bluetooth devices, please see Bluetooth Device Documentation.