Clean up phone telemetry

This commit is contained in:
Garth Vander Houwen 2022-07-26 07:35:16 -07:00
parent 920e200593
commit 0a386c531e
4 changed files with 150 additions and 66 deletions

View file

@ -1169,6 +1169,55 @@ class BLEManager: NSObject, ObservableObject, CBCentralManagerDelegate, CBPeriph
return 0
}
public func getCannedMessageModuleMessages(destNum: Int64, wantResponse: Bool) -> Bool {
var adminPacket = AdminMessage()
adminPacket.getCannedMessageModulePart1Request = true
//adminPacket.getOwnerRequest = true
var meshPacket: MeshPacket = MeshPacket()
meshPacket.to = UInt32(connectedPeripheral.num)
meshPacket.from = 0 //UInt32(connectedPeripheral.num)
meshPacket.id = UInt32.random(in: UInt32(UInt8.max)..<UInt32.max)
meshPacket.priority = MeshPacket.Priority.reliable
meshPacket.wantAck = wantResponse
var dataMessage = DataMessage()
dataMessage.payload = try! adminPacket.serializedData()
dataMessage.portnum = PortNum.adminApp
meshPacket.decoded = dataMessage
var toRadio: ToRadio!
toRadio = ToRadio()
toRadio.packet = meshPacket
let binaryData: Data = try! toRadio.serializedData()
if connectedPeripheral!.peripheral.state == CBPeripheralState.connected {
do {
try context!.save()
if meshLoggingEnabled { MeshLogger.log("💾 Saved a Canned Messages Module Get Messages Request Admin Message for node: \(String(destNum))") }
connectedPeripheral.peripheral.writeValue(binaryData, for: TORADIO_characteristic, type: .withResponse)
return true
} catch {
context!.rollback()
let nsError = error as NSError
print("💥 Error Inserting New Core Data MessageEntity: \(nsError)")
}
}
return false
}
public func saveExternalNotificationModuleConfig(config: ModuleConfig.ExternalNotificationConfig, fromUser: UserEntity, toUser: UserEntity, wantResponse: Bool) -> Int64 {
var adminPacket = AdminMessage()

View file

@ -190,14 +190,16 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont
newLoRaConfig.modemPreset = 0
// 3 Hops default protobuf value of 0
newLoRaConfig.hopLimit = 0
// Default value of 0 is 22dbm
newLoRaConfig.txPower = 0
} else {
// UNSET default protobuf value of 0
newLoRaConfig.regionCode = Int32(config.lora.region.rawValue)
// LongFast default protobuf value of 0
newLoRaConfig.modemPreset = Int32(config.lora.modemPreset.rawValue)
// 3 Hops default protobuf value of 0
newLoRaConfig.hopLimit = Int32(config.lora.hopLimit)
newLoRaConfig.txPower = Int32(config.lora.txPower)
}
fetchedNode[0].loRaConfig = newLoRaConfig
@ -212,14 +214,15 @@ func localConfig (config: Config, meshlogging: Bool, context:NSManagedObjectCont
fetchedNode[0].loRaConfig?.modemPreset = 0
// 3 Hops default protobuf value of 0
fetchedNode[0].loRaConfig?.hopLimit = 0
// Default value of 0 is 22dbm
fetchedNode[0].loRaConfig?.txPower = 0
} else {
// UNSET default protobuf value of 0
fetchedNode[0].loRaConfig?.regionCode = Int32(config.lora.region.rawValue)
// LongFast default protobuf value of 0
fetchedNode[0].loRaConfig?.modemPreset = Int32(config.lora.modemPreset.rawValue)
// 3 Hops default protobuf value of 0
fetchedNode[0].loRaConfig?.hopLimit = Int32(config.lora.hopLimit)
fetchedNode[0].loRaConfig?.txPower = Int32(config.lora.txPower)
}
}
@ -417,6 +420,7 @@ func moduleConfig (config: ModuleConfig, meshlogging: Bool, context:NSManagedObj
try context.save()
if meshlogging { MeshLogger.log("💾 Updated Canned Message Module Config for node number: \(String(nodeNum))") }
print(try config.cannedMessage.jsonString())
} catch {

View file

@ -88,7 +88,7 @@ struct TelemetryLog: View {
let sensor = SensorTypes(rawValue: Int(node.telemetryConfig?.environmentSensorType ?? 0))
let tempReadingType = (!(node.telemetryConfig?.environmentDisplayFahrenheit ?? true)) ? "°F" : "°C"
let tempReadingType = (!(node.telemetryConfig?.environmentDisplayFahrenheit ?? true)) ? "°C" : "°F"
if sensor == SensorTypes.bme280 ||
sensor == SensorTypes.bme680 ||
@ -178,8 +178,9 @@ struct TelemetryLog: View {
if tel.metricsType == 0 {
// Device Metrics
// Device Metrics iPhone Template
VStack {
HStack {
Spacer()
@ -243,94 +244,121 @@ struct TelemetryLog: View {
// Environment Metrics
let sensor = SensorTypes(rawValue: Int(node.telemetryConfig?.environmentSensorType ?? 0))
let tempReadingType = (!(node.telemetryConfig?.environmentDisplayFahrenheit ?? true)) ? "°F" : "°C"
let tempReadingType = (!(node.telemetryConfig?.environmentDisplayFahrenheit ?? true)) ? "°C" : "°F"
// Environment Metrics iPhone Template
VStack {
Text("Environment Metrics")
.font(.title3)
if sensor == SensorTypes.bme280 ||
sensor == SensorTypes.bme680 ||
sensor == SensorTypes.shtc3 ||
sensor == SensorTypes.mcp9808 {
HStack {
Image(systemName: "thermometer")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Temperature: \(String(format: "%.2f", tel.temperature))\(tempReadingType)")
.foregroundColor(.gray)
.font(.callout)
Spacer()
Text("Environment Metrics")
.font(.title3)
Spacer()
}
if sensor == SensorTypes.bme280 ||
sensor == SensorTypes.bme680 ||
sensor == SensorTypes.shtc3 {
Image(systemName: "humidity")
HStack {
if sensor == SensorTypes.bme280 ||
sensor == SensorTypes.bme680 ||
sensor == SensorTypes.shtc3 ||
sensor == SensorTypes.mcp9808 {
Image(systemName: "thermometer")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Temperature: \(String(format: "%.2f", tel.temperature))\(tempReadingType)")
.foregroundColor(.gray)
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Relative Humidity: \(String(format: "%.2f", tel.relativeHumidity))")
.foregroundColor(.gray)
.font(.callout)
}
}
HStack {
if sensor == SensorTypes.bme280 ||
sensor == SensorTypes.bme680 ||
sensor == SensorTypes.shtc3 {
Image(systemName: "humidity")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Relative Humidity: \(String(format: "%.2f", tel.relativeHumidity))")
.foregroundColor(.gray)
.font(.callout)
}
}
if sensor == SensorTypes.ina219 ||
sensor == SensorTypes.ina260 {
Image(systemName: "directcurrent")
HStack {
Image(systemName: "directcurrent")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Current: \(String(format: "%.2f", tel.current))")
.foregroundColor(.gray)
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Current: \(String(format: "%.2f", tel.current))")
.foregroundColor(.gray)
.font(.callout)
}
Image(systemName: "bolt")
HStack {
Image(systemName: "bolt")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Voltage: \(String(format: "%.2f", tel.voltage))")
.foregroundColor(.gray)
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Voltage: \(String(format: "%.2f", tel.voltage))")
.foregroundColor(.gray)
.font(.callout)
}
}
if sensor == SensorTypes.bme280 ||
sensor == SensorTypes.bme680 {
Image(systemName: "barometer")
HStack {
Image(systemName: "barometer")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Barometric Pressure: \(String(format: "%.2f", tel.barometricPressure))")
.foregroundColor(.gray)
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Barometric Pressure: \(String(format: "%.2f", tel.barometricPressure))")
.foregroundColor(.gray)
.font(.callout)
}
}
if sensor == SensorTypes.bme680 {
Image(systemName: "aqi.medium")
HStack {
Image(systemName: "aqi.medium")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Gas Resistance: \(String(format: "%.2f", tel.gasResistance))")
.foregroundColor(.gray)
.font(.callout)
}
}
HStack {
Image(systemName: "clock.badge.checkmark.fill")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Gas Resistance: \(String(format: "%.2f", tel.gasResistance))")
Text("Time:")
.foregroundColor(.gray)
.font(.callout)
DateTimeText(dateTime: tel.time)
.foregroundColor(.gray)
.font(.callout)
}
Image(systemName: "clock.badge.checkmark.fill")
.font(.callout)
.foregroundColor(.accentColor)
.symbolRenderingMode(.hierarchical)
Text("Time:")
.foregroundColor(.gray)
.font(.callout)
DateTimeText(dateTime: tel.time)
.foregroundColor(.gray)
.font(.callout)
}
}
}

View file

@ -362,6 +362,9 @@ struct CannedMessagesConfig: View {
self.inputbrokerPinA = Int(node!.cannedMessageConfig?.inputbrokerPinA ?? 0)
self.inputbrokerPinB = Int(node!.cannedMessageConfig?.inputbrokerPinB ?? 0)
self.inputbrokerPinPress = Int(node!.cannedMessageConfig?.inputbrokerPinPress ?? 0)
self.inputbrokerEventCw = Int(node!.cannedMessageConfig?.inputbrokerEventCw ?? 0)
self.inputbrokerEventCcw = Int(node!.cannedMessageConfig?.inputbrokerEventCcw ?? 0)
self.inputbrokerEventPress = Int(node!.cannedMessageConfig?.inputbrokerEventPress ?? 0)
self.hasChanges = false
self.initialLoad = false
}