qcloud-iotexplorer-appdev-plugin-wificonf-airkiss
v3.0.117
Published
腾讯云物联网开发平台应用开发小程序端WIFI配网方式之Airkiss SDK
Downloads
250
Keywords
Readme
qcloud-iotexplorer-appdev-plugin-wificonf-airkiss
腾讯云物联网开发平台应用开发小程序端WIFI配网方式之Airkiss SDK
安装依赖
npm install qcloud-iotexplorer-appdev-sdk
npm install qcloud-iotexplorer-appdev-plugin-wificonf-core
安装SDK
npm install qcloud-iotexplorer-appdev-plugin-wificonf-airkiss
使用
step1.向 sdk 里面注册 airkiss 插件,sdk 的初始化方式参考文档qcloud-iotexplorer-appdev-sdk
import AirKissPlug from 'qcloud-iotexplorer-appdev-plugin-wificonf-airkiss';
sdk.usePlugin(AirKissPlug);
step2.开始airkiss配网,配网流程详见官方文档
import { constants as WifiConfConstants } from 'qcloud-iotexplorer-appdev-plugin-wificonf-core';
const {
MpStatType, MyStatDimension, WifiConfErrorMsg, WifiConfStepCode,
} = WifiConfConstants;
/**
* airkiss一键配网
*/
export function AirKissConfigure({
token,
wifiInfo = {
SSID: '';
password: '';
BSSID: '';
},
familyId = 'default',
roomId,
reporter,
onStepChange,
onStatusChange,
}) {
const onProgress = (data) => {
reporter.info(data.code, data.detail);
switch (data.code) {
case WifiConfStepCode.PROTOCOL_SUCCESS:
onStepChange(1);
break;
case WifiConfStepCode.CREATE_UDP_CONNECTION_SUCCESS:
onStepChange(2);
break;
case WifiConfStepCode.BUSINESS_QUERY_TOKEN_STATE_SUCCESS:
onStepChange(3);
break;
case WifiConfStepCode.WIFI_CONF_SUCCESS:
onStepChange(4);
break;
}
};
const onComplete = ({ productId, deviceName }) => {
onStatusChange({
status: 'success',
productId,
deviceName,
});
};
const onError = async ({ code, detail }) => {
reporter.error(code, detail);
onStatusChange({ status: 'error' });
};
sdk.plugins['wifiConfAirKiss'].start({
wifiConfToken: token,
targetWifiInfo: wifiInfo,
autoRetry: true, // 自动处理故障流程
familyId,
roomId,
onProgress,
onComplete,
onError
});
}