Library: mqtt

From Yombo
Jump to: navigation, search
mqtt
Commonly Used Yes
Status Active

Summary
MQTT (Message Queuing Telemetry Transport) is a lightweight IoT communication protocol used to communicate with low power automation devices.

Introduction

This library provides quick setup of a MQTT connection to MQTT brokers.

By default, Yombo starts up an MQTT broker that other devices can connect to. The user can also configure the gateway to use another MQTT broker, however, modules do not need to worry about that. Simply using self.mqtt_connection = self._MQTT.new(mqtt_incoming_callback=self.mqtt_incoming, client_id='myModuleName') within your module will connect the the system defined MQTT broker.

Implementation Overview

The Gateway starts an MQTT broker (aka server) that allows clients to subscribe to topics or send messages (commands, status updates, etc). A topic is something the client is interested in, for example, it might want to know when states change, when devices have status changes, etc. By default, the MQTT broker started by the Gateway only allows local connections and requires a username/password. See below for details on adding more users. The MQTT library also acts like a client. It allows other modules to connect to any MQTT client (including the broker it started) to send commands or receive topic messages. For example, the device's library will connect to the MQTT broker to listen for requests to change device status (such as turning on/off lights). The States and Atoms libraries will connect to the broker to publish any changes and receive requests to make changes.

See also

Hooks

No hooks registered.

Usage

Defined MQTT Topics

Yombo uses the following topics. Developers are free to use any topic desired, however, see suggestions below.

  • yombo - The primary yombo topic. Most other yombo items will stem from this.
    • devices - The devices library can accept command requests, status requests here. It also uses this topic branch for broadcasting updates. See below for details.
    • states - State changes will be broadcast as

Connecting, broadcasting, and listening

Modules wishing to connect the the MQTT broker, and simply use the MQTT library as such: self.mqtt_connection = self._MQTT.new(mqtt_incoming_callback=self.mqtt_incoming, client_id='myModuleName')


This page was last edited on 19 August 2018.