Roboflex Transport mqtt Library
Project description
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:
- MQTTContext, which you just have to instantiate somewhere
- MQTTNodeBase, a base class which you don't use
- MQTTPublisher, which can publish to an mqtt topic somewhere
- 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file roboflex_transport_mqtt-0.1.8.tar.gz.
File metadata
- Download URL: roboflex_transport_mqtt-0.1.8.tar.gz
- Upload date:
- Size: 14.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cc30d7f4a6582f0f46be9d729870d528b05e01ae4aebb2993f839c5df57c2bd2
|
|
| MD5 |
122883a530e91586687061b1117c4421
|
|
| BLAKE2b-256 |
18d0e90e5abc8386abab9c9721e3b53ef8d3f5bda3d421d4880c529b8197b6c5
|
File details
Details for the file roboflex_transport_mqtt-0.1.8-cp311-cp311-macosx_15_0_arm64.whl.
File metadata
- Download URL: roboflex_transport_mqtt-0.1.8-cp311-cp311-macosx_15_0_arm64.whl
- Upload date:
- Size: 207.6 kB
- Tags: CPython 3.11, macOS 15.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a08e476b6838f98ea9a17382a28a49c196085fd41dafd0d7eb93a07d7c98a8d
|
|
| MD5 |
af52a61970a67c59a48ee19c715e3106
|
|
| BLAKE2b-256 |
2baf4ae9e86debef3fc96d335e74c7100fd5219859751dd71814c9f1ffcc6077
|