Skip to content

examples: Update comments, user function. #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 5, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions examples/example.py
Original file line number Diff line number Diff line change
@@ -29,7 +29,8 @@ def on_clight_changed(client, clight):
logging.info(f"ColoredLight changed. Swi: {clight.swi} Bri: {clight.bri} Sat: {clight.sat} Hue: {clight.hue}")


def main(client):
def user_task(client):
# NOTE: this function should not block.
# This is a user-defined task that updates the colored light. Note any registered
# cloud object can be accessed using the client object passed to this function.
# The composite ColoredLight object fields can be assigned to individually, using dot:
@@ -58,7 +59,7 @@ def main(client):
# To use a secure element, set the token's "pin" and URI in "keyfile" and "certfile", and
# the CA certificate (if any) in "ssl_params". Alternatively, a username and password can
# be used to authenticate, for example:
# client = AIOTClient(device_id, username="username", password="password")
# client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY")
client = AIOTClient(
device_id=DEVICE_ID,
ssl_params={
@@ -97,7 +98,7 @@ def main(client):
# The client can also schedule user code in a task and run it along with the other cloud objects.
# To schedule a user function, use the Task object and pass the task name and function in "on_run"
# to client.register().
client.register(Task("main", on_run=main, interval=1.0))
client.register(Task("user_task", on_run=user_task, interval=1.0))

# Start the Arduino IoT cloud client.
client.start()
10 changes: 5 additions & 5 deletions examples/micropython.py
Original file line number Diff line number Diff line change
@@ -31,7 +31,8 @@ def on_clight_changed(client, clight):
logging.info(f"ColoredLight changed. Swi: {clight.swi} Bri: {clight.bri} Sat: {clight.sat} Hue: {clight.hue}")


def main(client):
def user_task(client):
# NOTE: this function should not block.
# This is a user-defined task that updates the colored light. Note any registered
# cloud object can be accessed using the client object passed to this function.
# The composite ColoredLight object fields can be assigned to individually, using dot:
@@ -65,9 +66,8 @@ def wifi_connect():
wifi_connect()

# Create a client object to connect to the Arduino IoT cloud.
# For MicroPython, the key and cert files must be stored in DER
# format on the filesystem. Alternatively, a username and password
# can be used to authenticate:
# For MicroPython, the key and cert files must be stored in DER format on the filesystem.
# Alternatively, a username and password can be used to authenticate:
# client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY")
client = AIOTClient(
device_id=DEVICE_ID,
@@ -106,7 +106,7 @@ def wifi_connect():
# The client can also schedule user code in a task and run it along with the other cloud objects.
# To schedule a user function, use the Task object and pass the task name and function in "on_run"
# to client.register().
client.register(Task("main", on_run=main, interval=1.0))
client.register(Task("user_task", on_run=user_task, interval=1.0))

# Start the Arduino IoT cloud client.
client.start()