mirror of
https://github.com/meshtastic/Meshtastic-Apple.git
synced 2026-04-20 22:13:56 +00:00
Delete unnecessary MQTT nonsense
This commit is contained in:
parent
0231e110fb
commit
dc53ef743e
2 changed files with 7 additions and 40 deletions
|
|
@ -12,14 +12,14 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
|
||||
// MqttClientProxyManagerDelegate
|
||||
func onMqttConnected() {
|
||||
mqttManager.status = .connected
|
||||
//mqttManager.status = .connected
|
||||
mqttProxyConnected = true
|
||||
print("📲 Mqtt Client Proxy onMqttConnected now subscribing to \(mqttManager.topic).")
|
||||
mqttManager.mqttClientProxy?.subscribe(mqttManager.topic)
|
||||
}
|
||||
|
||||
func onMqttDisconnected() {
|
||||
mqttManager.status = .disconnected
|
||||
// mqttManager.status = .disconnected
|
||||
mqttProxyConnected = false
|
||||
print("MQTT Disconnected")
|
||||
}
|
||||
|
|
@ -47,6 +47,7 @@ class BLEManager: NSObject, CBPeripheralDelegate, MqttClientProxyManagerDelegate
|
|||
}
|
||||
|
||||
func onMqttError(message: String) {
|
||||
mqttProxyConnected = false
|
||||
print("MQTT Error")
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -16,31 +16,12 @@ protocol MqttClientProxyManagerDelegate: AnyObject {
|
|||
}
|
||||
|
||||
class MqttClientProxyManager {
|
||||
enum ConnectionStatus {
|
||||
case connecting
|
||||
case connected
|
||||
case disconnecting
|
||||
case disconnected
|
||||
case error
|
||||
case none
|
||||
}
|
||||
|
||||
enum MqttQos: Int {
|
||||
case atMostOnce = 0
|
||||
case atLeastOnce = 1
|
||||
case exactlyOnce = 2
|
||||
}
|
||||
|
||||
// Singleton Instance
|
||||
static let shared = MqttClientProxyManager()
|
||||
|
||||
private static let defaultKeepAliveInterval: Int32 = 60
|
||||
|
||||
weak var delegate: MqttClientProxyManagerDelegate?
|
||||
var status = ConnectionStatus.none
|
||||
|
||||
var mqttClientProxy: CocoaMQTT?
|
||||
|
||||
var topic = "msh/2/c"
|
||||
|
||||
private init() {
|
||||
|
|
@ -81,8 +62,6 @@ class MqttClientProxyManager {
|
|||
return
|
||||
}
|
||||
|
||||
status = .connecting
|
||||
|
||||
let clientId = "MeshtasticAppleMqttProxy-" + String(ProcessInfo().processIdentifier)
|
||||
|
||||
mqttClientProxy = CocoaMQTT(clientID: clientId, host: host, port: UInt16(port))
|
||||
|
|
@ -103,17 +82,14 @@ class MqttClientProxyManager {
|
|||
let success = mqttClient.connect()
|
||||
if !success {
|
||||
delegate?.onMqttError(message: "Mqtt connect error")
|
||||
status = .error
|
||||
}
|
||||
} else {
|
||||
delegate?.onMqttError(message: "Mqtt initialization error")
|
||||
status = .error
|
||||
}
|
||||
}
|
||||
|
||||
func subscribe(topic: String, qos: MqttQos) {
|
||||
func subscribe(topic: String, qos: CocoaMQTTQoS) {
|
||||
print("📲 MQTT Client Proxy subscribed to: " + topic)
|
||||
let qos = CocoaMQTTQoS(rawValue :UInt8(qos.rawValue))!
|
||||
mqttClientProxy?.subscribe(topic, qos: qos)
|
||||
}
|
||||
|
||||
|
|
@ -122,21 +98,16 @@ class MqttClientProxyManager {
|
|||
print("📲 MQTT Client Proxy unsubscribe for: " + topic)
|
||||
}
|
||||
|
||||
func publish(message: String, topic: String, qos: MqttQos) {
|
||||
let qos = CocoaMQTTQoS(rawValue :UInt8(qos.rawValue))!
|
||||
func publish(message: String, topic: String, qos: CocoaMQTTQoS) {
|
||||
mqttClientProxy?.publish(topic, withString: message, qos: qos)
|
||||
print("📲 MQTT Client Proxy publish for: " + topic)
|
||||
}
|
||||
|
||||
func disconnect() {
|
||||
//MqttSettings.shared.isConnected = false
|
||||
|
||||
if let client = mqttClientProxy {
|
||||
status = .disconnecting
|
||||
client.disconnect()
|
||||
print("📲 MQTT Client Proxy Disconnected")
|
||||
} else {
|
||||
status = .disconnected
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -170,21 +141,16 @@ extension MqttClientProxyManager: CocoaMQTTDelegate {
|
|||
print(errorDescription)
|
||||
delegate?.onMqttError(message: errorDescription)
|
||||
|
||||
//self.disconnect() // Stop reconnecting
|
||||
//mqttSettings.isConnected = false // Disable automatic connect on start
|
||||
self.disconnect()
|
||||
}
|
||||
|
||||
self.status = ack == .accept ? ConnectionStatus.connected : ConnectionStatus.error // Set AFTER sending onMqttError (so the delegate can detect that was an error while establishing connection)
|
||||
}
|
||||
|
||||
func mqttDidDisconnect(_ mqtt: CocoaMQTT, withError err: Error?) {
|
||||
print("mqttDidDisconnect: \(err?.localizedDescription ?? "")")
|
||||
|
||||
if let error = err, status == .connecting {
|
||||
if let error = err {
|
||||
delegate?.onMqttError(message: error.localizedDescription)
|
||||
}
|
||||
|
||||
status = err == nil ? .disconnected : .error
|
||||
delegate?.onMqttDisconnected()
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue