Skip to content

Commit

Permalink
fix: don't mix MQTT topics
Browse files Browse the repository at this point in the history
  • Loading branch information
andrekir committed Mar 19, 2024
1 parent ee61b79 commit 0948f8e
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ 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 @@ -69,6 +70,11 @@ class MQTTRepository @Inject constructor(
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
password = mqttConfig.password.toCharArray()
Expand All @@ -90,7 +96,8 @@ class MQTTRepository @Inject constructor(
override fun connectComplete(reconnect: Boolean, serverURI: String) {
info("MQTT connectComplete: $serverURI reconnect: $reconnect ")
channelSet.subscribeList.forEach { globalId ->
subscribe("$rootTopic$DEFAULT_TOPIC_LEVEL$globalId/#")
subscribe("$rootTopic$defaultTopic$globalId/#")
// subscribe("$rootTopic$DEFAULT_TOPIC_LEVEL$globalId/#")
if (mqttConfig.jsonEnabled) subscribe("$rootTopic$JSON_TOPIC_LEVEL$globalId/#")
}
// publish(statTopic, "online".encodeToByteArray(), DEFAULT_QOS, true)
Expand Down

0 comments on commit 0948f8e

Please sign in to comment.