diff --git a/examples/example.py b/examples/example.py index 7ff194a..c9e1bd1 100644 --- a/examples/example.py +++ b/examples/example.py @@ -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() diff --git a/examples/micropython.py b/examples/micropython.py index 6459eb0..ceee53e 100644 --- a/examples/micropython.py +++ b/examples/micropython.py @@ -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()