|
1 |
| -# Arduino IoT Cloud Micro/Python client ☁️🐍☁️ |
2 |
| -Arduino IoT cloud client for Python and MicroPython. |
| 1 | +# Arduino IoT Cloud Python client ☁️🐍☁️ |
| 2 | +This is a Python client for the Arduino IoT cloud, which runs on both CPython and MicroPython. The client supports basic and advanced authentication methods, and provides a user-friendly API that allows the user to connect to the cloud, and create and link local objects to cloud objects with a just a few lines of code. |
| 3 | + |
| 4 | +## Minimal Example |
| 5 | +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. |
| 6 | +```python |
| 7 | +# Switch callback, toggles the LED. |
| 8 | +def on_switch_changed(client, value): |
| 9 | + # Note the client object passed to this function can be used to access |
| 10 | + # and modify any registered cloud object. The following line updates |
| 11 | + # the LED value. |
| 12 | + client["led"] = value |
| 13 | + |
| 14 | +# 1. Create a client object, which is used to connect to the IoT cloud and link local |
| 15 | +# objects to cloud objects. Note a username and password can be used for basic authentication |
| 16 | +# on both CPython and MicroPython. For more advanced authentication methods, please see the examples. |
| 17 | +client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY") |
| 18 | + |
| 19 | +# 2. Register cloud objects. |
| 20 | +# Note: The following objects must be created first in the dashboard and linked to the device. |
| 21 | +# When the switch is toggled from the dashboard, the on_switch_changed function is called with |
| 22 | +# the client object and new value args. |
| 23 | +client.register("sw1", value=None, on_write=on_switch_changed) |
| 24 | + |
| 25 | +# The LED object is updated in the switch's on_write callback. |
| 26 | +client.register("led", value=None) |
| 27 | + |
| 28 | +# 3. Start the Arduino cloud client. |
| 29 | +client.start() |
| 30 | +``` |
| 31 | + |
| 32 | +For more detailed examples and advanced API features, please see the [examples](https://github.com/arduino/arduino-iot-cloud-py/tree/main/examples). |
3 | 33 |
|
4 | 34 | ## Testing on CPython/Linux
|
5 |
| -If a crypto device is available, the following steps can be skipped, otherwise Arduino IoT cloud can be tested on Linux using SoftHSM. |
| 35 | +The client supports basic authentication using a username and password, and the more advanced key/cert pair stored on filesystem or in a crypto device. To test this functionality, the following steps can be used to emulate a crypto device (if one is not available) using SoftHSM on Linux. |
6 | 36 |
|
7 | 37 | #### Create softhsm token
|
8 | 38 | Using the first available slot, in this case 0
|
@@ -52,8 +82,7 @@ python examples/example.py
|
52 | 82 | ```
|
53 | 83 |
|
54 | 84 | ## Testing on MicroPython
|
55 |
| -MicroPython currently does Not support secure elements, the key and cert files must be stored in DER format on the filesystem. |
56 |
| -Convert the key and certificate to DER, using the following commands, and copy to the filesystem storage. |
| 85 | +MicroPython currently does Not support secure elements. The username and password can be used, or the key and cert files must be stored in DER format on the filesystem. To test the client on MicroPython, first convert the key and certificate to DER, using the following commands, then copy the files to the internal storage. |
57 | 86 |
|
58 | 87 | #### Convert key and certificate to `.DER`
|
59 | 88 | ```bash
|
|
0 commit comments