diff --git a/miniprogram/pages/ble-connect/ble-connect.js b/miniprogram/pages/ble-connect/ble-connect.js index b334f53..41573fb 100644 --- a/miniprogram/pages/ble-connect/ble-connect.js +++ b/miniprogram/pages/ble-connect/ble-connect.js @@ -34,8 +34,15 @@ Page({ onUnload: function () { clearTimeout(this._scanTimer) + clearTimeout(this._retryTimer) ble.stopScan() - if (this._onBindResult) ble.off('bind_result', this._onBindResult) + if (this._onBindResult) { + ble.off('bind_result', this._onBindResult) + this._onBindResult = null + } + if (this.data.state !== 'done') { + ble.disconnect() + } }, startBleConnect: function () { @@ -98,7 +105,7 @@ Page({ self._onBindResult = null } ble.disconnect() - setTimeout(function () { + self._retryTimer = setTimeout(function () { self.startBleConnect() }, 1000) },