Skip to content

Commit abe6896

Browse files
committed
ucloud: Update module imports.
1 parent e949ac8 commit abe6896

File tree

4 files changed

+32
-19
lines changed

4 files changed

+32
-19
lines changed

README.md

+24-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,28 @@
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 authentication via username and password, or key/certificate pair stored on the filesystem or in a secure element.
3+
4+
## Minimal Example
5+
The following minimal example shows how to control an LED from the dashboard using a switch widget. It first creates a client object which is used to register the LED and Switch objects, and start the client.
6+
```python
7+
# Switch callback, toggles the LED
8+
def led_toggle(client, value):
9+
client["led"] = value
10+
11+
# 1. Create the client, using basic username and password authentication.
12+
client = AIOTClient(device_id=b"DEVICE_ID", username=b"DEVICE_ID", password=b"SECRET_KEY")
13+
14+
# 2. Register some cloud objects.
15+
client.register("led", value=None)
16+
client.register("sw1", value=None, on_write=led_toggle)
17+
18+
# 3. Start the Arduino cloud client.
19+
client.start()
20+
```
21+
22+
For more detailed examples and advanced API features, please see the [examples](https://github.com/arduino/arduino-iot-cloud-py/tree/main/examples).
323

424
## 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.
25+
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, if a crypto device is not available, the following steps can be used to emulate one using SoftHSM.
626

727
#### Create softhsm token
828
Using the first available slot, in this case 0
@@ -52,8 +72,7 @@ python examples/example.py
5272
```
5373

5474
## 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.
75+
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.
5776

5877
#### Convert key and certificate to `.DER`
5978
```bash
@@ -67,7 +86,6 @@ openssl x509 -in cert.pem -out cert.der -outform DER
6786

6887
## Useful links
6988

70-
* [ulogging](https://github.com/iabdalkader/micropython-ulogging)
7189
* [senml-micropython](https://github.com/kpn-iot/senml-micropython-library)
7290
* [m2crypto](https://github.com/m2crypto/m2crypto)
7391
* [umqtt.simple](https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.simple)

arduino_iot_cloud/ucloud.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@
55
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
66

77
import time
8+
import logging
89
from kpn_senml import SenmlPack
910
from kpn_senml import SenmlRecord
1011
from arduino_iot_cloud.umqtt import MQTTClient
1112

1213
try:
13-
import logging
1414
import asyncio
1515
from asyncio import CancelledError
1616
from asyncio import InvalidStateError
1717
except ImportError:
18-
import ulogging as logging
1918
import uasyncio as asyncio
2019
from uasyncio.core import CancelledError
2120

arduino_iot_cloud/umqtt.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,16 @@
2222
#
2323
# Based on: https://github.com/micropython/micropython-lib/tree/master/micropython/umqtt.simple
2424

25+
import socket
26+
import struct
27+
import select
28+
import logging
29+
2530
try:
2631
from ussl import wrap_socket
27-
import usocket as socket
28-
import ustruct as struct
29-
import ulogging as logging
30-
import uselect as select
3132
except ImportError:
32-
import socket
33-
import struct
34-
import logging
35-
import select
3633
from arduino_iot_cloud.ussl import wrap_socket
3734

38-
3935
class MQTTException(Exception):
4036
pass
4137

examples/micropython.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import time
55
import ussl
66
import network
7-
import ulogging as logging
8-
from ulogging.ustrftime import strftime
7+
import logging
8+
from time import strftime
99
from arduino_iot_cloud import AIOTClient
1010
from arduino_iot_cloud import Location
1111
from arduino_iot_cloud import Schedule

0 commit comments

Comments
 (0)