MQTT mixin for spade, enabling agents to pub/sub to MQTT topics.
Project description
spade_mqtt
The goal of this project is to implement a way to enable spade agents to interact (connect, subscribe, publish, ...) on MQTT.
Installation
pip install spade_mqtt
Getting started
Agent should use it by adding the MqttMixin in the class declaration. This mixin add the mqtt attribute in the agent class. This object wraps mqtt calls and manage asyncio.
class MyAgent(MqttMixin, spade.agent.Agent):
async def setup(self):
try:
await self.mqtt.connect("localhost", 30)
except TimeoutError:
print("Warning: could not connect to MQTT brocker localhost")
#...
Such agent can then have behaviour that can subscribe on topics, and await messages on them.
class MQTTSubBehaviour(spade.behaviour.CyclicBehaviour):
"""Behaviour that subscribes to a topic and store the messages received."""
def __init__(self, topic):
spade.behaviour.CyclicBehaviour.__init__(self)
self.topic = topic
async def run(self):
print(f"awaiting message on topic {self.topic}")
msg = await self.agent.mqtt.receive(self.topic)
if msg:
print(f"got message with payload {msg.payload}")
# process the message...
async def on_start(self):
await self.agent.mqtt.subscribe(self.topic)
async def on_end(self):
await self.agent.mqtt.unsubscribe(self.topic)
MQTT publish is done likewise.
class MQTTPubBehaviour(spade.behaviour.OneShotBehaviour):
"""Publish hello world to example/topic"""
async def run(self):
await self.agent.mqtt.publish(
"example/topic", "hello world", retain=True
)
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 spade_mqtt-0.6.0.tar.gz.
File metadata
- Download URL: spade_mqtt-0.6.0.tar.gz
- Upload date:
- Size: 24.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e40e1bed4a8f9dc03e7cdf861b51bb01106badce5281fc71699860f9eb4b7c09
|
|
| MD5 |
0042287be4a9cb8ef808b275be6f4b3e
|
|
| BLAKE2b-256 |
86a25ea83d12e87a9edbf4d9adbd16365cc8c0b0d7eb67864e8e83fa2e988c2b
|
Provenance
The following attestation bundles were made for spade_mqtt-0.6.0.tar.gz:
Publisher:
python-publish.yml on remipannequin/spade_mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spade_mqtt-0.6.0.tar.gz -
Subject digest:
e40e1bed4a8f9dc03e7cdf861b51bb01106badce5281fc71699860f9eb4b7c09 - Sigstore transparency entry: 1122715130
- Sigstore integration time:
-
Permalink:
remipannequin/spade_mqtt@5e2346ad1af21cf11bde86516fad2f8730489216 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/remipannequin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e2346ad1af21cf11bde86516fad2f8730489216 -
Trigger Event:
release
-
Statement type:
File details
Details for the file spade_mqtt-0.6.0-py2.py3-none-any.whl.
File metadata
- Download URL: spade_mqtt-0.6.0-py2.py3-none-any.whl
- Upload date:
- Size: 18.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9de3e3de9b0880026fcfe3315ee04206a56182f980cb10a9c4d04d8b28f0391
|
|
| MD5 |
3afcf7ccd6ae6e12f901625ff3b78bf3
|
|
| BLAKE2b-256 |
0da19b028b0f5c1397070cebe10d49b97f5f94d07eb229bd3e4fd7e034856495
|
Provenance
The following attestation bundles were made for spade_mqtt-0.6.0-py2.py3-none-any.whl:
Publisher:
python-publish.yml on remipannequin/spade_mqtt
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
spade_mqtt-0.6.0-py2.py3-none-any.whl -
Subject digest:
f9de3e3de9b0880026fcfe3315ee04206a56182f980cb10a9c4d04d8b28f0391 - Sigstore transparency entry: 1122715150
- Sigstore integration time:
-
Permalink:
remipannequin/spade_mqtt@5e2346ad1af21cf11bde86516fad2f8730489216 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/remipannequin
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@5e2346ad1af21cf11bde86516fad2f8730489216 -
Trigger Event:
release
-
Statement type: