seguro.common.broker.Client¶
- class seguro.common.broker.Client(uid=None, host='localhost', port=8883, tls_cert='keys/clients/admin.crt', tls_key='keys/clients/admin.key', tls_cacert='keys/ca.crt', keepalive=60)[source]¶
Bases:
objectHelper class for MQTT interaction with the SEGuRo platform.
This class provides an abstraction layer for MQTT based communication between the SEGuRo platform and the MQTT broker.
Creates a paho.mqtt.client object and initialize the message queue.
- Parameters:
uid – An identifier of the client
host (str) – The MQTT hostname or IP address. Defaults to localhost.
port (int) – The port number used for connecting to the MQTT broker. Defaults to 8883.
tls_cert (str) – File containing the TLS client certificate for mutual TLS authentication.
tls_key (str) – File containing the TLS client key for mutual TLS authentication.
tls_cacert (str) – File containing the TLS certificate authority to validate the servers certificate against.
keepalive – The keepalive interval in seconds.
- __init__(uid=None, host='localhost', port=8883, tls_cert='keys/clients/admin.crt', tls_key='keys/clients/admin.key', tls_cacert='keys/ca.crt', keepalive=60)[source]¶
- Parameters:
host (str)
port (int)
tls_cert (str)
tls_key (str)
tls_cacert (str)
Methods
__init__([uid, host, port, tls_cert, ...])publish(topic, message)Publish message to given topic
publish_samples(topic, samples)Publish sample to given topic.
Start async listening on subscribed topics.
Stop async listening on subscribed topics.
subscribe(topic, cb)Subscribe client to given topic and registering callback (optional).
subscribe_samples(topic, cb)Subscribe client to given topic and registering callback (optional).
- publish(topic, message)[source]¶
Publish message to given topic
- Parameters:
topic (str)
message (str | bytes | bytearray | int | float | None)
- Returns:
The MQTT message information
- Return type:
MQTTMessageInfo
- publish_samples(topic, samples)[source]¶
Publish sample to given topic.
- Parameters:
topic
samples (Iterable[Sample])
- Returns:
The MQTT message information
- Return type:
MQTTMessageInfo