diff --git a/Meshtastic Client.xcodeproj/project.pbxproj b/Meshtastic Client.xcodeproj/project.pbxproj index 38dd6e48..14494d8a 100644 --- a/Meshtastic Client.xcodeproj/project.pbxproj +++ b/Meshtastic Client.xcodeproj/project.pbxproj @@ -27,6 +27,7 @@ DD5394FC276993AD00AD86B1 /* SwiftProtobuf in Frameworks */ = {isa = PBXBuildFile; productRef = DD5394FB276993AD00AD86B1 /* SwiftProtobuf */; }; DD5394FE276BA0EF00AD86B1 /* PositionEntityExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD5394FD276BA0EF00AD86B1 /* PositionEntityExtension.swift */; }; DD539502276DAA6A00AD86B1 /* MapLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD539501276DAA6A00AD86B1 /* MapLocation.swift */; }; + DD70A468279C554A003120E4 /* cannedmessages.pb.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD70A467279C554A003120E4 /* cannedmessages.pb.swift */; }; DD8169F9271F1A6100F4AB02 /* MeshLogger.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8169F8271F1A6100F4AB02 /* MeshLogger.swift */; }; DD8169FB271F1F3A00F4AB02 /* MeshLog.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8169FA271F1F3A00F4AB02 /* MeshLog.swift */; }; DD8169FF272476C700F4AB02 /* LogDocument.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8169FE272476C700F4AB02 /* LogDocument.swift */; }; @@ -94,6 +95,7 @@ DD4DED8F27AD2975004BA27E /* cannedmessages.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = cannedmessages.pb.swift; sourceTree = ""; }; DD5394FD276BA0EF00AD86B1 /* PositionEntityExtension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PositionEntityExtension.swift; sourceTree = ""; }; DD539501276DAA6A00AD86B1 /* MapLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapLocation.swift; sourceTree = ""; }; + DD70A467279C554A003120E4 /* cannedmessages.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = cannedmessages.pb.swift; sourceTree = ""; }; DD8169F8271F1A6100F4AB02 /* MeshLogger.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshLogger.swift; sourceTree = ""; }; DD8169FA271F1F3A00F4AB02 /* MeshLog.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MeshLog.swift; sourceTree = ""; }; DD8169FE272476C700F4AB02 /* LogDocument.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogDocument.swift; sourceTree = ""; }; @@ -218,7 +220,8 @@ children = ( DD4DED8F27AD2975004BA27E /* cannedmessages.pb.swift */, DDAF8C6126ED0A230058C060 /* admin.pb.swift */, - C9A88B56278B559900BD810A /* apponly.pb.swift */, + DD17E5DB277D49D400010EC2 /* apponly.pb.swift */, + DD70A467279C554A003120E4 /* cannedmessages.pb.swift */, DDAF8C6426ED0A490058C060 /* channel.pb.swift */, DDAF8C6826ED0D070058C060 /* deviceonly.pb.swift */, DDAF8C6A26ED0DD80058C060 /* environmental_measurement.pb.swift */, @@ -544,6 +547,7 @@ DD47E3DB26F3901B00029299 /* Channels.swift in Sources */, DD8169FF272476C700F4AB02 /* LogDocument.swift in Sources */, DDAF8C6926ED0D070058C060 /* deviceonly.pb.swift in Sources */, + DD70A468279C554A003120E4 /* cannedmessages.pb.swift in Sources */, DDAF8C6B26ED0DD80058C060 /* environmental_measurement.pb.swift in Sources */, DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */, DD4A911E2708C65400501B7E /* AppSettings.swift in Sources */, diff --git a/MeshtasticClient/Helpers/BLEManager.swift b/MeshtasticClient/Helpers/BLEManager.swift index 21ce011e..55d15b8a 100644 --- a/MeshtasticClient/Helpers/BLEManager.swift +++ b/MeshtasticClient/Helpers/BLEManager.swift @@ -55,7 +55,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // MARK: init BLEManager override init() { - self.meshLoggingEnabled = true // UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? true + self.meshLoggingEnabled = true // UserDefaults.standard.object(forKey: "meshActivityLog") as? Bool ?? false self.lastConnectionError = "" self.lastConnnectionVersion = "0.0.0" super.init() @@ -128,8 +128,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph self.timeoutTimer?.invalidate() } else { - print("🚫 BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") - if meshLoggingEnabled { MeshLogger.log("🚫 BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") } + print("🚨 BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") + if meshLoggingEnabled { MeshLogger.log("🚨 BLE Connecting 2 Second Timeout Timer Fired \(timeoutTimerCount) Time(s): \(name)") } } } @@ -142,6 +142,8 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph stopScanning() if self.connectedPeripheral != nil { + if meshLoggingEnabled { MeshLogger.log("ℹ️ BLE Disconnecting from: \(self.connectedPeripheral.name) to connect to \(peripheral.name ?? "Unknown")") } + print("ℹ️ BLE Disconnecting from: \(self.connectedPeripheral.name) to connect to \(peripheral.name ?? "Unknown")") self.disconnectPeripheral() } @@ -364,8 +366,6 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } // MARK: Data Read / Update Characteristic Event - // TODO: Convert to CoreData - // FIXME: Remove broken JSON file data layer implementation func peripheral(_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) { @@ -384,6 +384,15 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph self.centralManager?.cancelPeripheralConnection(peripheral) } + if errorCode == 15 { // CBATTErrorDomain Code=15 "Encryption is insufficient." + + // BLE Pin connection error + // We will try and re-connect to this device + lastConnectionError = "🚫 BLE \(e.localizedDescription) This may be a Meshtastic Firmware bug affecting BLE 4.0 devices." + if meshLoggingEnabled { MeshLogger.log("🚫 BLE \(e.localizedDescription) Please try connecting again. You may need to forget the device under Settings > General > Bluetooth.") } + self.centralManager?.cancelPeripheralConnection(peripheral) + + } } switch characteristic.uuid { @@ -407,7 +416,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph // print("Print DecodedInfo") // print(decodedInfo) - // MyInfo Data + // MARK: Incoming MyInfo Packet if decodedInfo.myInfo.myNodeNum != 0 { let fetchMyInfoRequest: NSFetchRequest = NSFetchRequest.init(entityName: "MyInfoEntity") @@ -491,7 +500,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph } } - // NodeInfo Data + // MARK: Incoming Node Info Packet if decodedInfo.nodeInfo.num != 0 { let fetchNodeRequest: NSFetchRequest = NSFetchRequest.init(entityName: "NodeInfoEntity") @@ -653,7 +662,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph do { - // Text Message App - Primary Broadcast User + // MARK: Incoming Packet from the TEXTMESSAGE_APP if decodedInfo.packet.decoded.portnum == PortNum.textMessageApp { if let messageText = String(bytes: decodedInfo.packet.decoded.payload, encoding: .utf8) { @@ -788,6 +797,7 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph print("💥 Error Fetching NodeInfoEntity for NODEINFO_APP") } + // MARK: Incoming Packet from the POSITION_APP } else if decodedInfo.packet.decoded.portnum == PortNum.positionApp { let fetchNodePositionRequest: NSFetchRequest = NSFetchRequest.init(entityName: "NodeInfoEntity") @@ -987,11 +997,11 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph var meshPacket = MeshPacket() meshPacket.to = UInt32(toUserNum) meshPacket.from = UInt32(fromUserNum) + meshPacket.decoded = dataMessage meshPacket.decoded.isTapback = isTapback if replyID > 0 { meshPacket.decoded.replyID = UInt32(replyID) } - meshPacket.decoded = dataMessage meshPacket.wantAck = true var toRadio: ToRadio! diff --git a/MeshtasticClient/Views/Bluetooth/Connect.swift b/MeshtasticClient/Views/Bluetooth/Connect.swift index e5c59b12..8fdcad18 100644 --- a/MeshtasticClient/Views/Bluetooth/Connect.swift +++ b/MeshtasticClient/Views/Bluetooth/Connect.swift @@ -24,7 +24,7 @@ struct Connect: View { var body: some View { let firmwareVersion = bleManager.lastConnnectionVersion - let minimumVersion = "1.2.30" + let minimumVersion = "1.2.46" let supportedVersion = firmwareVersion == "0.0.0" || minimumVersion.compare(firmwareVersion, options: .numeric) == .orderedAscending || minimumVersion.compare(firmwareVersion, options: .numeric) == .orderedSame @@ -73,7 +73,7 @@ struct Connect: View { Text(String(bleManager.connectedPeripheral.peripheral.name ?? "Unknown")).font(.title2) } - Text("BLE Name: ").font(.caption)+Text(bleManager.connectedPeripheral.name) + Text("BLE Name: ").font(.caption)+Text(bleManager.connectedPeripheral.peripheral.name ?? "Unknown") .font(.caption).foregroundColor(Color.gray) if bleManager.connectedPeripheral != nil { Text("FW Version: ").font(.caption)+Text(bleManager.connectedPeripheral.firmwareVersion) diff --git a/MeshtasticClient/Views/Messages/UserMessageList.swift b/MeshtasticClient/Views/Messages/UserMessageList.swift index 8b407652..c97fcc99 100644 --- a/MeshtasticClient/Views/Messages/UserMessageList.swift +++ b/MeshtasticClient/Views/Messages/UserMessageList.swift @@ -345,7 +345,7 @@ struct UserMessageList: View { }) .onChange(of: allMessages.count, perform: { count in - self.context.refresh(user, mergeChanges: true) + //self.context.refresh(user, mergeChanges: true) let index = count - 1 diff --git a/gen_protos.sh b/gen_protos.sh index 852c9d8d..d43133ae 100755 --- a/gen_protos.sh +++ b/gen_protos.sh @@ -14,8 +14,8 @@ fi pdir=$(realpath "../Meshtastic-protobufs") sdir=$(realpath "./MeshtasticClient/Protobufs") -echo "pdir:$pdir sdir:$sdir" -pfiles="radioconfig.proto channel.proto cannedmessages.proto deviceonly.proto portnums.proto remote_hardware.proto environmental_measurement.proto admin.proto mqtt.proto mesh.proto storeforward.proto" +echo "pdir:$pdir sdir:$sdir +pfiles="admin.proto apponly.proto cannedmessages.proto channel.proto deviceonly.proto environmental_measurement.proto mesh.proto mqtt.proto portnums.proto radioconfig.proto remote_hardware.proto storeforward.proto" for pf in $pfiles do echo "Generating $pf..."