htc 1 день назад
Родитель
Сommit
b9a07d531f
4 измененных файлов с 1905 добавлено и 1168 удалено
  1. 408 309
      pagesMy/wifiSearch.vue
  2. 14 13
      pagesMy/wifiSet.vue
  3. 847 0
      utils/blufi/xBlufi-wx-impl - 副本.js
  4. 636 846
      utils/blufi/xBlufi-wx-impl.js

+ 408 - 309
pagesMy/wifiSearch.vue

@@ -1,311 +1,410 @@
-<template>
-	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
-		<cus-header title='配置网络'></cus-header>
-		<template v-if="!nodevice">
-			<div class="search adffcac">
-				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/379c752c-13f5-4668-9977-e8cad9cd0fa4.gif"></image>
-				<p>正在搜索可配网设备</p>
-			</div>
-		</template>
-		<template v-else>
-			<div class="empty adffcac">
-				<div class="title">搜索超时</div>
-				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/5824159f-0bd8-4399-be6c-7d309e2a35dc.png"></image>
-				<div class="tip">没有找到可用设备?</div>
-				<div class="warn adfac" @tap="alertShow=true">
-					<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/19ca1b06-9bfd-4ae6-9c1c-eec45a86f0a0.png"></image>
-					<span>找不到设备怎么办 ></span>
-				</div>
-			</div>
-		</template>
-		<div class="zt_btn" v-if="nodevice" @tap="searchAgain">再次搜索</div>
-		<u-popup :show="alertShow" :round="56" mode="center" @close="alertShow=false">
-			<div class="alert">
-				<div class="title">找不到设备怎么办</div>
-				<p style="margin-top: 53rpx;">1.请确保可配网的设备在手机旁边</p>
-				<p>2.如果没有开机,请先按住开关键直到指示灯亮起</p>
-				<p>3.开机状态下,按配网键1次进入配网模式</p>
-				<div class="btn" @tap="alertShow=false">我知道了</div>
-			</div>
-		</u-popup>
-		<u-popup :show="show" :round="64" mode="bottom" @close="show=false">
-			<div class="connect adffcac">
-				<div class="title">找到一个待配网的设备</div>
-				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/6f06a2de-5d6c-4596-9a0c-77971d6ea230.png"></image>
-				<div class="tip">序列号:{{lanya.deviceId}}</div>
-				<div class="btn" @tap="connectWiFi">连接</div>
-			</div>
-		</u-popup>
-	</view>
-</template>
-
+<template>
+	<view class="page" :style="{'min-height':h+'px', 'padding-top':mt+'px'}">
+		<cus-header title='配置网络'></cus-header>
+		<template v-if="!nodevice">
+			<div class="search adffcac">
+				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/379c752c-13f5-4668-9977-e8cad9cd0fa4.gif"></image>
+				<p>正在搜索可配网设备</p>
+			</div>
+		</template>
+		<template v-else>
+			<div class="empty adffcac">
+				<div class="title">{{ emptyState.title }}</div>
+				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/5824159f-0bd8-4399-be6c-7d309e2a35dc.png"></image>
+				<div class="tip">{{ emptyState.tip }}</div>
+				<div class="warn adfac" @tap="alertShow=true">
+					<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/19ca1b06-9bfd-4ae6-9c1c-eec45a86f0a0.png"></image>
+					<span>找不到设备怎么办 ></span>
+				</div>
+			</div>
+		</template>
+
+		<div class="zt_btn" v-if="nodevice" @tap="searchAgain">再次搜索</div>
+
+		<u-popup :show="alertShow" :round="56" mode="center" @close="alertShow=false">
+			<div class="alert">
+				<div class="title">找不到设备怎么办</div>
+				<p style="margin-top: 53rpx;">1.请确保可配网的设备在手机旁边</p>
+				<p>2.如果没有开机,请先按住开关键直到指示灯亮起</p>
+				<p>3.开机状态下,按配网键1次进入配网模式</p>
+				<div class="btn" @tap="alertShow=false">我知道了</div>
+			</div>
+		</u-popup>
+
+		<u-popup :show="show" :round="64" mode="bottom" @close="show=false">
+			<div class="connect adffcac">
+				<div class="title">找到一个待配网的设备</div>
+				<image src="https://transcend.ringzle.com/xiaozhi-app/profile/2025/06/04/6f06a2de-5d6c-4596-9a0c-77971d6ea230.png"></image>
+				<div class="tip">序列号:{{lanya.deviceId}}</div>
+				<div class="btn" @tap="connectWiFi">连接</div>
+			</div>
+		</u-popup>
+	</view>
+</template>
+
 <script>
-	var xBlufi = require("@/utils/blufi/xBlufi.js");
-	let _this = null;
-	export default {
-		data(){
-			return {
-				nodevice:false,
-				show:false,
-				alertShow:false,
-				lanya:null,
-				devicesList: [],
-				searching: false,
-				type:''
-			}
-		},
-		onShow() {
-			this.nodevice = false;
-			this.show = false;
-			this.alertShow = false;
-			this.lanya = null;
-			this.devicesList = [];
-			this.searching = false;
-			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
-			this.Search();
-			xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
-		},
-		onLoad: function(option) {
-			this.type = option.type || '';
-			_this = this;
-		},
-		onUnload() {
-			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
-		},
-		methods:{
-			funListenDeviceMsgEvent: function(options) {
-				switch (options.type) {
-					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
-						console.log(options,'TYPE_STATUS_CONNECTED')
-						break;
-					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
-						if (options.result)
-							_this.devicesList = options.data;
-							let ly = _this.devicesList.find(d=>d.name.indexOf('cx-')>-1);
-							if(!ly) ly = _this.devicesList.find(d=>d.name.indexOf('BLUFI_DEVICE')>-1);
-							if(ly){
-								console.log(ly,'找到设备')
-								xBlufi.notifyStartDiscoverBle({
-									'isStart': false
-								})
-								_this.lanya = ly;
-								_this.nodevice = false;
-								_this.show = true;
-							}
-						break;
-					case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
-						if (options.result) {
-							wx.hideLoading()
-							wx.showToast({
-								title: '连接成功',
-								icon: 'none'
-							})
-							console.log(options.data,'连接成功')
-							wx.navigateTo({
-								url: '/pagesMy/wifiSet?deviceId=' + options.data.deviceId + '&name=' + options
-									.data.name+ '&type=' + _this.type
-							});
-						} else {
-							wx.hideLoading()
-							wx.showModal({
-							  title: '连接失败',
-							  content: '请检查:\n1.设备是否离手机太远;\n2.设备是否已被其他手机连接;\n3.请尝试重启设备后再试。',
-							  showCancel: false
-							});
-						}
-						break;
-					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
-						if (!options.result) {
-							wx.showToast({
-								title: '蓝牙未开启',
-								icon: 'none'
-							})
-						} else {
-							//蓝牙搜索开始
-							_this.searching = true;
-						}
-						break;
-					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
-						if (options.result) {
-							//蓝牙停止搜索ok
-							console.log('蓝牙停止搜索ok')
-						} else {
-							//蓝牙停止搜索失败
-							console.log('蓝牙停止搜索失败')
-						}
-						_this.searching = false;
-						break;
-				}
-			},
-			Search: function() {
-				if (this.searching) {
-					xBlufi.notifyStartDiscoverBle({
-						'isStart': false
-					})
-				} else {
-					xBlufi.notifyStartDiscoverBle({
-						'isStart': true
-					})
-				}
-			},
-			connectWiFi: function() {
-				xBlufi.notifyConnectBle({
-					isStart: true,
-					deviceId: _this.lanya.deviceId,
-					name:_this.lanya.name
-				});
-				wx.showLoading({
-					title: '连接蓝牙设备中...',
-				})
-			}
-		}
-	}
-</script>
-
-<style scoped lang="less">
-	.page{
-		width: 100%;
-		padding: 0 0 300rpx;
-		background: #FFFFFF;
-		box-sizing: border-box;
-		.search{
-			image{
-				width: 620rpx;
-				height: 620rpx;
-				margin-top: 120rpx;
-			}
-			p{
-				font-family: PingFang-SC, PingFang-SC;
-				font-weight: bold;
-				font-size: 36rpx;
-				color: #111111;
-				line-height: 36rpx;
-				text-align: center;
-				margin-top: 80rpx;
-			}
-		}
-		.empty{
-			.title{
-				font-family: PingFang-SC, PingFang-SC;
-				font-weight: bold;
-				font-size: 36rpx;
-				color: #111111;
-				line-height: 36rpx;
-				text-align: center;
-				margin-top: 158rpx;
-			}
-			&>image{
-				width: 400rpx;
-				height: 366rpx;
-				margin-top: 48rpx;
-			}
-			.tip{
-				font-family: PingFang-SC, PingFang-SC;
-				font-weight: bold;
-				font-size: 32rpx;
-				color: #111111;
-				line-height: 36rpx;
-				text-align: center;
-				margin-top: 53rpx;
-			}
-			.warn{
-				background: rgba(27,80,255,0.06);
-				border-radius: 28rpx;
-				padding: 10rpx 24rpx;
-				margin-top: 48rpx;
-				image{
-					width: 26rpx;
-					height: 26rpx;
-				}
-				span{
-					font-family: PingFangSC, PingFang SC;
-					font-weight: 400;
-					font-size: 26rpx;
-					color: #1B50FF;
-					line-height: 37rpx;
-					margin-left: 8rpx;
-				}
-			}
-		}
-		.zt_btn{
-			width: calc(100% - 120rpx);
-			position: fixed;
-			left: 60rpx;
-			bottom: 201rpx;
-		}
-		
-		.alert{
-			padding: 54rpx 40rpx 0;
-			.title{
-				font-family: PingFang-SC, PingFang-SC;
-				font-weight: bold;
-				font-size: 36rpx;
-				color: #111111;
-				line-height: 36rpx;
-				text-align: center;
-				margin-bottom: 19rpx;
-			}
-			p{
-				font-family: PingFangSC, PingFang SC;
-				font-weight: 400;
-				font-size: 30rpx;
-				color: #111111;
-				line-height: 65rpx;
-				text-align: left;
-				margin-top: 24rpx;
-			}
-			.btn{
-				width: calc(100% - 108rpx);
-				height: 90rpx;
-				background: #D9F159;
-				border-radius: 16rpx;
-				font-family: PingFang-SC, PingFang-SC;
-				font-weight: bold;
-				font-size: 32rpx;
-				color: #252525;
-				line-height: 90rpx;
-				text-align: center;
-				margin: 113rpx 54rpx 0;
-				letter-spacing: 2rpx;
-			}
-		}
-		.connect{
-			padding: 66rpx 40rpx 30rpx;
-			.title{
-				font-family: PingFangSC, PingFang SC;
-				font-weight: 600;
-				font-size: 36rpx;
-				color: #111111;
-				line-height: 36rpx;
-				text-align: center;
-			}
-			image{
-				width: 504rpx;
-				height: 254rpx;
-				margin-top: 37rpx;
-			}
-			.tip{
-				font-family: PingFangSC, PingFang SC;
-				font-weight: 400;
-				font-size: 30rpx;
-				color: #111111;
-				line-height: 36rpx;
-				margin-top: 40rpx;
-			}
-			.btn{
-				width: 100%;
-				height: 90rpx;
-				background: #D9F159;
-				border-radius: 16rpx;
-				font-family: PingFang-SC, PingFang-SC;
-				font-weight: bold;
-				font-size: 32rpx;
-				color: #252525;
-				line-height: 90rpx;
-				text-align: center;
-				margin-top: 101rpx;
-				letter-spacing: 2rpx;
-			}
-		}
-	}
+	var xBlufi = require("@/utils/blufi/xBlufi.js");
+	let _this = null;
+	export default {
+		data() {
+			return {
+				nodevice: false, // 是否未找到设备
+				show: false, // 是否显示连接弹窗
+				alertShow: false, // 是否显示帮助弹窗
+				lanya: null, // 找到的蓝牙设备信息
+				devicesList: [],
+				searching: false, // 是否正在搜索
+				type: '', // 设备类型
+				errorType: '', // 'timeout' 或 'bluetoothOff',用于区分错误类型
+				timeoutTimer: null // 搜索超时定时器
+			}
+		},
+		computed: {
+			// 根据错误类型动态生成提示文案
+			emptyState() {
+				if (this.errorType === 'bluetoothOff') {
+					return {
+						title: '蓝牙未开启',
+						tip: '请检查手机蓝牙是否已开启'
+					};
+				}
+				if (this.errorType === 'timeout') {
+					return {
+						title: '搜索超时',
+						tip: '没有找到可用设备?'
+					};
+				}
+				// 默认情况
+				return {
+					title: '搜索失败',
+					tip: '没有找到可用设备?'
+				};
+			}
+		},
+		onShow() {
+			this.init();
+		},
+		onLoad: function(option) {
+			this.type = option.type || '';
+			_this = this; // 保留页面实例的引用,供回调函数使用
+		},
+		onUnload() {
+			// 页面卸载时,停止监听并清除定时器,防止内存泄漏
+			xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
+			if (this.timeoutTimer) {
+				clearTimeout(this.timeoutTimer);
+				this.timeoutTimer = null;
+			}
+		},
+		methods: {
+			// 初始化页面状态
+			init() {
+				this.nodevice = false;
+				this.show = false;
+				this.alertShow = false;
+				this.lanya = null;
+				this.devicesList = [];
+				this.searching = false;
+				this.errorType = '';
+
+				// 清理上一次的定时器
+				if (this.timeoutTimer) {
+					clearTimeout(this.timeoutTimer);
+					this.timeoutTimer = null;
+				}
+				
+				// 重新注册监听事件并开始搜索
+				xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent); // 先移除旧监听
+				this.Search();
+				xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent); // 再添加新监听
+			},
+			// 再次搜索
+			searchAgain() {
+				this.init();
+			},
+			// 蓝牙事件回调处理
+			funListenDeviceMsgEvent: function(options) {
+				switch (options.type) {
+					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
+						console.log(options, 'TYPE_STATUS_CONNECTED')
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
+						if (options.result && options.data.length > 0) {
+							_this.devicesList = options.data;
+							// 优先查找 'cx-' 前缀的设备,其次是 'BLUFI_DEVICE'
+							let ly = _this.devicesList.find(d => d.name.indexOf('cx-') > -1);
+							if (!ly) ly = _this.devicesList.find(d => d.name.indexOf('BLUFI_DEVICE') > -1);
+
+							if (ly) {
+								console.log(ly, '找到设备');
+								// 找到设备后,清除超时定时器
+								if (_this.timeoutTimer) {
+									clearTimeout(_this.timeoutTimer);
+									_this.timeoutTimer = null;
+								}
+								// 停止蓝牙搜索
+								xBlufi.notifyStartDiscoverBle({
+									'isStart': false
+								});
+								_this.lanya = ly;
+								_this.nodevice = false;
+								_this.show = true;
+							}
+						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED:
+						wx.hideLoading();
+						if (options.result) {
+							wx.showToast({
+								title: '连接成功',
+								icon: 'none'
+							});
+							console.log(options.data, '连接成功');
+							wx.navigateTo({
+								url: '/pagesMy/wifiSet?deviceId=' + options.data.deviceId + '&name=' +
+									options.data.name + '&type=' + _this.type
+							});
+						} else {
+							wx.showModal({
+								title: '连接失败',
+								content: '请检查:\n1.设备是否离手机太远;\n2.设备是否已被其他手机连接;\n3.请尝试重启设备后再试。',
+								showCancel: false
+							});
+						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START:
+						if (!options.result) {
+							// 蓝牙未开启
+							wx.showToast({
+								title: '蓝牙未开启',
+								icon: 'none'
+							});
+							_this.nodevice = true;
+							_this.errorType = 'bluetoothOff'; // 设置错误类型为蓝牙未开启
+						} else {
+							// 蓝牙搜索开始
+							_this.searching = true;
+						}
+						break;
+					case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP:
+						_this.searching = false;
+						if (options.result) {
+							console.log('蓝牙停止搜索ok');
+						} else {
+							console.log('蓝牙停止搜索失败');
+						}
+						break;
+				}
+			},
+			// 开始或停止搜索设备
+			Search: function() {
+				if (this.searching) {
+					xBlufi.notifyStartDiscoverBle({
+						'isStart': false
+					});
+				} else {
+					xBlufi.notifyStartDiscoverBle({
+						'isStart': true
+					});
+					
+					// 启动搜索时,设置一个超时定时器
+					this.timeoutTimer = setTimeout(() => {
+						// 检查15秒后是否仍未找到设备
+						if (!_this.lanya) {
+							xBlufi.notifyStartDiscoverBle({ 'isStart': false }); // 停止搜索
+							_this.nodevice = true;
+							_this.errorType = 'timeout'; // 设置错误类型为超时
+							console.log('搜索超时');
+						}
+					}, 15000); // 设置15秒超时
+				}
+			},
+			// 连接WiFi
+			connectWiFi: function() {
+				wx.showLoading({
+					title: '连接蓝牙设备中...',
+				})
+				xBlufi.notifyConnectBle({
+					isStart: true,
+					deviceId: _this.lanya.deviceId,
+					name: _this.lanya.name
+				});
+			}
+		}
+	}
+</script>
+
+<style scoped lang="less">
+	.page {
+		width: 100%;
+		padding: 0 0 300rpx;
+		background: #FFFFFF;
+		box-sizing: border-box;
+	}
+
+	.search {
+		image {
+			width: 620rpx;
+			height: 620rpx;
+			margin-top: 120rpx;
+		}
+
+		p {
+			font-family: PingFang-SC, PingFang-SC;
+			font-weight: bold;
+			font-size: 36rpx;
+			color: #111111;
+			line-height: 36rpx;
+			text-align: center;
+			margin-top: 80rpx;
+		}
+	}
+
+	.empty {
+		.title {
+			font-family: PingFang-SC, PingFang-SC;
+			font-weight: bold;
+			font-size: 36rpx;
+			color: #111111;
+			line-height: 36rpx;
+			text-align: center;
+			margin-top: 158rpx;
+		}
+
+		&>image {
+			width: 400rpx;
+			height: 366rpx;
+			margin-top: 48rpx;
+		}
+
+		.tip {
+			font-family: PingFang-SC, PingFang-SC;
+			font-weight: bold;
+			font-size: 32rpx;
+			color: #111111;
+			line-height: 36rpx;
+			text-align: center;
+			margin-top: 53rpx;
+		}
+
+		.warn {
+			background: rgba(27, 80, 255, 0.06);
+			border-radius: 28rpx;
+			padding: 10rpx 24rpx;
+			margin-top: 48rpx;
+
+			image {
+				width: 26rpx;
+				height: 26rpx;
+			}
+
+			span {
+				font-family: PingFangSC, PingFang SC;
+				font-weight: 400;
+				font-size: 26rpx;
+				color: #1B50FF;
+				line-height: 37rpx;
+				margin-left: 8rpx;
+			}
+		}
+	}
+
+	.zt_btn {
+		width: calc(100% - 120rpx);
+		position: fixed;
+		left: 60rpx;
+		bottom: 201rpx;
+	}
+
+	.alert {
+		padding: 54rpx 40rpx 0;
+
+		.title {
+			font-family: PingFang-SC, PingFang-SC;
+			font-weight: bold;
+			font-size: 36rpx;
+			color: #111111;
+			line-height: 36rpx;
+			text-align: center;
+			margin-bottom: 19rpx;
+		}
+
+		p {
+			font-family: PingFangSC, PingFang SC;
+			font-weight: 400;
+			font-size: 30rpx;
+			color: #111111;
+			line-height: 65rpx;
+			text-align: left;
+			margin-top: 24rpx;
+		}
+
+		.btn {
+			width: calc(100% - 108rpx);
+			height: 90rpx;
+			background: #D9F159;
+			border-radius: 16rpx;
+			font-family: PingFang-SC, PingFang-SC;
+			font-weight: bold;
+			font-size: 32rpx;
+			color: #252525;
+			line-height: 90rpx;
+			text-align: center;
+			margin: 113rpx 54rpx 0;
+			letter-spacing: 2rpx;
+		}
+	}
+
+	.connect {
+		padding: 66rpx 40rpx 30rpx;
+
+		.title {
+			font-family: PingFangSC, PingFang SC;
+			font-weight: 600;
+			font-size: 36rpx;
+			color: #111111;
+			line-height: 36rpx;
+			text-align: center;
+		}
+
+		image {
+			width: 504rpx;
+			height: 254rpx;
+			margin-top: 37rpx;
+		}
+
+		.tip {
+			font-family: PingFangSC, PingFang SC;
+			font-weight: 400;
+			font-size: 30rpx;
+			color: #111111;
+			line-height: 36rpx;
+			margin-top: 40rpx;
+		}
+
+		.btn {
+			width: 100%;
+			height: 90rpx;
+			background: #D9F159;
+			border-radius: 16rpx;
+			font-family: PingFang-SC, PingFang-SC;
+			font-weight: bold;
+			font-size: 32rpx;
+			color: #252525;
+			line-height: 90rpx;
+			text-align: center;
+			margin-top: 101rpx;
+			letter-spacing: 2rpx;
+		}
+	}
+    /* 公共样式,用于居中 */
+	.adffcac{
+		display: flex;
+		flex-direction: column;
+		align-items: center;
+	}
+	.adfac{
+		display: flex;
+		align-items: center;
+	}
 </style>

+ 14 - 13
pagesMy/wifiSet.vue

@@ -35,9 +35,9 @@
 			<div class="wifis">
 				<div class="top adfacjb">
 					<div class="tl">选择WiFi</div>
-					<div class="tr adfac" @tap="initWiFi">
-						<!-- <image src="@/static/refreash.png"></image>
-						<text>刷新</text> -->
+					<div class="tr adfac" @tap="sxWiFi">
+						<image src="@/static/refreash.png"></image>
+						<text>刷新</text>
 					</div>
 				</div>
 				<div class="list" v-if="wifiList.length">
@@ -116,14 +116,12 @@
 				let ssid_arry = this.wifiList;
 				switch (options.type) {
 					case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
-						console.log(options,'TYPE_STATUS_CONNECTED')
 						that.connected = options.result
 						if (!options.result) {
 							console.log('小程序与设备异常断开')
 						}
 						break;
 					case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT:
-						console.log(options,'TYPE_CONNECT_ROUTER_RESULT')
 						wx.hideLoading();
 						if (this.connectTimeout) {
 							clearTimeout(this.connectTimeout);
@@ -145,7 +143,6 @@
 						}
 						break;
 					case xBlufi.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA:
-						console.log(options.data,'收到自定义设备数据')
 						break;
 					case xBlufi.XBLUFI_TYPE.TYPE_CONNECT_NEAR_ROUTER_LISTS:
 						if (this.wifiListFetchTimeout) {
@@ -209,10 +206,16 @@
 				if (this.wifiListCache.length > 0) {
 					this.wifiList = [...this.wifiListCache];
 					return;
-				}
-
-				wx.showLoading({ title: '获取周围WiFi列表...' });
-
+				}
+				
+				this.sxWiFi();
+			},
+			sxWiFi(){
+				xBlufi.notifySendGetNearRouterSsid()
+				wx.showLoading({
+					title: '获取周围WiFi列表...',
+				})
+				
 				// 获取Wi-Fi列表超时处理
 				this.wifiListFetchTimeout = setTimeout(() => {
 					wx.hideLoading();
@@ -221,9 +224,7 @@
 						content: '获取Wi-Fi列表超时,请重试',
 						showCancel: false
 					});
-				}, 10000);
-
-				xBlufi.notifySendGetNearRouterSsid()
+				}, 10000);
 			},
 			connectWifi(){
 				let that = this;

+ 847 - 0
utils/blufi/xBlufi-wx-impl - 副本.js

@@ -0,0 +1,847 @@
+let tempTimer = 0;
+let client = null;
+let util = null
+let mDeviceEvent = null
+let crypto = null
+let md5 = null
+let aesjs = null
+const timeOut = 20; //超时时间
+var timeId = "";
+let sequenceControl = 0;
+let sequenceNumber = -1;
+
+let _self = {
+  data: {
+    deviceId: null,
+    isConnected: false,
+    failure: false,
+    value: 0,
+    desc: "请耐心等待...",
+    isChecksum: true,
+    isEncrypt: true,
+    flagEnd: false,
+    defaultData: 1,
+    ssidType: 2,
+    passwordType: 3,
+    meshIdType: 3,
+    deviceId: "",
+    ssid: "",
+    uuid: "",
+    serviceId: "",
+    password: "",
+    meshId: "",
+    processList: [],
+    result: [],
+    service_uuid: "0000FFFF-0000-1000-8000-00805F9B34FB",
+    characteristic_write_uuid: "0000FF01-0000-1000-8000-00805F9B34FB",
+    characteristic_read_uuid: "0000FF02-0000-1000-8000-00805F9B34FB",
+    customData: null,
+    md5Key: 0,
+  }
+}
+
+function buf2hex(buffer) {
+  return Array.prototype.map.call(new Uint8Array(buffer), x => ('00' + x.toString(16)).slice(-2)).join('');
+}
+
+function buf2string(buffer) {
+  var arr = Array.prototype.map.call(new Uint8Array(buffer), x => x);
+  var str = '';
+  for (var i = 0; i < arr.length; i++) {
+    str += String.fromCharCode(arr[i]);
+  }
+  return str;
+}
+
+function getSsids(str) {
+  var list = [],
+    strs = str.split(":");
+  for (var i = 0; i < strs.length; i++) {
+    list.push(parseInt(strs[i], 16));
+  }
+  return list;
+}
+
+function getCharCodeat(str) {
+  var list = [];
+  for (var i = 0; i < str.length; i++) {
+    list.push(str.charCodeAt(i));
+  }
+  return list;
+}
+function getCharCodeatSSID(str) {
+  return unescape(encodeURIComponent(str)).split("").map(val => val.charCodeAt());
+}
+
+
+//判断返回的数据是否加密
+function isEncrypt(fragNum, list, md5Key) {
+  var checksum = [],
+    checkData = [];
+  if (fragNum[7] == "1") { //返回数据加密
+    if (fragNum[6] == "1") {
+      var len = list.length - 2;
+      list = list.slice(0, len);
+    }
+    var iv = this.generateAESIV(parseInt(list[2], 16));
+    if (fragNum[3] == "0") { //未分包
+      list = list.slice(4);
+      _self.data.flagEnd = true
+    } else { //分包
+      list = list.slice(6);
+    }
+  } else { //返回数据未加密
+    if (fragNum[6] == "1") {
+      var len = list.length - 2;
+      list = list.slice(0, len);
+    }
+    if (fragNum[3] == "0") { //未分包
+      list = list.slice(4);
+      _self.data.flagEnd = true
+    } else { //分包
+      list = list.slice(6);
+    }
+  }
+  return list;
+}
+
+function getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, data) {
+
+  var obj = [],
+    frameControl = 0;
+  sequenceControl = parseInt(sequenceControl) + 1;
+  if (!util._isEmpty(data)) {
+    obj = util.isSubcontractor(data, true, sequenceControl);
+    frameControl = util.getFrameCTRLValue(false, true, util.DIRECTION_OUTPUT, false, obj.flag);
+  } else {
+    data = [];
+    data.push(util.NEG_SET_SEC_ALL_DATA);
+    var pLength = pBytes.length;
+    var pLen1 = (pLength >> 8) & 0xff;
+    var pLen2 = pLength & 0xff;
+    data.push(pLen1);
+    data.push(pLen2);
+    data = data.concat(pBytes);
+    var gLength = gBytes.length;
+    var gLen1 = (gLength >> 8) & 0xff;
+    var gLen2 = gLength & 0xff;
+    data.push(gLen1);
+    data.push(gLen2);
+    data = data.concat(gBytes);
+    var kLength = kBytes.length;
+    var kLen1 = (kLength >> 8) & 0xff;
+    var kLen2 = kLength & 0xff;
+    data.push(kLen1);
+    data.push(kLen2);
+    data = data.concat(kBytes);
+    obj = util.isSubcontractor(data, true, sequenceControl);
+    frameControl = util.getFrameCTRLValue(false, true, util.DIRECTION_OUTPUT, false, obj.flag);
+  }
+  var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_NEG, frameControl, sequenceControl, obj.len, obj.lenData);
+  var typedArray = new Uint8Array(value);
+  console.log(typedArray)
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+      if (obj.flag) {
+        getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, obj.laveData);
+      }
+    },
+    fail: function (res) {
+      console.log(res)
+      console.log(deviceId)
+      console.log(serviceId)
+      console.log(characteristicId)
+      console.log(typedArray.length)
+    }
+  })
+}
+
+function writeDeviceRouterInfoStart(deviceId, serviceId, characteristicId, data) {
+  var obj = {},
+    frameControl = 0;
+  sequenceControl = parseInt(sequenceControl) + 1;
+  if (!util._isEmpty(data)) {
+    obj = util.isSubcontractor(data, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  } else {
+    obj = util.isSubcontractor([_self.data.defaultData], _self.data.isChecksum, sequenceControl, true);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  }
+  var defaultData = util.encrypt(aesjs, _self.data.md5Key, sequenceControl, obj.lenData, true);
+  var value = util.writeData(util.PACKAGE_CONTROL_VALUE, util.SUBTYPE_WIFI_MODEl, frameControl, sequenceControl, obj.len, defaultData);
+  var typedArray = new Uint8Array(value)
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+      if (obj.flag) {
+        writeDeviceRouterInfoStart(deviceId, serviceId, characteristicId, obj.laveData);
+      } else {
+        writeRouterSsid(deviceId, serviceId, characteristicId, null);
+      }
+    },
+    fail: function (res) {
+    }
+  })
+}
+
+function writeCutomsData(deviceId, serviceId, characteristicId, data) {
+  var obj = {},
+    frameControl = 0;
+  sequenceControl = parseInt(sequenceControl) + 1;
+  if (!util._isEmpty(data)) {
+    obj = util.isSubcontractor(data, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  } else {
+    var ssidData = getCharCodeat(_self.data.customData);
+    obj = util.isSubcontractor(ssidData, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  }
+  var defaultData = util.encrypt(aesjs, _self.data.md5Key, sequenceControl, obj.lenData, true);
+  var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_CUSTOM_DATA, frameControl, sequenceControl, obj.len, defaultData);
+  var typedArray = new Uint8Array(value)
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+      if (obj.flag) {
+        writeCutomsData(deviceId, serviceId, characteristicId, obj.laveData);
+      }
+    },
+    fail: function (res) {
+      //console.log(257);
+    }
+  })
+}
+
+
+function writeGetNearRouterSsid(deviceId, serviceId, characteristicId, data) {
+  sequenceControl = parseInt(sequenceControl) + 1;
+  var frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, false, util.DIRECTION_OUTPUT, false, false);
+  var value = util.writeData(_self.data.PACKAGE_CONTROL_VALUE, util.SUBTYPE_WIFI_NEG, frameControl, sequenceControl, 0, null);
+  var typedArray = new Uint8Array(value)
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+
+    },
+    fail: function (res) {
+
+    }
+  })
+}
+
+
+
+function writeRouterSsid(deviceId, serviceId, characteristicId, data) {
+  var obj = {},
+    frameControl = 0;
+  sequenceControl = parseInt(sequenceControl) + 1;
+  if (!util._isEmpty(data)) {
+    obj = util.isSubcontractor(data, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  } else {
+    // var ssidData = getCharCodeat(_self.data.ssid);
+    var ssidData = getCharCodeatSSID(_self.data.ssid);
+    obj = util.isSubcontractor(ssidData, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  }
+  var defaultData = util.encrypt(aesjs, _self.data.md5Key, sequenceControl, obj.lenData, true);
+  var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_SET_SSID, frameControl, sequenceControl, obj.len, defaultData);
+  var typedArray = new Uint8Array(value)
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+      if (obj.flag) {
+        writeRouterSsid(deviceId, serviceId, characteristicId, obj.laveData);
+      } else {
+        writeDevicePwd(deviceId, serviceId, characteristicId, null);
+      }
+    },
+    fail: function (res) {
+      //console.log(257);
+    }
+  })
+}
+
+function writeDevicePwd(deviceId, serviceId, characteristicId, data) {
+  var obj = {},
+    frameControl = 0;
+  sequenceControl = parseInt(sequenceControl) + 1;
+  if (!util._isEmpty(data)) {
+    obj = util.isSubcontractor(data, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  } else {
+    var pwdData = getCharCodeat(_self.data.password);
+    obj = util.isSubcontractor(pwdData, _self.data.isChecksum, sequenceControl, _self.data.isEncrypt);
+    frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, _self.data.isChecksum, util.DIRECTION_OUTPUT, false, obj.flag);
+  }
+  var defaultData = util.encrypt(aesjs, _self.data.md5Key, sequenceControl, obj.lenData, true);
+  var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_SET_PWD, frameControl, sequenceControl, obj.len, defaultData);
+  var typedArray = new Uint8Array(value)
+
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+      if (obj.flag) {
+        writeDevicePwd(deviceId, serviceId, characteristicId, obj.laveData);
+      } else {
+        writeDeviceEnd(deviceId, serviceId, characteristicId, null);
+      }
+    },
+    fail: function (res) { }
+  })
+}
+
+function writeDeviceEnd(deviceId, serviceId, characteristicId) {
+  sequenceControl = parseInt(sequenceControl) + 1;
+  var frameControl = util.getFrameCTRLValue(_self.data.isEncrypt, false, util.DIRECTION_OUTPUT, false, false);
+  var value = util.writeData(_self.data.PACKAGE_CONTROL_VALUE, util.SUBTYPE_END, frameControl, sequenceControl, 0, null);
+  var typedArray = new Uint8Array(value)
+  wx.writeBLECharacteristicValue({
+    deviceId: deviceId,
+    serviceId: serviceId,
+    characteristicId: characteristicId,
+    value: typedArray.buffer,
+    success: function (res) {
+
+    },
+    fail: function (res) {
+
+    }
+  })
+}
+
+function init() {
+
+  let mOnFire = require("./other/onfire.js");
+  mDeviceEvent = require('./xBlufi.js');
+
+  util = require('@/utils/blufi/util.js');
+  crypto = require('@/utils/blufi/crypto/crypto-dh.js');
+  md5 = require('@/utils/blufi/crypto/md5.min.js');
+  aesjs = require('@/utils/blufi/crypto/aes.js');
+
+  wx.onBLEConnectionStateChange(function (res) {
+    let obj = {
+      'type': mDeviceEvent.XBLUFI_TYPE.TYPE_STATUS_CONNECTED,
+      'result': res.connected,
+      'data': res
+    }
+    mDeviceEvent.notifyDeviceMsgEvent(obj);
+  })
+
+  mDeviceEvent.listenStartDiscoverBle(true, function (options) {
+
+    if (options.isStart) {
+      //第一步检查蓝牙适配器是否可用
+      wx.onBluetoothAdapterStateChange(function (res) {
+        if (!res.available) {
+
+        }
+      });
+      //第二步关闭适配器,重新来搜索
+      wx.closeBluetoothAdapter({
+        complete: function (res) {
+          wx.openBluetoothAdapter({
+            success: function (res) {
+              wx.getBluetoothAdapterState({
+                success: function (res) {
+                  wx.stopBluetoothDevicesDiscovery({
+                    success: function (res) {
+                      let devicesList = [];
+                      let countsTimes = 0;
+                      wx.onBluetoothDeviceFound(function (devices) {
+                        //剔除重复设备,兼容不同设备API的不同返回值
+                        var isnotexist = true;
+                        if (devices.deviceId) {
+                          if (devices.advertisData) {
+                            devices.advertisData = buf2hex(devices.advertisData)
+                          } else {
+                            devices.advertisData = ''
+                          }
+                          for (var i = 0; i < devicesList.length; i++) {
+                            if (devices.deviceId === devicesList[i].deviceId) {
+                              isnotexist = false
+                            }
+                          }
+                          if (isnotexist) {
+                            devicesList.push(devices)
+                          }
+                        } else if (devices.devices) {
+                          if (devices.devices[0].advertisData) {
+                            devices.devices[0].advertisData = buf2hex(devices.devices[0].advertisData)
+                          } else {
+                            devices.devices[0].advertisData = ''
+                          }
+                          for (var i = 0; i < devicesList.length; i++) {
+                            if (devices.devices[0].deviceId == devicesList[i].deviceId) {
+                              isnotexist = false
+                            }
+                          }
+                          if (isnotexist) {
+                            devicesList.push(devices.devices[0])
+                          }
+                        } else if (devices[0]) {
+                          if (devices[0].advertisData) {
+                            devices[0].advertisData = buf2hex(devices[0].advertisData)
+                          } else {
+                            devices[0].advertisData = ''
+                          }
+                          for (var i = 0; i < devices_list.length; i++) {
+                            if (devices[0].deviceId == devicesList[i].deviceId) {
+                              isnotexist = false
+                            }
+                          }
+                          if (isnotexist) {
+                            devicesList.push(devices[0])
+                          }
+                        }
+
+                        let obj = {
+                          'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS,
+                          'result': true,
+                          'data': devicesList
+                        }
+                        mDeviceEvent.notifyDeviceMsgEvent(obj);
+                      })
+                      wx.startBluetoothDevicesDiscovery({
+                        allowDuplicatesKey: true,
+                        success: function (res) {
+                          let obj = {
+                            'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+                            'result': true,
+                            'data': res
+                          }
+                          mDeviceEvent.notifyDeviceMsgEvent(obj);
+                          //开始扫码,清空列表
+                          devicesList.length = 0;
+
+                        },
+                        fail: function (res) {
+                          let obj = {
+                            'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+                            'result': false,
+                            'data': res
+                          }
+                          mDeviceEvent.notifyDeviceMsgEvent(obj);
+                        }
+                      });
+                    },
+                    fail: function (res) {
+                      let obj = {
+                        'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+                        'result': false,
+                        'data': res
+                      }
+                      mDeviceEvent.notifyDeviceMsgEvent(obj);
+                    }
+                  });
+                },
+                fail: function (res) {
+                  let obj = {
+                    'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+                    'result': false,
+                    'data': res
+                  }
+                  mDeviceEvent.notifyDeviceMsgEvent(obj);
+                }
+              });
+            },
+            fail: function (res) {
+              let obj = {
+                'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_START,
+                'result': false,
+                'data': res
+              }
+              mDeviceEvent.notifyDeviceMsgEvent(obj);
+            }
+          });
+        }
+      });
+    } else {
+      wx.stopBluetoothDevicesDiscovery({
+        success: function (res) {
+          clearInterval(tempTimer);
+          let obj = {
+            'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP,
+            'result': true,
+            'data': res
+          }
+          mDeviceEvent.notifyDeviceMsgEvent(obj);
+        },
+        fail: function (res) {
+          let obj = {
+            'type': mDeviceEvent.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS_STOP,
+            'result': false,
+            'data': res
+          }
+          mDeviceEvent.notifyDeviceMsgEvent(obj);
+        }
+      })
+    }
+  })
+
+
+  mDeviceEvent.listenConnectBle(true, function (options) {
+    //console.log("我要连接?", (options.isStart))
+
+    if (options.isStart)
+      wx.createBLEConnection({
+        deviceId: options.deviceId,
+        success: function (res) {
+          wx.setBLEMTU({
+            deviceId: options.deviceId,
+            mtu: 128
+          })
+          _self.data.deviceId = options.deviceId
+          mDeviceEvent.notifyDeviceMsgEvent({
+            'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED,
+            'result': true,
+            'data': {
+              deviceId: options.deviceId,
+              name: options.name
+            },
+          });
+        },
+        fail: function (res) {
+          _self.data.deviceId = null
+          mDeviceEvent.notifyDeviceMsgEvent({
+            'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECTED,
+            'result': false,
+            'data': res,
+          });
+        }
+      });
+    else wx.closeBLEConnection({
+      deviceId: options.deviceId,
+      success: function (res) {
+        console.log('断开成功')
+        _self.data.deviceId = null
+        mDeviceEvent.notifyDeviceMsgEvent({
+          'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CLOSE_CONNECTED,
+          'result': true,
+          'data': {
+            deviceId: options.deviceId,
+            name: options.name
+          }
+        });
+      },
+      fail: function (res) {
+        _self.data.deviceId = null
+        mDeviceEvent.notifyDeviceMsgEvent({
+          'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CLOSE_CONNECTED,
+          'result': false,
+          'data': res,
+        });
+      }
+    })
+  })
+
+  mDeviceEvent.listenInitBleEsp32(true, function (options) {
+    sequenceControl = 0;
+    sequenceNumber = -1;
+    _self = null
+    _self = {
+      data: {
+        deviceId: null,
+        isConnected: false,
+        failure: false,
+        value: 0,
+        desc: "请耐心等待...",
+        isChecksum: true,
+        isEncrypt: true,
+        flagEnd: false,
+        defaultData: 1,
+        ssidType: 2,
+        passwordType: 3,
+        meshIdType: 3,
+        deviceId: "",
+        ssid: "",
+        uuid: "",
+        serviceId: "",
+        password: "",
+        meshId: "",
+        processList: [],
+        result: [],
+        service_uuid: "0000FFFF-0000-1000-8000-00805F9B34FB",
+        characteristic_write_uuid: "0000FF01-0000-1000-8000-00805F9B34FB",
+        characteristic_read_uuid: "0000FF02-0000-1000-8000-00805F9B34FB",
+        customData: null,
+        md5Key: 0,
+      }
+    }
+    let deviceId = options.deviceId
+    _self.data.deviceId = options.deviceId
+    wx.getBLEDeviceServices({
+      // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
+      deviceId: deviceId,
+      success: function (res) {
+        var services = res.services;
+        if (services.length > 0) {
+          for (var i = 0; i < services.length; i++) {
+            if (services[i].uuid === _self.data.service_uuid) {
+              var serviceId = services[i].uuid;
+              wx.getBLEDeviceCharacteristics({
+                // 这里的 deviceId 需要已经通过 createBLEConnection 与对应设备建立链接
+                deviceId: deviceId,
+                serviceId: serviceId,
+                success: function (res) {
+                  var list = res.characteristics;
+                  if (list.length > 0) {
+                    for (var i = 0; i < list.length; i++) {
+                      var uuid = list[i].uuid;
+                      if (uuid == _self.data.characteristic_write_uuid) {
+                        _self.data.serviceId = serviceId;
+                        _self.data.uuid = uuid;
+                        wx.notifyBLECharacteristicValueChange({
+                          state: true, // 启用 notify 功能
+                          deviceId: deviceId,
+                          serviceId: serviceId,
+                          characteristicId: list[1].uuid,
+                          success: function (res) {
+                            let characteristicId = _self.data.characteristic_write_uuid
+                            //通知设备交互方式(是否加密) start
+                            client = util.blueDH(util.DH_P, util.DH_G, crypto);
+                            var kBytes = util.uint8ArrayToArray(client.getPublicKey());
+                            var pBytes = util.hexByInt(util.DH_P);
+                            var gBytes = util.hexByInt(util.DH_G);
+                            var pgkLength = pBytes.length + gBytes.length + kBytes.length + 6;
+                            var pgkLen1 = (pgkLength >> 8) & 0xff;
+                            var pgkLen2 = pgkLength & 0xff;
+                            var data = [];
+                            data.push(util.NEG_SET_SEC_TOTAL_LEN);
+                            data.push(pgkLen1);
+                            data.push(pgkLen2);
+                            var frameControl = util.getFrameCTRLValue(false, false, util.DIRECTION_OUTPUT, false, false);
+                            var value = util.writeData(util.PACKAGE_VALUE, util.SUBTYPE_NEG, frameControl, sequenceControl, data.length, data);
+                            var typedArray = new Uint8Array(value);
+                            wx.writeBLECharacteristicValue({
+                              deviceId: deviceId,
+                              serviceId: serviceId,
+                              characteristicId: characteristicId,
+                              value: typedArray.buffer,
+                              success: function (res) {
+                                getSecret(deviceId, serviceId, characteristicId, client, kBytes, pBytes, gBytes, null);
+                              },
+                              fail: function (res) {
+                                let obj = {
+                                  'type': mDeviceEvent.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT,
+                                  'result': false,
+                                  'data': res
+                                }
+                                mDeviceEvent.notifyDeviceMsgEvent(obj);
+                              }
+                            })
+                            //通知设备交互方式(是否加密) end
+                            wx.onBLECharacteristicValueChange(function (res) {
+                              let list2 = (util.ab2hex(res.value));
+                              // start
+                              let result = _self.data.result;
+                              if (list2.length < 4) {
+                                cosnole.log(407);
+                                return false;
+                              }
+                              var val = parseInt(list2[0], 16),
+                                type = val & 3,
+                                subType = val >> 2;
+                              var dataLength = parseInt(list2[3], 16);
+                              if (dataLength == 0) {
+                                return false;
+                              }
+                              var fragNum = util.hexToBinArray(list2[1]);
+                              list2 = isEncrypt(fragNum, list2, _self.data.md5Key);
+                              result = result.concat(list2);
+                              _self.data.result = result
+                              if (_self.data.flagEnd) {
+                                _self.data.flagEnd = false
+                                if (type == 1) {
+                                  let what = [];
+                                  console.log("recieve data subType: ", subType)
+                                  switch (subType) {
+                                    case 15:
+                                      if (result.length == 3) {
+                                        mDeviceEvent.notifyDeviceMsgEvent({
+                                          'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT,
+                                          'result': false,
+                                          'data': {
+                                            'progress': 0,
+                                            'ssid': what.join('')
+                                          }
+                                        });
+                                      } else {
+                                        for (var i = 0; i <= result.length; i++) {
+                                          var num = parseInt(result[i], 16) + "";
+                                          if (i > 12) what.push(String.fromCharCode(parseInt(result[i], 16)));
+                                        }
+                                        mDeviceEvent.notifyDeviceMsgEvent({
+                                          'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECT_ROUTER_RESULT,
+                                          'result': true,
+                                          'data': {
+                                            'progress': 100,
+                                            'ssid': what.join('')
+                                          }
+                                        });
+                                      }
+
+                                      break;
+                                    case 19: //自定义数据
+                                      let customData = [];
+                                      for (var i = 0; i <= result.length; i++) {
+                                        customData.push(String.fromCharCode(parseInt(result[i], 16)));
+                                      }
+                                      let obj = {
+                                        'type': mDeviceEvent.XBLUFI_TYPE.TYPE_RECIEVE_CUSTON_DATA,
+                                        'result': true,
+                                        'data': customData.join('')
+                                      }
+                                      mDeviceEvent.notifyDeviceMsgEvent(obj);
+
+                                      break;
+                                    case util.SUBTYPE_NEGOTIATION_NEG:
+                                      var arr = util.hexByInt(result.join(""));
+                                      var clientSecret = client.computeSecret(new Uint8Array(arr));
+                                      var md5Key = md5.array(clientSecret);
+                                      _self.data.md5Key = md5Key;
+                                      mDeviceEvent.notifyDeviceMsgEvent({
+                                        'type': mDeviceEvent.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT,
+                                        'result': true,
+                                        'data': {
+                                          deviceId,
+                                          serviceId,
+                                          characteristicId
+                                        }
+                                      });
+                                      break;
+
+                                    case 17:
+                                      getList(result, result.length, 0);
+                                      break;
+
+                                    default:
+                                      console.log(468);
+                                      //_self.setFailProcess(true, util.descFailList[4])
+                                      console.log("入网失败 468 :", util.failList[4]);
+                                      break;
+                                  }
+                                  _self.data.result = []
+                                } else {
+                                  //console.log(472);
+                                  console.log("入网失败 472:", util.failList[4]);
+                                }
+                              }
+                              // end
+
+                            })
+
+                          },
+                          fail: function (res) {
+                            let obj = {
+                              'type': mDeviceEvent.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT,
+                              'result': false,
+                              'data': res
+                            }
+                            mDeviceEvent.notifyDeviceMsgEvent(obj);
+                          }
+                        })
+                      }
+                    }
+                  }
+                },
+                fail: function (res) {
+                  let obj = {
+                    'type': mDeviceEvent.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT,
+                    'result': false,
+                    'data': res
+                  }
+                  mDeviceEvent.notifyDeviceMsgEvent(obj);
+                  console.log("fail getBLEDeviceCharacteristics:" + JSON.stringify(res))
+                }
+              })
+              break;
+            }
+          }
+        }
+      },
+      fail: function (res) {
+        let obj = {
+          'type': mDeviceEvent.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT,
+          'result': false,
+          'data': res
+        }
+        mDeviceEvent.notifyDeviceMsgEvent(obj);
+        console.log("fail getBLEDeviceServices:" + JSON.stringify(res))
+      }
+    })
+  })
+
+  mDeviceEvent.listenSendRouterSsidAndPassword(true, function (options) {
+    _self.data.password = options.password
+    _self.data.ssid = options.ssid
+    writeDeviceRouterInfoStart(_self.data.deviceId, _self.data.service_uuid, _self.data.characteristic_write_uuid, null);
+  })
+
+
+  mDeviceEvent.listenSendCustomData(true, function (options) {
+    _self.data.customData = options.customData
+    writeCutomsData(_self.data.deviceId, _self.data.service_uuid, _self.data.characteristic_write_uuid, null);
+  })
+
+  mDeviceEvent.listenSendGetNearRouterSsid(true, function (options) {
+    writeGetNearRouterSsid(_self.data.deviceId, _self.data.service_uuid, _self.data.characteristic_write_uuid, null);
+  })
+
+}
+
+function getList(arr, totalLength, curLength) {
+  // console.log(totalLength)
+  // console.log(arr)
+  var _self = this;
+  if (arr.length > 0) {
+    var len = parseInt(arr[0], 16);
+    curLength += (1 + len);
+    if (len > 0 && curLength < totalLength) {
+      var rssi = 0, name = "";
+      let list = []
+      for (var i = 1; i <= len; i++) {
+        if (i == 1) {
+          rssi = parseInt(arr[i], 16);
+        } else {
+          list.push(parseInt(arr[i], 16))
+        }
+      }
+      name = decodeURIComponent(escape(String.fromCharCode(...list)))
+      let obj = {
+        'type': mDeviceEvent.XBLUFI_TYPE.TYPE_CONNECT_NEAR_ROUTER_LISTS,
+        'result': true,
+        'data': { "rssi": rssi, "SSID": name }
+      }
+      mDeviceEvent.notifyDeviceMsgEvent(obj);
+      arr = arr.splice(len + 1);
+      getList(arr, totalLength, curLength);
+    }
+  }
+}
+
+
+/****************************** 对外  ***************************************/
+module.exports = {
+  init: init,
+};

Разница между файлами не показана из-за своего большого размера
+ 636 - 846
utils/blufi/xBlufi-wx-impl.js