MQTT persistence worked in 2.0.0 snapshot but not 2.1.0 release


(bri) #1

Hi I haven’t updated in a long time, but I was running one of the 2.0.0 snapshot builds. Since then I have upgraded to 2.1.0 release (not nightly) and my states have stopped publishing to mqtt. Here is my config:

/opt/openhab/conf/services/

$cat mqtt.cfg 
#
#
# Define your MQTT broker connections here for use in the MQTT Binding or MQTT
# Persistence bundles. Replace <broker> with an ID you choose.
#

# URL to the MQTT broker, e.g. tcp://localhost:1883 or ssl://localhost:8883
#<broker>.url=tcp://<host>:1883
mqb.url=tcp://localhost:1883

# Optional. Client id (max 23 chars) to use when connecting to the broker.
# If not provided a default one is generated.
mqb.clientId=openhab

# Optional. User id to authenticate with the broker.
#<broker>.user=<user>

# Optional. Password to authenticate with the broker.
#<broker>.pwd=<password>

# Optional. Set the quality of service level for sending messages to this broker.
# Possible values are 0 (Deliver at most once),1 (Deliver at least once) or 2
# (Deliver exactly once). Defaults to 0.
#<broker>.qos=<qos>

# Optional. True or false. Defines if the broker should retain the messages sent to
# it. Defaults to false.
#<broker>.retain=<retain>

# Optional. True or false. Defines if messages are published asynchronously or
# synchronously. Defaults to true.
#<broker>.async=<async>

# Optional. Defines the last will and testament that is sent when this client goes offline
# Format: topic:message:qos:retained <br/>
#<broker>.lwt=<last will definition>
$cat mqtt-persistence.cfg 
#
# Name of the broker as defined in mqtt.cfg
broker=mqb

# The MQTT topic to which the persistence messages should be sent.
topic=ohab

# A string representing the persistence message content.
message=%1$s|%3$s

/opt/openhab/conf/persistence

$cat mqtt.persist 
Strategies {
        default = everyChange
}
Items {
        // persist all items every hour and on every change
        * : strategy = everyChange
}

I am just trying to publish everything to that ohab topic.

Any help is greatly appreciated

Thanks,
Bri


(bri) #2

I can switch back to the 2.0.0 snapshot and it works with those same files. Am I missing something I should configure in the 2.1.0 release? Any suggestions greatly appreciated. I just want to send mqtt messages on any state change. Is there some other way?


(Angelos) #3

If you are interested to publish all item states from openHAB2 to the MQTT Broker, you could use the MQTT-EventBus solution:

  • Setup your broker connection with the $OPENHAB_CONF/services/mqtt.cfg
    ($OPENHAB_CONF = /opt/openhab/conf in your case)
mqb.url=tcp://localhost:1883
mqb.clientId=openhab
  • Define within $OPENHAB_CONF/services/mqtt-eventbus.cfg your publishing settings
    (and optionally, your subscribing):
broker=mqb
statePublishTopic=openhab/out/${item}/state
commandPublishTopic=openhab/out/${item}/command
stateSubscribeTopic=openhab/in/${item}/state
commandSubscribeTopic=openhab/in/${item}/command

This will send the state of every $item to a separate topic. Keep in mind that this is a massive link. It will “connect” the entire Event Bus of openHAB2 to the Broker.

For persistence, I recommend using a 2-tier solution as @rlkoshak wrote here: Good Tutorial On Persistence (RRD4J and JDBC-MYSQL)?.

  • mapdb for everyChange & restoreOnStartup (set as the default persistence service)
  • Influxdb for everyChange to be used with Grafana
  • Optionally, a 3rd tier with MySQL would be nice also but heavy :slight_smile:

MQTT persistence doesn’t really store historical data. It’s only used for publishing states of selected items to the broker.
It has the advantage of fine tuning the mqtt.persist to define a strategy of what to “persist” (put the items for which you want to publish the state in a group, then persist the group members)


MQTT Setup - File not found
(bri) #4

Thank you so much @Dim ! I will try this after the holiday weekend. That looks like it would do exactly what I want. I currently use openhab as a zwave gateway/bridge so I don’t have really any other state changes other than the zwave stuff which I track all that.

Thanks Again