Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
qcloud-iotexplorer-appdev-plugin-wificonf-blecombo
Advanced tools
腾讯云物联网开发平台应用开发小程序端WIFI配网方式之蓝牙辅助配网(BLE-combo) SDK
腾讯云物联网开发平台应用开发小程序端WIFI配网方式之蓝牙辅助配网(BLE-combo) SDK
npm install qcloud-iotexplorer-appdev-sdk
npm install qcloud-iotexplorer-appdev-plugin-wificonf-core
npm install qcloud-iotexplorer-appdev-plugin-wificonf-blecombo
就像其他配网方式那样,我们首先要向 appdev-sdk 里面注册 blecombo 插件,appdev-sdk 的初始化方式,详见qcloud-iotexplorer-appdev-sdk,这里不再赘述
import BleComboPlug from 'qcloud-iotexplorer-appdev-plugin-wificonf-blecombo';
BleComboPlug.install(sdk);
在这一步,需要使用表单来让用户填入WI-FI的 SSID 和 password 信息,以供后续配网使用。
在配网正式开始前,我们还需要先完成手机和设备的蓝牙连接,并获得一个 deviceAdapter 来向设备传递WI-FI和token数据。主要分为以下几步:
bluetoothAdapter 可以用来搜索设备,连接到设备。代码如下:
import { BleComboEspDeviceAdapter, BleComboLLSyncDeviceAdapter } from 'qcloud-iotexplorer-appdev-plugin-wificonf-blecombo';
import { BlueToothAdapter } from 'qcloud-iotexplorer-bluetooth-adapter';
export const bluetoothAdapter = new BlueToothAdapter({
deviceAdapters: [
BleComboEspDeviceAdapter,
BleComboLLSyncDeviceAdapter,
],
});
通过 bluetoothAdapter.startSearch方法,我们可以发现设备,获得设备列表。
const serviceIds = [BleComboLLSyncDeviceAdapter.serviceId];
await bluetoothAdapter.startSearch({
ignoreDeviceIds,
serviceIds,
ignoreServiceIds,
onError: (error) => {
console.log('----error', error);
// 搜索设备出错
bluetoothAdapter.stopSearch();
},
onSearch: (devices) => {
console.log('searched devices', devices);
if (devices.length > 0) {
console.log('找到设备', devices); // 此时可以在页面上展示
}
},
timeout: 1.4 * 15 * 1000,
});
在上面的 onSearch 回调函数中,我们可以获得搜寻到的设备列表,这时可以将设备列表展示到页面上,供用户选择要连接哪个设备。
用户从上面获取到的设备中选择一个,并发起连接操作时,可以调用 bluetoothAdapter.connectDevice
方法进行连接。连接成功后会返回一个 deviceAdapter,可以用来向连接的设备发送Wi-Fi,token等数据。
try {
// device参数是上一步获取的devices中的某一个item
const deviceAdapter = await bluetoothAdapter.connectDevice(device);
if (!deviceAdapter) {
throw {
code: 'CONNECT_ERROR',
};
}
} catch (err) {
console.error('连接到设备出错');
}
在上面三步完成之后,我们已经通过蓝牙连接到了设备,并获得了可以更设备通信的 deviceAdapter,接下来就可以正式进行配网了。
接下来我们开始蓝牙辅助配网
// 这里可以进行一些UI进度更新操作
const onStepChange = (progress) => {
console.log(progress);
}
// 这里是配网进行过程中的回调函数
const onProgress = (data) => {
console.info(data.code, data.detail);
switch (data.code) {
case WifiConfStepCode.PROTOCOL_START: // 开始配网
onStepChange(1);
break;
case WifiConfStepCode.PROTOCOL_SUCCESS: // 设备联网成功,设备可以访问互联网
onStepChange(2);
break;
case WifiConfStepCode.BUSINESS_QUERY_TOKEN_STATE_SUCCESS: // 发送token到设备成功
break;
case WifiConfStepCode.WIFI_CONF_SUCCESS: // 配网成功
onStepChange(4);
break;
}
};
const onComplete = ({ productId, deviceName }) => {
// 配网成功后,可以拿到设备的 productId 和 设备名称
console.log('配网成功', productId, deviceName);
};
const onError = async ({ code, detail }) => {
console.error('配网出错', code, detail);
};
const config = {
wifiConfToken, // 用于设备连接云端的token
targetWifiInfo: { // 用于设备联网的wifi信息,由用户填入
SSID: '你的Wi-Fi名称',
password: '你的Wi-Fi密码',
BSSID: '',
},
wifiConfType: 'ble', // 'ble' | 'llsyncble'
deviceAdapter, // 由连接设备之后获得
familyId: 'default',
roomId,
onProgress, // 用来更新页面的进度条
onError,
OnComplete,
}
// 开始执行配网逻辑 go!
sdk.plugins['wifiConfBleCombo'].start(config);
关于 bluetoothAdapter 的 api 更多介绍,请参考 https://github.com/tencentyun/qcloud-iotexplorer-bluetooth-adapter
FAQs
腾讯云物联网开发平台应用开发小程序端WIFI配网方式之蓝牙辅助配网(BLE-combo) SDK
The npm package qcloud-iotexplorer-appdev-plugin-wificonf-blecombo receives a total of 6 weekly downloads. As such, qcloud-iotexplorer-appdev-plugin-wificonf-blecombo popularity was classified as not popular.
We found that qcloud-iotexplorer-appdev-plugin-wificonf-blecombo demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.