diff --git a/src/io/ble.js b/src/io/ble.js index af0dc3086..cf6530f8d 100644 --- a/src/io/ble.js +++ b/src/io/ble.js @@ -172,7 +172,7 @@ class BLE extends JSONRPCWebSocket { } _sendError (/* e */) { - this.disconnect(); + if (this._connected) this.disconnect(); // log.error(`BLE error: ${JSON.stringify(e)}`); this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { message: `Scratch lost connection to`, diff --git a/src/io/bt.js b/src/io/bt.js index 60e74ff00..bf492f84a 100644 --- a/src/io/bt.js +++ b/src/io/bt.js @@ -115,7 +115,7 @@ class BT extends JSONRPCWebSocket { } _sendError (/* e */) { - this.disconnect(); + if (this._connected) this.disconnect(); // log.error(`BT error: ${JSON.stringify(e)}`); this._runtime.emit(this._runtime.constructor.PERIPHERAL_ERROR, { message: `Scratch lost connection to`,