From HFML-FELIX Wiki
Revision as of 18:57, 9 July 2020 by Claessen (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
mqtt_daemon
python package
mqtt_daemon logo
Rapid deployment of linux/windows daemons that communicate via MQTT.
Language Python
Repository mqtt_daemon on gitlab

MQTT daemon is a Python library for quickly developing linux/windows daemons that communicate via MQTT. The master repository can be found on the science gitlab server.

Design philosophy

[edit | edit source]

The idea is that you create a class for your specific purpose, like talking to a certain hardware (e.g. a network device, or a serial device, or an FLARE undulatord), and then you would like to have this object 1) communicate with other software via MQTT 2) run as a daemon/service. This is where mqtt_daemon comes in. You can create a new daemon class (as a child class of mqtt_daemon), and have it inherit all the things required to communicate and daemonize. There is a callback for sending MQTT messages. You can define which topics to listen to, and then you define which functions to call on your specific object. The rest is handled for you. Mqtt_daemon itself relies on felix_mqtt for the mqtt communication, and on linux_daemon or windows_daemon to handle the daemonization. It's sort of the glue that binds all those things together.

class example_thing(object)                                                    # could also be a Thread
class example_daemon(mqtt_daemon):
  def setup(self):                                                             # this is called once by mqtt_daemon
    self.e = example_thing()
    self.mqtt.subscribe('FELIX/example/setpoint', self.new_setpoint_received)
  def loop(self):
    self.e.check_something_regularly()
    if self.e.want_to_quit:
      self.alive = False
  def new_setpoint_received(self, message):                                    # actually this gets some more parameters (see code), this is pseudo-code
    self.e.do_something_with(message)
  def end(self):
    self.e.stop()

In use at FELIX

[edit | edit source]

<DynamicPageList> category = MQTT_daemon ordermethod = sortkey order = ascending </DynamicPageList>

Dependencies

[edit | edit source]

Installation

[edit | edit source]
pip install git+https://gitlab.science.ru.nl/felix/mqtt_daemon.git