Mqtt Abstract Interface

by
Odoo
v 11.0 Third Party 515
Download for v 11.0 Deploy on Odoo.sh
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 114
Technical Name mqtt_abstract_interface
LicenseLGPL-3
Websitehttps://www.tectronix.cl
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 114
Technical Name mqtt_abstract_interface
LicenseLGPL-3
Websitehttps://www.tectronix.cl

MQTT Abstract interface

Add MQTT functionalities to your modules

Tectronix Spa - www.tectronix.cl

Overview

This is a technical base module that enable Mqtt communication between Odoo database, your modules and IoT devices through a Broker server.

Requirements

There is two requirements for the correct operation of this module:

  • paho-mqtt library:
    A python's library developed by Eclipse, for Mqtt Protocol. It can be installed via the Pip package manager (Official site: https://pypi.org/project/paho-mqtt/)

  • Broker server:
    The broker is encharged of distribute the messages between the devices and database. Mosquitto (An open source MQTT broker) is recommended because it is simple, effective and efficient, also developed by eclipse. Can be easily deploy in no more than three or four lines in a console. (Official site)

How install it?

It can be easily deployed in four steps:

  1. Inherit the interface into one of your module's models
  2. Implement the required methods
  3. Mount your Broker server
  4. Create an automated action to start mqtt
The automated action must be "action_start_mqtt (topic)" to start the MQTT Client and subscribe to the topic parameter. This automated action must be executed every minute, for ensure the correct functioning of the module.

Documentation for Mqtt Abstract Interface

Contents:

  • How works this module?
  • Requirements
  • What contains this module?
  • What must I implement?
  • How use it?
  • State of the module and future updates.

How works this module?

This is a Abstract technical module for Developers, that allows other models / modules to have Mqtt communication with devices through a broker.

For this, the module that must have connectivity through mqtt, must inherit this interface in one of its models and implement the methods that will be described later in the documentation.

Requirements

This module require external dependencies:

  • Paho-mqtt library for python (install with pip).
  • A Broker server (like Mosquitto)

What contains this module?

This model only contains two files:

Main.py:

This python file acts as a controller for the MqttAbstractInterface model, it contains all the methods necessaries to connect to a broker and subscribe to topics.
The controller start a thread, that receives "tasks" from the model (subscribe, publish, connect, etc..) and put them in a queue where they are executed one by one by the model.

Mqtt_abstract_interface_model.py:

This file contains the MqttAbstractInterface class (the abstract model) that is inherited by another's models. This class has 3 methods that requires implemententation:
  • on_message(self, client, userdata, msg):
    This method is a callback executed when there are a incoming message from a topic, this message contain a payload (msg.payload) that must by processed in this method to extract the necessaries parameters and pass it to the "create record" method.
  • create_record(self, values):
    This method is responsible for the creation of records in the database, from the "values" dictionary that contains the data needed for the model.
  • mqtt_publish(self, toic, message):
    This is a optional method for adding functionalities to the original "publish" method (It's necessary include the original method)

What must I implement?

In addition to the methods already mentioned it's necessary serve the broker and create an automated action with the model that inherit the abstract interface which includes the followings methods:

  • action_start_mqtt(self):
    This method initiates the mqtt client in a thread and starts a connection with the broker. The defaults values are:
    Server : locallhost
    Port : 1883
    Ttl :60
    The changes in this values must be done directly in the font code.
  • subscribe(self, topic):

    This method subscribes the client to a topic, the "topic" parameter is optional, with default value '#' (for subscribe to all topics.

How use it

It can be easily initialized:

  1. Download and install paho-mqtt library.
  2. Extend your custom model with the abstract interface.
  3. Implement the methods previously described.
  4. Create automatized actions to start Mqtt and subscribes topics

State of the module and future updates.

This technicall module is a beta version and many features will be impleted in the future.
Some of this features will be:
  • Multi connection to brokers and a manage wizard for its.
  • Auto creation of the automatized action.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.
good to start
by
YoC
on 9/2/22, 10:31 AM

Hi,

Could someone share a simple example of a model created from this module?
Thanks


I cann't install module, when install odoo notification "Unable to install module "mqtt_abstract_interface" because an external dependency is not met: No module named paho". help me, pleaseee. Thanks
by
dnguyenhoai@gmail.com
on 4/27/21, 10:43 PM


Re: I cann't install module, when install odoo notification "Unable to install module "mqtt_abstract_interface" because an external dependency is not met: No module named paho". help me, pleaseee. Thanks
by
giovani
on 4/28/21, 9:55 AM Author

Hi:

Yes, you need install first the Paho Mqtt Lib.

  • paho-mqtt library:
    A python's library developed by Eclipse, for Mqtt Protocol. It can be installed via the Pip package manager (Official site: https://pypi.org/project/paho-mqtt/)

good Luck

Re: I cann't install module, when install odoo notification "Unable to install module "mqtt_abstract_interface" because an external dependency is not met: No module named paho". help me, pleaseee. Thanks
by
giovani
on 4/28/21, 9:55 AM Author

Hi:

Yes, you need install first the Paho Mqtt Lib.

  • paho-mqtt library:
    A python's library developed by Eclipse, for Mqtt Protocol. It can be installed via the Pip package manager (Official site: https://pypi.org/project/paho-mqtt/)

good Luck


not bad
by
joshua
on 4/29/20, 5:37 AM

Hi, I am facing a problem, when i received a publish message from a topic, i try to call the create_record method. Inside create_record method my code is something like " self.env['sale.order'].create(vals) ", I want to create a sale order record using the data receive from on_message. But in Log file, the on_log function return me "Caught exception in on_message: environments ". Do you have any idea about it? Thanks in advance. Regards Joshua


Is the hyperlink for "Download for v11.0" available?
by
chenxi
on 8/13/21, 1:23 PM

Hi Tectronix Spa, when I clicked the button "Download for v11.0", nothing was downloaded. What shall I do to download your code? Thanks.


Is the hyperlink for "Download for v11.0" available?
by
chenxi
on 8/13/21, 1:20 PM

Hi Tectronix Spa, when I clicked the button "Download for v11.0", nothing was downloaded. What shall I do to download your code? Thanks.


by
dnguyenhoai@gmail.com
on 4/27/21, 10:43 PM

I cann't install module, when install odoo notification "Unable to install module "mqtt_abstract_interface" because an external dependency is not met: No module named paho". help me, pleaseee. Thanks