adafruit_aws_iot

Amazon AWS IoT MQTT Client for CircuitPython

  • Author(s): Brent Rubell

Implementation Notes

Hardware:

Software and Dependencies:

exception adafruit_aws_iot.AWS_IOT_ERROR

Exception raised on MQTT API return-code errors.

class adafruit_aws_iot.MQTT_CLIENT(mmqttclient, keep_alive=30)

Client for interacting with Amazon AWS IoT MQTT API.

Parameters:
  • mmqttclient (MiniMQTT) – Pre-configured MiniMQTT Client object.
  • keep_alive (int) – Optional Keep-alive timer interval, in seconds. Provided interval must be 30 <= keep_alive <= 1200.
connect(clean_session=True)

Connects to Amazon AWS IoT MQTT Broker with Client ID. :param bool clean_session: Establishes a clean session with AWS broker.

disconnect()

Disconnects from Amazon AWS IoT MQTT Broker and de-initializes the MiniMQTT Client.

is_connected

Returns if MQTT_CLIENT is connected to AWS IoT MQTT Broker

loop()

Starts a synchronous message loop which maintains connection with AWS IoT. Must be called within the keep_alive timeout specified to init. This method does not handle network connection/disconnection.

Example of “pumping” an AWS IoT message loop: ..code-block::python

while True:
aws_iot.loop()
loop_forever()

Begins a blocking, asynchronous message loop. This method handles network connection/disconnection.

publish(topic, payload, qos=1)

Publishes to a AWS IoT Topic. :param str topic: MQTT topic to publish to. :param str payload: Data to publish to topic. :param int payload: Data to publish to topic. :param float payload: Data to publish to topic. :param json payload: JSON-formatted data to publish to topic. :param int qos: Quality of service level for publishing.

shadow_delete()

Publishes an empty message to the shadow delete topic to delete a device’s shadow

shadow_get()

Publishes an empty message to shadow get topic to get the device’s shadow.

shadow_get_subscribe(qos=1)

Subscribes to device’s shadow get response. :param int qos: Optional quality of service level.

shadow_subscribe(qos=1)

Subscribes to all notifications on the device’s shadow update topic. :param int qos: Optional quality of service level.

shadow_update(document)

Publishes a request state document to update the device’s shadow. :param json state_document: JSON-formatted state document.

subscribe(topic, qos=1)

Subscribes to an AWS IoT Topic. :param str topic: MQTT topic to subscribe to. :param int qos: Desired topic subscription’s quality-of-service.

static validate_topic(topic)

Validates if user-provided pub/sub topics adhere to AWS Service Limits. https://docs.aws.amazon.com/general/latest/gr/aws_service_limits.html :param str topic: Desired topic to validate