fix(mp): 数据监听器移到连接前注册,修复认证超时
根因:veepooWeiXinSDKNotifyMonitorValueChange 封装 wx.onBLECharacteristicValueChange,必须在连接+订阅 特征值之前注册,否则认证响应(type=1)丢失。 流程修正:registerListeners → connect → auth 原流程:connect → callback → registerListeners → auth(错误) 同时增加 SDK 事件诊断日志和认证超时时输出 deviceChipStatus 实际值便于排查。
This commit is contained in:
@@ -174,11 +174,16 @@ Page({
|
|||||||
console.log('[veepoo-native] 连接设备:', device.deviceId || device.mac);
|
console.log('[veepoo-native] 连接设备:', device.deviceId || device.mac);
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
|
// 关键修复:在连接前注册数据监听器
|
||||||
|
// SDK 的 veepooWeiXinSDKNotifyMonitorValueChange 内部封装 wx.onBLECharacteristicValueChange
|
||||||
|
// 必须在连接 + 订阅特征值之前注册,否则会丢失认证响应(type=1)
|
||||||
|
self._registerListeners();
|
||||||
|
|
||||||
veepooBle.veepooWeiXinSDKBleConnectionServicesCharacteristicsNotifyManager(device, function (result) {
|
veepooBle.veepooWeiXinSDKBleConnectionServicesCharacteristicsNotifyManager(device, function (result) {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
console.log('[veepoo-native] 连接回调:', JSON.stringify(result));
|
console.log('[veepoo-native] 连接回调:', JSON.stringify(result));
|
||||||
|
|
||||||
// C4 修复:按官方 Demo 检查 connection:true,同时兼容 errno:0
|
// 按官方 Demo 检查 connection:true,同时兼容 errno:0 / errCode:0
|
||||||
if (result.connection === true || result.errno === 0 || result.errCode === 0) {
|
if (result.connection === true || result.errno === 0 || result.errCode === 0) {
|
||||||
self._connected = true;
|
self._connected = true;
|
||||||
self._connecting = false;
|
self._connecting = false;
|
||||||
@@ -186,8 +191,7 @@ Page({
|
|||||||
deviceId: device.deviceId || device.mac || '',
|
deviceId: device.deviceId || device.mac || '',
|
||||||
});
|
});
|
||||||
|
|
||||||
self._registerListeners();
|
// 连接成功后延迟 500ms 发送认证指令(等待特征值订阅就绪)
|
||||||
|
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
veepooFeature.veepooBlePasswordCheckManager();
|
veepooFeature.veepooBlePasswordCheckManager();
|
||||||
@@ -196,6 +200,7 @@ Page({
|
|||||||
console.log('[veepoo-native] 认证指令已发送');
|
console.log('[veepoo-native] 认证指令已发送');
|
||||||
}, 500);
|
}, 500);
|
||||||
|
|
||||||
|
// 双重检测认证结果:事件监听器(type=1)+ Storage 轮询兜底
|
||||||
self._authTimer = setInterval(function () {
|
self._authTimer = setInterval(function () {
|
||||||
try {
|
try {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
@@ -213,6 +218,8 @@ Page({
|
|||||||
clearInterval(self._authTimer);
|
clearInterval(self._authTimer);
|
||||||
self._authTimer = null;
|
self._authTimer = null;
|
||||||
self._connecting = false;
|
self._connecting = false;
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
console.error('[veepoo-native] 认证超时,deviceChipStatus=', wx.getStorageSync('deviceChipStatus'));
|
||||||
self.setData({ phase: 'error', error: '设备认证超时,请重新连接' });
|
self.setData({ phase: 'error', error: '设备认证超时,请重新连接' });
|
||||||
}
|
}
|
||||||
}, 8000);
|
}, 8000);
|
||||||
@@ -250,6 +257,8 @@ Page({
|
|||||||
_handleSdkEvent: function (data) {
|
_handleSdkEvent: function (data) {
|
||||||
if (!data || data.type === undefined) return;
|
if (!data || data.type === undefined) return;
|
||||||
var type = data.type;
|
var type = data.type;
|
||||||
|
// eslint-disable-next-line no-undef
|
||||||
|
console.log('[veepoo-native] SDK 事件: type=' + type, JSON.stringify(data).substring(0, 300));
|
||||||
|
|
||||||
if (type === SDK_EVENT_AUTH) {
|
if (type === SDK_EVENT_AUTH) {
|
||||||
var password = (data.content || {}).VPDevicepassword;
|
var password = (data.content || {}).VPDevicepassword;
|
||||||
|
|||||||
Reference in New Issue
Block a user