Skip to content

Commit

Permalink
refactor: remove ClientProxy MQTT status topic
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir authored and danwelch3 committed Oct 3, 2024
1 parent 2aab4fc commit 6c7a89b
Showing 1 changed file with 1 addition and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.geeksville.mesh.repository.network

import com.geeksville.mesh.MeshProtos.MqttClientProxyMessage
import com.geeksville.mesh.android.Logging
import com.geeksville.mesh.model.DeviceVersion
import com.geeksville.mesh.model.subscribeList
import com.geeksville.mesh.mqttClientProxyMessage
import com.geeksville.mesh.repository.datastore.RadioConfigRepository
Expand Down Expand Up @@ -41,7 +40,6 @@ class MQTTRepository @Inject constructor(
*/
private const val DEFAULT_QOS = 1
private const val DEFAULT_TOPIC_ROOT = "msh"
private const val STAT_TOPIC_LEVEL = "/2/stat/"
private const val DEFAULT_TOPIC_LEVEL = "/2/e/"
private const val JSON_TOPIC_LEVEL = "/2/json/"
private const val DEFAULT_SERVER_ADDRESS = "mqtt.meshtastic.org"
Expand All @@ -68,12 +66,6 @@ class MQTTRepository @Inject constructor(
sslContext.init(null, arrayOf<TrustManager>(TrustAllX509TrustManager()), SecureRandom())

val rootTopic = mqttConfig.root.ifEmpty { DEFAULT_TOPIC_ROOT }
val statTopic = "$rootTopic$STAT_TOPIC_LEVEL$ownerId"

// TODO remove after MeshService.minDeviceVersion >= 2.3.0
val myNodeInfo = radioConfigRepository.myNodeInfo.first()
val curVer = DeviceVersion(myNodeInfo?.firmwareVersion.orEmpty())
val defaultTopic = if (curVer < DeviceVersion("2.3.0")) "/2/c/" else DEFAULT_TOPIC_LEVEL

val connectOptions = MqttConnectOptions().apply {
userName = mqttConfig.username
Expand All @@ -82,7 +74,6 @@ class MQTTRepository @Inject constructor(
if (mqttConfig.tlsEnabled) {
socketFactory = sslContext.socketFactory
}
setWill(statTopic, "offline".encodeToByteArray(), DEFAULT_QOS, true)
}

val bufferOptions = DisconnectedBufferOptions().apply {
Expand All @@ -96,11 +87,9 @@ class MQTTRepository @Inject constructor(
override fun connectComplete(reconnect: Boolean, serverURI: String) {
info("MQTT connectComplete: $serverURI reconnect: $reconnect ")
channelSet.subscribeList.forEach { globalId ->
subscribe("$rootTopic$defaultTopic$globalId/#")
// subscribe("$rootTopic$DEFAULT_TOPIC_LEVEL$globalId/#")
subscribe("$rootTopic$DEFAULT_TOPIC_LEVEL$globalId/#")
if (mqttConfig.jsonEnabled) subscribe("$rootTopic$JSON_TOPIC_LEVEL$globalId/#")
}
// publish(statTopic, "online".encodeToByteArray(), DEFAULT_QOS, true)
}

override fun connectionLost(cause: Throwable) {
Expand Down

0 comments on commit 6c7a89b

Please sign in to comment.