Skip to content

Commit

Permalink
Release 0.8.8
Browse files Browse the repository at this point in the history
  • Loading branch information
Kunsi committed Mar 27, 2021
2 parents 2eb4a68 + 964c9e1 commit c8fc199
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ plugins:

## Helpers

### mqtt_publish(topic, payload, retained=False, qos=0, allow_queueing=False)
### mqtt_publish(topic, payload, retained=False, qos=0, allow_queueing=False, raw_data=False)

Publishes `payload` to `topic`. If `retained` is set to `True`, message will be flagged to be retained by the
broker. The QOS setting can be overridden with the `qos` parameter.

`payload` may be a string in which case it will be sent as is. Otherwise a value conversion to JSON will be performed.
`payload` may be a string in which case it will be sent as is. Otherwise a value conversion to JSON will be performed, unless you set `raw_data` to `True`.

If the MQTT plugin is currently not connected to the broker but `allow_queueing` is `True`, the message will be
stored internally and published upon connection to the broker.
Expand Down
12 changes: 9 additions & 3 deletions octoprint_mqtt/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class MqttPlugin(octoprint.plugin.SettingsPlugin,
def __init__(self):
self._mqtt = None
self._mqtt_connected = False
self._mqtt_reset_state = True

self._mqtt_subscriptions = []

Expand Down Expand Up @@ -195,7 +196,7 @@ def on_print_progress(self, storage, path, progress):
if self._settings.get_boolean(["publish", "printerData"]):
data['printer_data'] = self._printer.get_current_data()

self.mqtt_publish_with_timestamp(topic.format(progress="printing"), data)
self.mqtt_publish_with_timestamp(topic.format(progress="printing"), data, retained=True)

def on_slicing_progress(self, slicer, source_location, source_path, destination_location, destination_path, progress):
topic = self._get_topic("progress")
Expand Down Expand Up @@ -355,8 +356,8 @@ def mqtt_publish_with_timestamp(self, topic, payload, qos=0, allow_queueing=Fals

return self.mqtt_publish(topic, payload, qos=qos, allow_queueing=allow_queueing)

def mqtt_publish(self, topic, payload, qos=0, allow_queueing=False):
if not isinstance(payload, six.string_types):
def mqtt_publish(self, topic, payload, retained=False, qos=0, allow_queueing=False, raw_data=False):
if not (isinstance(payload, basestring) or raw_data):
payload = json.dumps(payload)

if not self._mqtt_connected:
Expand Down Expand Up @@ -444,6 +445,11 @@ def _on_mqtt_connect(self, client, userdata, flags, rc):

self._mqtt_connected = True

if self._mqtt_reset_state:
self.on_print_progress("", "", 0)
self.on_slicing_progress("", "", "", "", "", 0)
self._mqtt_reset_state = False

def _on_mqtt_disconnect(self, client, userdata, rc):
if not client == self._mqtt:
return
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
plugin_name = "OctoPrint-MQTT"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.8.7"
plugin_version = "0.8.8"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit c8fc199

Please sign in to comment.