Aparatos por MQTT (sensores, básculas, autómatas)
Conecta Odoo con sensores, básculas, autómatas, lectores y cerraduras por MQTT: los aparatos publican en un broker (Mosquitto, EMQX, HiveMQ…), el puente GERP MQTT trae sus mensajes a Odoo y Odoo les envía órdenes. Temas que se escuchan con su valor e historial, una acción de Odoo por cada mensaje y órdenes con su botón.
- Technical name
gerp_mqtt- Author
- GestioERP · SIAM Cloud
What it is and how it works
MQTT es la mensajería ligera que usan los aparatos. Ninguno se conecta a Odoo directamente: todos hablan con un intermediario, el broker, publicando en «temas» como planta/linea1/temperatura. Lo que publican lo trae a Odoo el puente GERP MQTT, un servicio aparte que no frena a Odoo; lo que Odoo quiere decirles lo publica él mismo en el broker al momento.
- Da de alta el broker en «Brokers» y pulsa «Probar la conexión».
- Pon en marcha el puente con la dirección de Odoo y la «Clave del puente».
- Añade los temas que quieres escuchar.
- Mira en «Mensajes» cómo van llegando.
Temas que se escuchan
Un tema es la dirección donde publica un aparato. Se puede escuchar uno exacto o varios a la vez con comodines: «+» vale por un nivel (planta/+/telemetria) y «#» por todo lo que sigue (almacen/#). De cada mensaje Odoo saca un valor numérico, guarda la última lectura y, si quieres, el historial.
Órdenes a los aparatos
Una orden es un mensaje preparado para un aparato: abrir una puerta, arrancar una línea, encender una luz. Se envía con su botón «Enviar» y queda apuntada en «Mensajes». Las automatizaciones de Odoo también pueden enviar órdenes cuando pasa algo (se valida un albarán, empieza una orden de trabajo).
Questions
- What is MQTT?
- MQTT is the lightweight messaging used by devices (sensors, scales, PLCs). Devices do not connect to Odoo: they publish to a go-between, the broker, and the GERP MQTT bridge brings their messages to Odoo. Odoo publishes its commands for them to the same broker.
- How do I add a broker?
- Menu «Misc › Devices (MQTT) › Brokers» › «New»: name, address, port (1883, or 8883 encrypted), user and password. Save and press «Test connection».
- What is the GERP MQTT bridge?
- The bridge is a separate service that listens to the broker and brings the messages to Odoo. It only needs this Odoo's address (GERP_URL) and the «Bridge key» (GERP_TOKEN), both on the broker form. If the form says the bridge is not connected, it is not running or the key is wrong. It is not needed to send commands.
- How do I listen to a topic?
- Menu «Misc › Devices (MQTT) › Topics listened to» › «New»: description and topic. «+» stands for one level (planta/+/telemetria) and «#» for everything after (almacen/#). The bridge picks up the change by itself.
- How do I get the value of a message?
- On the topic, «Value field»: the name of the number inside the JSON, for example temperatura, or medida.peso if it is nested. If the device sends just the number, leave it empty. The last reading shows in the topic list.
- How do I make Odoo do something when a message arrives?
- On the topic, «Odoo action for each message»: create a server action on «MQTT message». In its code, record is the message: record.tema, record.valor and record.datos() (the JSON as a dictionary). If the action fails, the failure is noted on the message and the rest keep coming in.
- How do I send a command to a device?
- Menu «Misc › Devices (MQTT) › Commands» › «New»: name, the device's exact topic and message (text or JSON). Then press «Send». It is logged under «Messages» as sent.
- Where do I see the device messages?
- Menu «Misc › Devices (MQTT) › Messages»: what was received and sent, with filters (received, sent, with error, today) and a chart of the value. They are kept for the days set on the broker form (30 by default).