Skip to content

Commit

Permalink
fixed reconnecting to to mqttServer also resubscribing
Browse files Browse the repository at this point in the history
  • Loading branch information
jollyjinx committed Oct 16, 2023
1 parent da46a94 commit d82bf26
Showing 1 changed file with 2 additions and 11 deletions.
13 changes: 2 additions & 11 deletions Sources/modbus2mqtt/modbus2mqtt.swift
Original file line number Diff line number Diff line change
Expand Up @@ -183,17 +183,7 @@ func startServing(modbusDevice: ModbusDevice, mqttServer: JNXMQTTServer, options
let requestPath = "\(mqttServer.topic)/request"
let responsePath = "\(mqttServer.topic)/response"

for modbusDefinition in modbusDefinitions.values
{
switch modbusDefinition.modbusaccess
{
case .read: break

case .write: fallthrough
case .readwrite: let topic = requestPath + "/#"
try await mqttClient.subscribe(to: topic)
}
}
try await mqttClient.subscribe(to: requestPath + "/#")

let staticDefinitions = modbusDefinitions.values
Task
Expand Down Expand Up @@ -392,6 +382,7 @@ func startServing(modbusDevice: ModbusDevice, mqttServer: JNXMQTTServer, options
modbusDefinitions.keys.forEach { address in modbusDefinitions[address]!.nextReadDate = .distantPast }

try await mqttClient.reconnect()
try await mqttClient.subscribe(to: requestPath + "/#")

guard mqttClient.isConnected
else
Expand Down

0 comments on commit d82bf26

Please sign in to comment.