Skip to content

Commit

Permalink
Merge pull request #62 from arduino/cred_strings
Browse files Browse the repository at this point in the history
ucloud: Allow passing device id, username and password as strings.
  • Loading branch information
iabdalkader authored Jul 18, 2023
2 parents 5f9ebfe + 6188a8e commit 2e2bc9e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ Your `secrets.py` file should look like this:
```python
WIFI_SSID = "" # WiFi network SSID (for MicroPython)
WIFI_PASS = "" # WiFi network key (for MicroPython)
DEVICE_ID = b"" # Provided by Arduino cloud when creating a device.
SECRET_KEY = b"" # Provided by Arduino cloud when creating a device.
DEVICE_ID = "" # Provided by Arduino cloud when creating a device.
SECRET_KEY = "" # Provided by Arduino cloud when creating a device.
```

For more detailed examples and advanced API features, please see the [examples](https://github.com/arduino/arduino-iot-cloud-py/tree/main/examples).
Expand Down
11 changes: 10 additions & 1 deletion src/arduino_iot_cloud/ucloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,19 @@ def __init__(
self.thing_id = None
self.keepalive = keepalive
self.last_ping = timestamp()
self.device_topic = b"/a/d/" + device_id + b"/e/i"
self.senmlpack = SenmlPack("", self.senml_generic_callback)
self.started = False

# Convert args to bytes if they are passed as strings.
if isinstance(device_id, str):
device_id = bytes(device_id, "utf-8")
if username is not None and isinstance(username, str):
username = bytes(username, "utf-8")
if password is not None and isinstance(password, str):
password = bytes(password, "utf-8")

self.device_topic = b"/a/d/" + device_id + b"/e/i"

# Update RTC from NTP server on MicroPython.
self.update_systime(ntp_server, ntp_timeout)

Expand Down

0 comments on commit 2e2bc9e

Please sign in to comment.