campbellcontrol.connection package

Submodules

campbellcontrol.connection.aws module

Module for AWS specific MQTT broker connections

class campbellcontrol.connection.aws.AWSConnection(client_id: str, *args, **kwargs)

Bases: Connection

Connection class for the AWS MQTT client.

client_id: str

The client ID used for the MQTT connection (important for IoT Core authentication).

get_client_bootstrap() ClientBootstrap

“The ClientBootstrap will default to the static default (Io.ClientBootstrap.get_or_create_static_default)” https://awslabs.github.io/aws-crt-python/api/io.html#awscrt.io.ClientBootstrap This example is from the mqtt_test.py util in the aws-crt-python repo. TODO - understand how this works.

get_client(*args, **kwargs) Connection

Return the AWS MQTT client instance.

Parameters:
  • *args – Additional arguments forwarded to the client.

  • **kwargs – Additional keyword arguments forwarded to the client.

connect() None

Connect to the MQTT broker.

disconnect() None

Disconnect from the MQTT broker.

subscribe(topic: str, qos: QoS = QoS.EXACTLY_ONCE, callback: Callable | None = None) None

Subscribe to a topic.

Parameters:
  • topic – The topic to subscribe to.

  • qos – The Quality of Service level for the subscription.

  • callback – Optional method that is called during subscription.

publish(topic: str, payload: str | bytes | bytearray, qos: QoS, retain: bool = False) None

Publish a message to a given topic.

Parameters:
  • topic – The topic to publish to.

  • payload – The message payload.

  • qos – The Quality of Service level for the publication.

  • retain – Whether to retain the message on the broker and deliver it to future subscribers.

campbellcontrol.connection.generic module

Module for handling generic MQTT clients

class campbellcontrol.connection.generic.PahoConnection(endpoint: str, port: int, *args, **kwargs)

Bases: Connection

Connection class for the generic Paho MQTT client.

get_client(*args, **kwargs) Client

Return the Paho MQTT client instance.

campbellcontrol.connection.interface module

class campbellcontrol.connection.interface.Connection(endpoint: str, port: int, *args, **kwargs)

Bases: ABC

Base interface for defining MQTT broker connections.

endpoint: str

The endpoint of the MQTT broker.

port: int

The port of the MQTT broker.

client: Any

Handle to the MQTT client object.

abstractmethod get_client(*args, **kwargs) Any

Return the client instance.

connect() None

Connect to the MQTT broker.

disconnect() None

Disconnect from the MQTT broker.

publish(topic: str, payload: str, *args, **kwargs) None

Publish a message to a given topic.

Parameters:
  • topic – The topic to publish to.

  • payload – The message payload.

  • *args – Additional arguments forwarded to the client.

  • **kwargs – Additional keyword arguments forwarded to the client.

subscribe(topic: str) None

Subscribe to a topic.

Parameters:

topic – The topic to subscribe to.

unsubscribe(topic: str) None

Unsubscribe from a topic.

Parameters:

topic – The topic to unsubscribe from.

Module contents