Skip to content

Commit cbfb519

Browse files
committed
examples: Update examples.
* Update examples to import device ID and secret key from secrets.py.
1 parent 02aec9e commit cbfb519

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ This is a Python client for the Arduino IoT cloud, which runs on both CPython an
44
## Minimal Example
55
The following basic example shows how to connect to the Arduino IoT cloud using basic username and password authentication, and control an LED from a dashboard's switch widget.
66
```python
7+
from secrets import DEVICE_ID
8+
from secrets import SECRET_KEY
9+
710
# Switch callback, toggles the LED.
811
def on_switch_changed(client, value):
912
# Note the client object passed to this function can be used to access
@@ -14,7 +17,7 @@ def on_switch_changed(client, value):
1417
# 1. Create a client object, which is used to connect to the IoT cloud and link local
1518
# objects to cloud objects. Note a username and password can be used for basic authentication
1619
# on both CPython and MicroPython. For more advanced authentication methods, please see the examples.
17-
client = ArduinoCloudClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY")
20+
client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
1821

1922
# 2. Register cloud objects.
2023
# Note: The following objects must be created first in the dashboard and linked to the device.
@@ -29,6 +32,15 @@ client.register("led", value=None)
2932
client.start()
3033
```
3134

35+
Your `secrets.py` file should look like this:
36+
37+
```python
38+
WIFI_SSID = "" # WiFi network SSID (for MicroPython)
39+
WIFI_PASS = "" # WiFi network key (for MicroPython)
40+
DEVICE_ID = b"" # Provided by Arduino cloud when creating a device.
41+
SECRET_KEY = b"" # Provided by Arduino cloud when creating a device.
42+
```
43+
3244
For more detailed examples and advanced API features, please see the [examples](https://github.com/arduino/arduino-iot-cloud-py/tree/main/examples).
3345

3446
## Testing on CPython/Linux

examples/example.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
import argparse
1414
import arduino_iot_cloud.ussl as ssl
1515

16+
from secrets import DEVICE_ID
17+
from secrets import SECRET_KEY
18+
1619
KEY_PATH = "pkcs11:token=arduino"
1720
CERT_PATH = "pkcs11:token=arduino"
1821
CA_PATH = "ca-root.pem"
19-
DEVICE_ID = b"fcbb21b8-b5b8-4961-a89f-a3f1abda7957"
2022

2123

2224
def on_switch_changed(client, value):
@@ -59,7 +61,7 @@ def user_task(client):
5961
# To use a secure element, set the token's "pin" and URI in "keyfile" and "certfile", and
6062
# the CA certificate (if any) in "ssl_params". Alternatively, a username and password can
6163
# be used to authenticate, for example:
62-
# client = ArduinoCloudClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY")
64+
# client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
6365
client = ArduinoCloudClient(
6466
device_id=DEVICE_ID,
6567
ssl_params={

examples/micropython.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@
1515
from random import uniform
1616
from secrets import WIFI_SSID
1717
from secrets import WIFI_PASS
18+
from secrets import DEVICE_ID
19+
from secrets import SECRET_KEY
1820

1921
KEY_PATH = "key.der"
2022
CERT_PATH = "cert.der"
21-
DEVICE_ID = b"fcbb21b8-b5b8-4961-a89f-a3f1abda7957"
2223

2324

2425
def on_switch_changed(client, value):
@@ -68,7 +69,7 @@ def wifi_connect():
6869
# Create a client object to connect to the Arduino IoT cloud.
6970
# For MicroPython, the key and cert files must be stored in DER format on the filesystem.
7071
# Alternatively, a username and password can be used to authenticate:
71-
# client = ArduinoCloudClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY")
72+
# client = ArduinoCloudClient(device_id=DEVICE_ID, username=DEVICE_ID, password=SECRET_KEY)
7273
client = ArduinoCloudClient(
7374
device_id=DEVICE_ID,
7475
ssl_params={

0 commit comments

Comments
 (0)