mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Use want config timer to prevent disconnect while config is running, stop force disconnecting.
This commit is contained in:
parent
db0119bed9
commit
aafa7b7b31
2 changed files with 7 additions and 9 deletions
|
|
@ -32,6 +32,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
public var isConnecting: Bool = false
|
||||
public var isConnected: Bool = false
|
||||
public var isSubscribed: Bool = false
|
||||
public var allowDisconnect: Bool = false
|
||||
private var configNonce: UInt32 = 1
|
||||
var timeoutTimer: Timer?
|
||||
var timeoutTimerCount = 0
|
||||
|
|
@ -172,6 +173,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
isConnecting = false
|
||||
isConnected = false
|
||||
isSubscribed = false
|
||||
allowDisconnect = false
|
||||
self.connectedPeripheral = nil
|
||||
invalidVersion = false
|
||||
connectedVersion = "0.0.0"
|
||||
|
|
@ -204,6 +206,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
self.FROMRADIO_characteristic = nil
|
||||
self.isConnected = false
|
||||
self.isSubscribed = false
|
||||
self.allowDisconnect = false
|
||||
self.invalidVersion = false
|
||||
self.connectedVersion = "0.0.0"
|
||||
self.stopScanning()
|
||||
|
|
@ -563,7 +566,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
sendWantConfig()
|
||||
} else {
|
||||
Logger.mesh.error("🚨 Want Config failed after \(self.maxWantConfigRetries) attempts, forcing disconnect")
|
||||
forceDisconnect()
|
||||
lastConnectionError = "Bluetooth connection timeout, keep your node closer or reboot your radio if the problem continues.".localized
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -576,12 +579,6 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
}
|
||||
}
|
||||
|
||||
private func forceDisconnect() {
|
||||
disconnectPeripheral(reconnect: false)
|
||||
lastConnectionError = "Bluetooth connection timeout, keep your node closer or reboot your radio if the problem continues.".localized
|
||||
Logger.mesh.error("💥 [BLE] Forced disconnect due to Want Config timeout")
|
||||
}
|
||||
|
||||
// Call this to reset the retry mechanism (e.g., on new connection)
|
||||
func resetWantConfigRetries() {
|
||||
wantConfigRetryCount = 0
|
||||
|
|
@ -1059,6 +1056,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
invalidVersion = false
|
||||
lastConnectionError = ""
|
||||
isSubscribed = true
|
||||
allowDisconnect = true
|
||||
Logger.mesh.info("🤜 [BLE] Want Config Complete. ID:\(decodedInfo.configCompleteID, privacy: .public)")
|
||||
if sendTime() {
|
||||
}
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ struct Connect: View {
|
|||
.foregroundColor(Color.gray)
|
||||
.padding([.top])
|
||||
.swipeActions {
|
||||
if bleManager.isSubscribed {
|
||||
if bleManager.allowDisconnect {
|
||||
Button(role: .destructive) {
|
||||
if let connectedPeripheral = bleManager.connectedPeripheral,
|
||||
connectedPeripheral.peripheral.state == .connected {
|
||||
|
|
@ -127,7 +127,7 @@ struct Connect: View {
|
|||
Text("Short Name: \(node?.user?.shortName ?? "?")")
|
||||
Text("Long Name: \(node?.user?.longName?.addingVariationSelectors ?? "Unknown".localized)")
|
||||
Text("BLE RSSI: \(connectedPeripheral.rssi)")
|
||||
if bleManager.isSubscribed {
|
||||
if bleManager.allowDisconnect {
|
||||
Button(role: .destructive) {
|
||||
if let connectedPeripheral = bleManager.connectedPeripheral,
|
||||
connectedPeripheral.peripheral.state == .connected {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue