adafruit_gc_iot_core
¶
CircuitPython Google Cloud IoT Module
Author(s): Brent Rubell, Google Inc.
Implementation Notes¶
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Adafruit CircuitPython JWT Module: https://github.com/adafruit/Adafruit_CircuitPython_JWT
Adafruit CircuitPython Logging Module: https://github.com/adafruit/Adafruit_CircuitPython_Logging
- class adafruit_gc_iot_core.Cloud_Core(esp: ESP_SPIcontrol | None = None, secrets: Dict[str, Any] | None = None, log: bool = False)¶
CircuitPython Google Cloud IoT Core module.
- Parameters:
- generate_jwt(ttl: int = 43200, algo: str = 'RS256') str ¶
Generates a JSON Web Token (https://jwt.io/) using network time.
- Parameters:
Example usage of generating and setting a JSON-Web-Token:
jwt = CloudCore.generate_jwt() print("Generated JWT: ", jwt)
- class adafruit_gc_iot_core.MQTT_API(mqtt_client: MQTT)¶
Client for interacting with Google’s Cloud Core MQTT API.
- Parameters:
mqtt_client (MQTT) – MiniMQTT Client object
- loop() None ¶
Maintains a connection with Google Cloud IoT Core’s MQTT broker. You will need to manually call this method within a loop to retain connection.
Example of “pumping” a Google Core IoT loop.
while True: google_iot.loop()
- publish(payload: int | str, topic: str = 'events', subfolder: str | None = None, qos: int = 0) None ¶
Publishes a payload from the device to its Google Cloud IoT device topic, defaults to “events” topic. To send state, use the publish_state method.
- Parameters:
payload (float) – Data to publish to Google Cloud IoT
payload – Data to publish to Google Cloud IoT
payload – Data to publish to Google Cloud IoT
topic (str) – Required MQTT topic. Defaults to events.
subfolder (str) – Optional MQTT topic subfolder. Defaults to None.
qos (int) – Quality of Service level for the message.
- publish_state(payload: int | str) None ¶
Publishes a device state message to the Cloud IoT MQTT API. Data sent by this method should be information about the device itself (such as number of crashes, battery level, or device health). This method is unidirectional, it communicates Device-to-Cloud only.
- subscribe(topic: str, subfolder: str | None = None, qos: int = 1) None ¶
Subscribes to a Google Cloud IoT device topic.
- subscribe_to_all_commands(qos: int = 1) None ¶
Subscribes to a device’s “commands/#” topic.
- Parameters:
qos (int) – Quality of Service level for the message.
- subscribe_to_config(qos: int = 1) None ¶
Subscribes to a Google Cloud IoT device’s configuration topic.
- Parameters:
qos (int) – Quality of Service level for the message.
- subscribe_to_subfolder(topic: str, subfolder: str | None = None, qos: int = 1) None ¶
Subscribes to a Google Cloud IoT device’s topic subfolder
- exception adafruit_gc_iot_core.MQTT_API_ERROR¶
Exception raised on MQTT API return-code errors.