import {
getSetting,
authorize,
startWifi,
getWifiList,
onGetWifiList
} from 'aiot-smc-ble-sdk';
try {
// 弹窗授权
const { authSetting } = await getSetting();
console.log(authSetting);
if (!authSetting['scope.userLocation']) {
await authorize({ scope: 'scope.userLocation' });
}
await startWifi();
// 发起Wi-Fi查询
await getWifiList();
} catch (error) {
console.log('err', error);
}
// 监听Wi-Fi列表获取
onGetWifiList((wifiList: WifiInfo[]) => {
console.log(wifiList);
})
// 关闭监听
offGetWifiList(fn)
import ScmBleSdk, { ConnectStatusMap } from '@ali/aiot-smc-ble-sdk';
const bleSdk = new ScmBleSdk();
bleSdk.startConnect({
ssid: 'ilop-fe',
password: '12345678',
userid: '-1', // 一方音箱是精灵ID,生态设备固定传 -1
token: 'ZEzUDO'
});
enum ConnectStatus = {
PENDING = 1, // 初始状态
SCAN = 2, // 扫描
CONNECTED = 3, // 已连接
SEND = 4, // 发送数据给数据
SUCCESS = 8, // 配网成功
ERROR = 9 // 配网失败
}
bleSdk.onConnectStatusChange(fn) // or bleSdk.on('connectStatusChange', fn);
bleSdk.offConnectStatusChange(fn) // or bleSdk.ff('connectStatusChange', fn);