Availability |
Odoo Online
Odoo.sh
On Premise
|
Lines of code | 114 |
Technical Name |
mqtt_abstract_interface |
License | LGPL-3 |
Website | https://www.tectronix.cl |
Availability |
Odoo Online
Odoo.sh
On Premise
|
Lines of code | 114 |
Technical Name |
mqtt_abstract_interface |
License | LGPL-3 |
Website | https://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:
- Inherit the interface into one of your module's models
- Implement the required methods
- Mount your Broker server
- Create an automated action to start mqtt
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?
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 : locallhostPort : 1883Ttl :60The 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:
- Download and install paho-mqtt library.
- Extend your custom model with the abstract interface.
- Implement the methods previously described.
- Create automatized actions to start Mqtt and subscribes topics
State of the module and future updates.
- Multi connection to brokers and a manage wizard for its.
- Auto creation of the automatized action.
Please log in to comment on this module
Report comment
Any abuse of this reporting system will be penalizedgood to start
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
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
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
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
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?
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?
Hi Tectronix Spa, when I clicked the button "Download for v11.0", nothing was downloaded. What shall I do to download your code? 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