0.1.5 • Published 2 years ago

aiot-smc-ble-sdk v0.1.5

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

快速使用

获取wifi列表

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);
0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago