diff --git a/Meshtastic.xcodeproj/project.pbxproj b/Meshtastic.xcodeproj/project.pbxproj index 82e9e383..9a560ee2 100644 --- a/Meshtastic.xcodeproj/project.pbxproj +++ b/Meshtastic.xcodeproj/project.pbxproj @@ -53,7 +53,7 @@ DD86D4112881D16900BAEB7A /* WriteCsvFile.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD86D4102881D16900BAEB7A /* WriteCsvFile.swift */; }; DD882F5D2772E4640005BF05 /* Contacts.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD882F5C2772E4640005BF05 /* Contacts.swift */; }; DD8EBF43285058FA00426DCA /* DisplayConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8EBF42285058FA00426DCA /* DisplayConfig.swift */; }; - DD8ED9C52898D51F00B3B0AB /* WiFiConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8ED9C42898D51F00B3B0AB /* WiFiConfig.swift */; }; + DD8ED9C52898D51F00B3B0AB /* NetworkConfig.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8ED9C42898D51F00B3B0AB /* NetworkConfig.swift */; }; DD8ED9C8289CE4B900B3B0AB /* RoutingError.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD8ED9C7289CE4B900B3B0AB /* RoutingError.swift */; }; DD90860C26F684AF00DC5189 /* BatteryIcon.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860B26F684AF00DC5189 /* BatteryIcon.swift */; }; DD90860E26F69BAE00DC5189 /* NodeMap.swift in Sources */ = {isa = PBXBuildFile; fileRef = DD90860D26F69BAE00DC5189 /* NodeMap.swift */; }; @@ -121,6 +121,7 @@ C9A88B56278B559900BD810A /* apponly.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = apponly.pb.swift; sourceTree = ""; }; DD0F791A28713C8A00A6FDAD /* AdminMessageList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AdminMessageList.swift; sourceTree = ""; }; DD17E5DC277D49D400010EC2 /* storeforward.pb.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = storeforward.pb.swift; sourceTree = ""; }; + DD1925B528CD591B00720036 /* MeshtasticDataModel v 11.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 11.xcdatamodel"; sourceTree = ""; }; DD1BF2F82776FE2E008C8D2F /* UserMessageList.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserMessageList.swift; sourceTree = ""; }; DD2160AD28C5536B00C17253 /* MeshtasticDataModel v 10.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 10.xcdatamodel"; sourceTree = ""; }; DD2160AE28C5552500C17253 /* MQTTConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MQTTConfig.swift; sourceTree = ""; }; @@ -164,7 +165,7 @@ DD882F5C2772E4640005BF05 /* Contacts.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Contacts.swift; sourceTree = ""; }; DD8EBF42285058FA00426DCA /* DisplayConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DisplayConfig.swift; sourceTree = ""; }; DD8ED9C328978D9D00B3B0AB /* MeshtasticDataModel v 5.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 5.xcdatamodel"; sourceTree = ""; }; - DD8ED9C42898D51F00B3B0AB /* WiFiConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WiFiConfig.swift; sourceTree = ""; }; + DD8ED9C42898D51F00B3B0AB /* NetworkConfig.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NetworkConfig.swift; sourceTree = ""; }; DD8ED9C7289CE4B900B3B0AB /* RoutingError.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RoutingError.swift; sourceTree = ""; }; DD8ED9C9289EA77E00B3B0AB /* MeshtasticDataModel v 6.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "MeshtasticDataModel v 6.xcdatamodel"; sourceTree = ""; }; DD90860A26F645B700DC5189 /* Meshtastic.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Meshtastic.entitlements; sourceTree = ""; }; @@ -314,7 +315,7 @@ DD8EBF42285058FA00426DCA /* DisplayConfig.swift */, DD2553562855B02500E55709 /* LoRaConfig.swift */, DD2553582855B52700E55709 /* PositionConfig.swift */, - DD8ED9C42898D51F00B3B0AB /* WiFiConfig.swift */, + DD8ED9C42898D51F00B3B0AB /* NetworkConfig.swift */, DD61937B2863877A00E59241 /* Module */, ); path = Config; @@ -749,7 +750,7 @@ C9483F6D2773017500998F6B /* MapView.swift in Sources */, DDAF8C5826ED07FD0058C060 /* mesh.pb.swift in Sources */, DD8169FB271F1F3A00F4AB02 /* MeshLog.swift in Sources */, - DD8ED9C52898D51F00B3B0AB /* WiFiConfig.swift in Sources */, + DD8ED9C52898D51F00B3B0AB /* NetworkConfig.swift in Sources */, DDC3B274283F411B00AC321C /* LastHeardText.swift in Sources */, DD2E65262767A01F00E45FC5 /* NodeDetail.swift in Sources */, DD86D4112881D16900BAEB7A /* WriteCsvFile.swift in Sources */, @@ -1154,6 +1155,7 @@ DD9D8F2D2764403B00080993 /* Meshtastic.xcdatamodeld */ = { isa = XCVersionGroup; children = ( + DD1925B528CD591B00720036 /* MeshtasticDataModel v 11.xcdatamodel */, DD2160AD28C5536B00C17253 /* MeshtasticDataModel v 10.xcdatamodel */, DD5929A528C0F292003DB21D /* MeshtasticDataModel v 9.xcdatamodel */, DD4033C328B405A60096A444 /* MeshtasticDataModel v 8.xcdatamodel */, @@ -1165,7 +1167,7 @@ DD45C77427BD4EF80011784F /* MeshtasticDataModel v2.xcdatamodel */, DD9D8F2E2764403B00080993 /* CoreDataSample.xcdatamodel */, ); - currentVersion = DD2160AD28C5536B00C17253 /* MeshtasticDataModel v 10.xcdatamodel */; + currentVersion = DD1925B528CD591B00720036 /* MeshtasticDataModel v 11.xcdatamodel */; name = Meshtastic.xcdatamodeld; path = Meshtastic/Meshtastic.xcdatamodeld; sourceTree = ""; diff --git a/Meshtastic/Helpers/MeshPackets.swift b/Meshtastic/Helpers/MeshPackets.swift index ec3fc9fa..dcdc9d2d 100644 --- a/Meshtastic/Helpers/MeshPackets.swift +++ b/Meshtastic/Helpers/MeshPackets.swift @@ -459,18 +459,9 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont } if config.payloadVariant == Config.OneOf_PayloadVariant.network(config.network) { - - var isDefault = false - - if (try! config.network.jsonString()) == "{}" { - - isDefault = true - if meshlogging { MeshLogger.log("📶 Default WiFi config received \(String(nodeNum))") } - - } else { - - if meshlogging { MeshLogger.log("📶 Custom WiFi config received \(String(nodeNum))") } - } + + if meshlogging { MeshLogger.log("📶 WiFi config received \(String(nodeNum))") } + print(try! config.network.jsonString()) let fetchNodeInfoRequest: NSFetchRequest = NSFetchRequest.init(entityName: "NodeInfoEntity") fetchNodeInfoRequest.predicate = NSPredicate(format: "num == %lld", Int64(nodeNum)) @@ -478,41 +469,25 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont do { let fetchedNode = try context.fetch(fetchNodeInfoRequest) as! [NodeInfoEntity] + // Found a node, save WiFi Config if !fetchedNode.isEmpty { - if fetchedNode[0].wiFiConfig == nil { + if fetchedNode[0].networkConfig == nil { - let newWiFiConfig = WiFiConfigEntity(context: context) + let newNetworkConfig = NetworkConfigEntity(context: context) - if isDefault { - - newWiFiConfig.ssid = "" - newWiFiConfig.password = "" - newWiFiConfig.mode = 0 + newNetworkConfig.wifiSsid = config.network.wifiSsid + newNetworkConfig.wifiPsk = config.network.wifiPsk + newNetworkConfig.wifiMode = Int32(config.network.wifiMode.rawValue) - } else { - - newWiFiConfig.ssid = config.network.wifiSsid - newWiFiConfig.password = config.network.wifiPsk - newWiFiConfig.mode = Int32(config.network.wifiMode.rawValue) - } - fetchedNode[0].wiFiConfig = newWiFiConfig + fetchedNode[0].networkConfig = newNetworkConfig } else { - if isDefault { - - fetchedNode[0].wiFiConfig?.ssid = "" - fetchedNode[0].wiFiConfig?.password = "" - fetchedNode[0].wiFiConfig?.mode = 0 - - } else { - - fetchedNode[0].wiFiConfig?.ssid = config.network.wifiSsid - fetchedNode[0].wiFiConfig?.password = config.network.wifiPsk - fetchedNode[0].wiFiConfig?.mode = Int32(config.network.wifiMode.rawValue) - } + fetchedNode[0].networkConfig?.wifiSsid = config.network.wifiSsid + fetchedNode[0].networkConfig?.wifiPsk = config.network.wifiPsk + fetchedNode[0].networkConfig?.wifiMode = Int32(config.network.wifiMode.rawValue) } do { diff --git a/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion b/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion index 8b0ce3b2..0d87f123 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion +++ b/Meshtastic/Meshtastic.xcdatamodeld/.xccurrentversion @@ -3,6 +3,6 @@ _XCCurrentVersionName - MeshtasticDataModel v 10.xcdatamodel + MeshtasticDataModel v 11.xcdatamodel diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 10.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 10.xcdatamodel/contents index fa053770..52afebb5 100644 --- a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 10.xcdatamodel/contents +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 10.xcdatamodel/contents @@ -1,5 +1,5 @@ - + @@ -100,6 +100,13 @@ + + + + + + + @@ -121,7 +128,7 @@ - + @@ -203,13 +210,6 @@ - - - - - - - @@ -218,6 +218,7 @@ + @@ -227,7 +228,6 @@ - - + \ No newline at end of file diff --git a/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 11.xcdatamodel/contents b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 11.xcdatamodel/contents new file mode 100644 index 00000000..b1c358d7 --- /dev/null +++ b/Meshtastic/Meshtastic.xcdatamodeld/MeshtasticDataModel v 11.xcdatamodel/contents @@ -0,0 +1,233 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Meshtastic/Protobufs/telemetry.pb.swift b/Meshtastic/Protobufs/telemetry.pb.swift index 85e95036..73f89cc0 100644 --- a/Meshtastic/Protobufs/telemetry.pb.swift +++ b/Meshtastic/Protobufs/telemetry.pb.swift @@ -52,6 +52,14 @@ enum TelemetrySensorType: SwiftProtobuf.Enum { /// /// High accuracy temperature and pressure case bmp280 // = 6 + + /// + /// High accuracy temperature and humidity + case shtc3 // = 7 + + /// + /// High accuracy pressure + case lps22 // = 8 case UNRECOGNIZED(Int) init() { @@ -67,6 +75,8 @@ enum TelemetrySensorType: SwiftProtobuf.Enum { case 4: self = .ina260 case 5: self = .ina219 case 6: self = .bmp280 + case 7: self = .shtc3 + case 8: self = .lps22 default: self = .UNRECOGNIZED(rawValue) } } @@ -80,6 +90,8 @@ enum TelemetrySensorType: SwiftProtobuf.Enum { case .ina260: return 4 case .ina219: return 5 case .bmp280: return 6 + case .shtc3: return 7 + case .lps22: return 8 case .UNRECOGNIZED(let i): return i } } @@ -98,6 +110,8 @@ extension TelemetrySensorType: CaseIterable { .ina260, .ina219, .bmp280, + .shtc3, + .lps22, ] } @@ -256,6 +270,8 @@ extension TelemetrySensorType: SwiftProtobuf._ProtoNameProviding { 4: .same(proto: "INA260"), 5: .same(proto: "INA219"), 6: .same(proto: "BMP280"), + 7: .same(proto: "SHTC3"), + 8: .same(proto: "LPS22"), ] } diff --git a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift index cd21f905..16c905ff 100644 --- a/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift +++ b/Meshtastic/Views/Settings/Config/Module/MQTTConfig.swift @@ -209,21 +209,21 @@ struct MQTTConfig: View { } .onChange(of: enabled) { newEnabled in - if node != nil && node!.wiFiConfig != nil { + if node != nil && node!.mqttConfig != nil { - if newEnabled != node!.wiFiConfig!.enabled { hasChanges = true } + if newEnabled != node!.mqttConfig!.enabled { hasChanges = true } } } .onChange(of: encryptionEnabled) { newEncryptionEnabled in - if node != nil && node!.wiFiConfig != nil { + if node != nil && node!.mqttConfig != nil { if newEncryptionEnabled != node!.mqttConfig!.encryptionEnabled { hasChanges = true } } } .onChange(of: jsonEnabled) { newJsonEnabled in - if node != nil && node!.wiFiConfig != nil { + if node != nil && node!.mqttConfig != nil { if newJsonEnabled != node!.mqttConfig!.jsonEnabled { hasChanges = true } } diff --git a/Meshtastic/Views/Settings/Config/WiFiConfig.swift b/Meshtastic/Views/Settings/Config/NetworkConfig.swift similarity index 60% rename from Meshtastic/Views/Settings/Config/WiFiConfig.swift rename to Meshtastic/Views/Settings/Config/NetworkConfig.swift index 914604de..db25c040 100644 --- a/Meshtastic/Views/Settings/Config/WiFiConfig.swift +++ b/Meshtastic/Views/Settings/Config/NetworkConfig.swift @@ -7,7 +7,7 @@ import SwiftUI -struct WiFiConfig: View { +struct NetworkConfig: View { @Environment(\.managedObjectContext) var context @EnvironmentObject var bleManager: BLEManager @@ -18,10 +18,10 @@ struct WiFiConfig: View { @State var initialLoad: Bool = true @State var hasChanges: Bool = false - @State var enabled = false - @State var ssid = "" - @State var password = "" - @State var mode = 0 + @State var wifiEnabled = false + @State var wifiSsid = "" + @State var wifiPsk = "" + @State var wifiMode = 0 var body: some View { @@ -29,47 +29,44 @@ struct WiFiConfig: View { Form { - Text("Enabling WiFi will disable the bluetooth connection to the app.") - .font(.title3) - - Section(header: Text("Options")) { + Section(header: Text("WiFi Options")) { + + Text("Enabling WiFi will disable the bluetooth connection to the app.") + .font(.title3) - Toggle(isOn: $enabled) { + Toggle(isOn: $wifiEnabled) { Label("Enabled", systemImage: "wifi") } .toggleStyle(SwitchToggleStyle(tint: .accentColor)) - Picker("Mode", selection: $mode ) { + Picker("Mode", selection: $wifiMode ) { ForEach(WiFiModes.allCases) { lu in Text(lu.description) } } .pickerStyle(DefaultPickerStyle()) - } - Section(header: Text("SSID & Password")) { - HStack { Label("SSID", systemImage: "network") - TextField("SSID", text: $ssid) + TextField("SSID", text: $wifiSsid) .foregroundColor(.gray) .autocapitalization(.none) .disableAutocorrection(true) - .onChange(of: ssid, perform: { value in + .onChange(of: wifiSsid, perform: { value in - let totalBytes = ssid.utf8.count + let totalBytes = wifiSsid.utf8.count // Only mess with the value if it is too big if totalBytes > 32 { - let firstNBytes = Data(ssid.utf8.prefix(32)) + let firstNBytes = Data(wifiSsid.utf8.prefix(32)) if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) { // Set the shortName back to the last place where it was the right size - ssid = maxBytesString + wifiSsid = maxBytesString } } hasChanges = true @@ -78,26 +75,25 @@ struct WiFiConfig: View { } .keyboardType(.default) - HStack { Label("Password", systemImage: "wallet.pass") - TextField("Password", text: $password) + TextField("Password", text: $wifiPsk) .foregroundColor(.gray) .autocapitalization(.none) .disableAutocorrection(true) - .onChange(of: password, perform: { value in + .onChange(of: wifiPsk, perform: { value in - let totalBytes = password.utf8.count + let totalBytes = wifiPsk.utf8.count // Only mess with the value if it is too big if totalBytes > 63 { - let firstNBytes = Data(password.utf8.prefix(63)) + let firstNBytes = Data(wifiPsk.utf8.prefix(63)) if let maxBytesString = String(data: firstNBytes, encoding: String.Encoding.utf8) { // Set the shortName back to the last place where it was the right size - password = maxBytesString + wifiPsk = maxBytesString } } hasChanges = true @@ -127,13 +123,13 @@ struct WiFiConfig: View { "Are you sure?", isPresented: $isPresentingSaveConfirm ) { - Button("Save WiFI Config to \(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral.longName : "Unknown")?") { + Button("Save Network Config to \(bleManager.connectedPeripheral != nil ? bleManager.connectedPeripheral.longName : "Unknown")?") { var network = Config.NetworkConfig() - network.wifiEnabled = self.enabled - network.wifiSsid = self.ssid - network.wifiPsk = self.password - network.wifiMode = WiFiModes(rawValue: self.mode)?.protoEnumValue() ?? WiFiModes.client.protoEnumValue() + network.wifiEnabled = self.wifiEnabled + network.wifiSsid = self.wifiSsid + network.wifiPsk = self.wifiPsk + network.wifiMode = WiFiModes(rawValue: self.wifiMode)?.protoEnumValue() ?? WiFiModes.client.protoEnumValue() let adminMessageId = bleManager.saveWiFiConfig(config: network, fromUser: node!.user!, toUser: node!.user!) @@ -149,7 +145,7 @@ struct WiFiConfig: View { } } } - .navigationTitle("WiFi Config") + .navigationTitle("Network Config") .navigationBarItems(trailing: ZStack { @@ -162,27 +158,41 @@ struct WiFiConfig: View { self.bleManager.context = context - self.enabled = (node!.wiFiConfig?.enabled ?? false) - self.ssid = node!.wiFiConfig?.ssid ?? "" - self.password = node!.wiFiConfig?.password ?? "" - self.mode = Int(node!.wiFiConfig?.mode ?? 0) + self.wifiEnabled = (node!.networkConfig?.wifiEnabled ?? false) + self.wifiSsid = node!.networkConfig?.wifiSsid ?? "" + self.wifiPsk = node!.networkConfig?.wifiPsk ?? "" + self.wifiMode = Int(node!.networkConfig?.wifiMode ?? 0) self.hasChanges = false self.initialLoad = false } } - .onChange(of: enabled) { newEnabled in + .onChange(of: wifiEnabled) { newEnabled in - if node != nil && node!.wiFiConfig != nil { + if node != nil && node!.networkConfig != nil { - if newEnabled != node!.wiFiConfig!.enabled { hasChanges = true } + if newEnabled != node!.networkConfig!.wifiEnabled { hasChanges = true } } } - .onChange(of: mode) { newMode in + .onChange(of: wifiSsid) { newSSID in - if node != nil && node!.wiFiConfig != nil { + if node != nil && node!.networkConfig != nil { - if newMode != node!.wiFiConfig!.mode { hasChanges = true } + if newSSID != node!.networkConfig!.wifiSsid { hasChanges = true } + } + } + .onChange(of: wifiPsk) { newPsk in + + if node != nil && node!.networkConfig != nil { + + if newPsk != node!.networkConfig!.wifiPsk { hasChanges = true } + } + } + .onChange(of: wifiMode) { newMode in + + if node != nil && node!.networkConfig != nil { + + if newMode != node!.networkConfig!.wifiMode { hasChanges = true } } } .navigationViewStyle(StackNavigationViewStyle()) diff --git a/Meshtastic/Views/Settings/Settings.swift b/Meshtastic/Views/Settings/Settings.swift index 2aa04051..caa8d24a 100644 --- a/Meshtastic/Views/Settings/Settings.swift +++ b/Meshtastic/Views/Settings/Settings.swift @@ -100,6 +100,17 @@ struct Settings: View { Text("Display (Device Screen)") } .disabled(bleManager.connectedPeripheral == nil) + + NavigationLink { + NetworkConfig(node: nodes.first(where: { $0.num == connectedNodeNum })) + } label: { + + Image(systemName: "network") + .symbolRenderingMode(.hierarchical) + + Text("Network (ESP32 Only)") + } + .disabled(bleManager.connectedPeripheral == nil) NavigationLink { PositionConfig(node: nodes.first(where: { $0.num == connectedNodeNum })) @@ -112,20 +123,6 @@ struct Settings: View { } .disabled(bleManager.connectedPeripheral == nil) - NavigationLink { - WiFiConfig(node: nodes.first(where: { $0.num == connectedNodeNum })) - } label: { - - Image(systemName: "wifi") - .symbolRenderingMode(.hierarchical) - - Text("WiFi (ESP32 Only)") - } - .disabled(bleManager.connectedPeripheral == nil) - - Text("Default settings values are prefered as they consume no bandwidth when sent over the mesh.") - .font(.caption2) - .fixedSize(horizontal: false, vertical: true) } Section("Module Configuration") {