API
- class cassiamqtt.CassiaMQTTClient
Establishes a connection with the MQTT Broker to publish and subscribe to messages. Currently, up to two instances are supported.
- __init__(self, uri, username: str | None = None, password: str | None = None, client_id: str | None = None) CassiaMQTTClient
Returns itself after initializing parameters.
- Parameters:
uri: MQTT Broker URI
username: Username
password: Password
client_id: Client ID
- async __aenter__(self)
Establishes a connection and allocates resources.
- async __aexit__(self)
Disconnects and releases resources.
- async __aiter__() BLEScanResult
Returns itself, allowing the instance to be used directly in an async for loop.
- async __anext__() dict
Returns the subscribed message.
When the queue is empty, it will wait until new data arrives. The iteration terminates when the connection is disconnected.
Data Field Description Field
Type
Description
Example
topic
str
Topic
/dev/down/CC:1B:E0:E4:C8:94/api
qos
int
QoS
0
payload
str
Payload
{“id”:”1758…
- async publish(self, topic: str, payload: str, qos: int = 0, retain: bool = False) tuple[ok: bool, result: str]
Publishes a message to the specified topic.
- Parameters:
topic: Topic
payload: Payload
qos: QoS
retain: Indicates whether the message should be retained.
- Returns:
ok: Whether the execution was successful
result: Execution result
- async subscribe(self, topic: str, qos: int = 0) tuple[ok: bool, result: str]
Subscribes to messages from the specified topic.
- Parameters:
topic: Topic
qos: QoS
- Returns:
ok: Whether the execution was successful
result: Execution result
- async unsubscribe(self, topic: str) tuple[ok: bool, result: str]
Unsubscribes from messages of the specified topic.
- Parameters:
topic: Topic
- Returns:
ok: Whether the execution was successful
result: Execution result