Skip to main content

roboflex.transport.mqtt

Rooboflex support for the MQTT transport.

See https://mqtt.org/ for details.

Using MQTT, nodes can connect to other nodes, even running on different computers. You must run your own MQTT broker - broker functionality is not wrapped in any way.

any node -> MQTTPublisher ==MQTT BROKER==> MQTTSubscriber -> any node

Contents

System Dependencies

apt-get install mosquitto
apt-get install libmosquitto-dev

... or on mac ...
brew install mosquitto

Build

mkdir build && cd build
cmake ..
make

Run Examples (see examples)

pub_sub_0_cpp
python pub_sub_0_py

Import

import roboflex.transport.mqtt as rtm

Classes

Roboflex's support for MQTT is embodied in four classes:

  1. MQTTContext, which you just have to instantiate somewhere
  2. MQTTNodeBase, a base class which you don't use
  3. MQTTPublisher, which can publish to an mqtt topic somewhere
  4. MQTTSubscriber, which can subscribe to an mqtt topic somewhere

MQTTContext

In order to use the other MQTT classes, you must instantiate an MQTTContext, and its lifetime must be >= the lifetime of all other MQTT node classes. You must pass an instance of this class to the constructors of both MQTTPublisher and MQTTSubscriber.

# instantiate like so:
mqtt_context = rtm.MQTTContext()

MQTTNodeBase

Do not instantiate directly. This is the base class for MQTTPublisher and MQTTSubscriber, and holds common functionality and properties.

# the address of the broker
mqtt_node.broker_address -> str

# the port number of the broker
mqtt_node.broker_port -> int

# the number of seconds between keepalive messages
mqtt_node.keepalive_seconds -> int

# the topic to publish or subscribe to
mqtt_node.topic_name -> str

# the mqtt quality-of-service
mqtt_node.qos -> int

# whether to print out debug messages
mqtt_node.debug -> bool

MQTTPublisher

(inherits MQTTNodeBase)

Publishes any messages it receives to some topic, on some broker. When it receives an message, it publishes the binary representation on the given topic, and then propagages the message verbatim.

mqtt_publisher = rtm.MQTTPublisher(
    mqtt_context: rtm.MQTTContext,
    broker_address: str,
    broker_port: int,
    keepalive_seconds: int,
    topic_name: str,

    # optional...
    name: str = "MQTTPublisher",
    qos: int = 0,
    retained: bool = false,
    debug: bool = false,
)

# additional properties:

# See the MQTT documentation for what the retained feature does:
# https://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages/
mqtt_publisher.retained -> bool

# If you have some message 'in hand' in some other function,
# you can just use an MQTTPublisher to publish the message
# directly. This is just an alias for 'signal_self' on core::Node.
mqtt_publisher.publish({"key1": 32})

MQTTSubscriber

(inherits MQTTNodeBase)

Suscribes to some topic from some broker. Expects only Roboflex encoded messages.

mqtt_subscriber = rtm.MQTTSubscriber(
    mqtt_context: rtm.MQTTContext,
    broker_address: str,
    broker_port: int,
    keepalive_seconds: int,
    topic_name: str,

    # optional...
    name: str = "MQTTSubscriber",
    qos: int = 0,
    loop_timeout_milliseconds: int = 100,
    debug: bool = false,
)

# additional properties:

# number of milliseconds, max, to wait in the mqtt message loop,
# before checking whether to continue or not.
mqtt_subscriber.loop_timeout_milliseconds -> int

Metadata

Release files for roboflex.transport.mqtt 0.1.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for roboflex.transport.mqtt 0.1.9
File Size Uploaded
roboflex_transport_mqtt-0.1.9.tar.gz 14.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for roboflex.transport.mqtt 0.1.9
File Interpreter ABI Platform
roboflex_transport_mqtt-0.1.9-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details

Total release size: 229.9 kB

Release files / roboflex_transport_mqtt-0.1.9.tar.gz

Download URL roboflex_transport_mqtt-0.1.9.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
ee28b6ffcc428135010c2c1b9a50daf5219397d9a735fca88f5cbf5da42d5282
BLAKE2b-256 checksum
How to use checksums
3f6fc5f1ff3ab75717fc259b404fd7208b17282f35934e8cda0d0eee4fadb7a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release files / roboflex_transport_mqtt-0.1.9-cp311-cp311-macosx_15_0_arm64.whl

Download URL roboflex_transport_mqtt-0.1.9-cp311-cp311-macosx_15_0_arm64.whl
Size 215.8 kB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
b590975c893dd8e351c7c35c1e143764f2fb9203859002b95f497829dc11936c
BLAKE2b-256 checksum
How to use checksums
e58db56f4215ed49a5b34d08d2b42f14b080848dc18b18178b2266060fa38b01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.5

Release history Release notifications | RSS feed

This release

0.1.9 This release

2 release files

0.1.8

2 release files

0.1.7

1 release file

0.1.6

1 release file

0.1.5

1 release file

0.1.4

1 release file

0.1.3

1 release file

0.1.2

1 release file

0.1.1

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page