mango.modules package

mango.modules.base_module module

This module contains the base class for basic modules that can be used inside agents to encapsulate complex functionality

class mango.modules.base_module.BaseModule(*, name: str, framework='mqtt', subscr_topics, pub_topics, broker)

Bases: object

An agent can have multiple specialized modules which inherit from BaseModule. The all need to specify which messaging framework should be used for the internal message exchange between the modules. TODO write more

frameworks = {'mqtt': <class 'mango.modules.mqtt_module.MQTTModule'>, 'rabbit': <class 'mango.modules.rabbit_module.RabbitModule'>, 'zero': <class 'mango.modules.zero_module.ZeroModule'>}
raise_exceptions(result)

Function used as a callback to raise exceptions :param result: result of the task

mango.modules.mqtt_module module

TODO

class mango.modules.mqtt_module.MQTTModule(*, name: str, subscr_topics, pub_topics, broker)

Bases: object

Module wrapper for a paho mqtt client used in the mango base module.

add_message_callback(topic, fkt)

Add a callback method in the mqtt client :param topic: the topic to bind the method to :param fkt: the method to bind :return: None

static bind_callback(func, client, userdata, message)

Function to call our generic callback function that has only two parameters from the framework specific callback with four parameters by binding it as a partial function.

Parameters:
  • func – The wanted callback function

  • client – the messaging client (unused)

  • userdata – the userdata object (unused)

  • message – the message payload

Returns:

None

conn(client, userdata, flags, reason_code, properties)

Callback method on broker connection on paho mqtt framework

Parameters:
  • client – the connecting client

  • userdata – userdata object

  • flags – returned flags

  • reason_code – reason code

  • properties – properties

Returns:

None

end_mq_thread()

Stop the message listening thread and disconnect the client :return:

log(client, userdata, level, buf)

Client log method

Parameters:
  • client – the mqtt client

  • userdata – userdata object

  • level – log level

  • buf – data buffer

Returns:

None

on_disconnect(client, userdata, disconnect_flags, reason_code, properties)

Callback method on broker disconnect on paho mqtt framework

Parameters:
  • client – the connecting client

  • userdata – userdata object

  • reason_code – reason code

  • properties – properties

Returns:

None

on_mqtt_msg(client, userdata, message)
Each module has to implement this to handle all messages it receives

in subscribed topics

Parameters:
  • client

  • userdata

  • message

Returns:

publish_mq_message(topic, payload, retain=False)

Publish a message to the mqtt broker. :param topic: the topic to publish on :param payload: the message to publish :param retain: flag indicating if the message should be retained on shutdown :return: None

start_mq_thread()

Start the message listening thread :return: None

mango.modules.rabbit_module module

class mango.modules.rabbit_module.RabbitModule(*, name: str, subscr_topics, pub_topics, broker)

Bases: ABC

add_message_callback(topic, fkt)
bind_callback(topic, func, ch, method, properties, message)
end_mq_thread()
publish_mq_message(topic, payload)
run_mq()
start_mq_thread()

mango.modules.zero_module module

class mango.modules.zero_module.ZeroModule(*, name: str, subscr_topics, pub_topics, broker)

Bases: ABC

add_message_callback(topic, fkt)
bind_callback(func, client, userdata, message)
end_mq_thread()
publish_mq_message(topic, payload)
run_mq()
start_mq_thread()