Skip to content

Commit e949ac8

Browse files
authoredJan 5, 2023
Merge pull request #44 from arduino/update_examples
examples: Update comments, user function.
2 parents 42a62bd + 6b44379 commit e949ac8

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed
 

‎examples/example.py

+4-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ def on_clight_changed(client, clight):
2929
logging.info(f"ColoredLight changed. Swi: {clight.swi} Bri: {clight.bri} Sat: {clight.sat} Hue: {clight.hue}")
3030

3131

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

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

‎examples/micropython.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def on_clight_changed(client, clight):
3131
logging.info(f"ColoredLight changed. Swi: {clight.swi} Bri: {clight.bri} Sat: {clight.sat} Hue: {clight.hue}")
3232

3333

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

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

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

0 commit comments

Comments
 (0)
Please sign in to comment.