mirror of
https://github.com/jhbruhn/respira.git
synced 2026-01-27 02:13:41 +00:00
fix: Detect unpaired Bluetooth devices during connection
The application now properly detects when a Brother PP1 machine is not paired with the operating system. Previously, the connection would appear successful but commands would fail silently. Changes: - Enhanced sendCommand() to check for empty or invalid responses during initial connection - Updated connect() to validate the connection with a test command (getMachineState) - Properly disconnect and clean up when pairing is not established - Throw BluetoothPairingError with helpful instructions for the user When the machine is not paired, users now see a clear error message instructing them to: 1. Long-press the Bluetooth button on the machine 2. Pair via the operating system's Bluetooth settings 3. Try connecting again 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
5f46f67cb4
commit
caf800b40b
1 changed files with 27 additions and 4 deletions
|
|
@ -131,12 +131,18 @@ export class BrotherPP1Service {
|
||||||
|
|
||||||
console.log("Connected to Brother PP1 machine");
|
console.log("Connected to Brother PP1 machine");
|
||||||
|
|
||||||
console.log("Send dummy command");
|
// Validate connection by sending a test command
|
||||||
|
// If the device is not paired, it won't respond properly
|
||||||
|
console.log("Validating connection with test command...");
|
||||||
try {
|
try {
|
||||||
await this.getMachineInfo();
|
await this.getMachineState();
|
||||||
console.log("Dummy command success");
|
console.log("Connection validation successful - device is properly paired");
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log(e);
|
console.log("Connection validation failed:", e);
|
||||||
|
// Disconnect to clean up
|
||||||
|
if (this.server) {
|
||||||
|
this.server.disconnect();
|
||||||
|
}
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -280,6 +286,23 @@ export class BrotherPP1Service {
|
||||||
.map((b) => b.toString(16).padStart(2, "0"))
|
.map((b) => b.toString(16).padStart(2, "0"))
|
||||||
.join(" ");
|
.join(" ");
|
||||||
|
|
||||||
|
// Detect pairing issues during initial connection - empty or invalid response
|
||||||
|
if (this.isInitialConnection) {
|
||||||
|
if (response.length === 0) {
|
||||||
|
console.log('[BrotherPP1] Empty response received - device likely not paired');
|
||||||
|
throw new BluetoothPairingError(
|
||||||
|
'Device not paired. To pair: long-press the Bluetooth button on the machine, then pair it using your operating system\'s Bluetooth settings. After pairing, try connecting again.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
// Check for invalid response (less than 3 bytes means no proper command response)
|
||||||
|
if (response.length < 3) {
|
||||||
|
console.log('[BrotherPP1] Invalid response length:', response.length);
|
||||||
|
throw new BluetoothPairingError(
|
||||||
|
'Device not paired. To pair: long-press the Bluetooth button on the machine, then pair it using your operating system\'s Bluetooth settings. After pairing, try connecting again.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Parse response
|
// Parse response
|
||||||
let parsed = "";
|
let parsed = "";
|
||||||
if (response.length >= 3) {
|
if (response.length >= 3) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue