Skip to content

Commit 2e2bc9e

Browse files
authored
Merge pull request #62 from arduino/cred_strings
ucloud: Allow passing device id, username and password as strings.
2 parents 5f9ebfe + 6188a8e commit 2e2bc9e

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ Your `secrets.py` file should look like this:
3737
```python
3838
WIFI_SSID = "" # WiFi network SSID (for MicroPython)
3939
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.
40+
DEVICE_ID = "" # Provided by Arduino cloud when creating a device.
41+
SECRET_KEY = "" # Provided by Arduino cloud when creating a device.
4242
```
4343

4444
For more detailed examples and advanced API features, please see the [examples](https://github.com/arduino/arduino-iot-cloud-py/tree/main/examples).

src/arduino_iot_cloud/ucloud.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,19 @@ def __init__(
172172
self.thing_id = None
173173
self.keepalive = keepalive
174174
self.last_ping = timestamp()
175-
self.device_topic = b"/a/d/" + device_id + b"/e/i"
176175
self.senmlpack = SenmlPack("", self.senml_generic_callback)
177176
self.started = False
178177

178+
# Convert args to bytes if they are passed as strings.
179+
if isinstance(device_id, str):
180+
device_id = bytes(device_id, "utf-8")
181+
if username is not None and isinstance(username, str):
182+
username = bytes(username, "utf-8")
183+
if password is not None and isinstance(password, str):
184+
password = bytes(password, "utf-8")
185+
186+
self.device_topic = b"/a/d/" + device_id + b"/e/i"
187+
179188
# Update RTC from NTP server on MicroPython.
180189
self.update_systime(ntp_server, ntp_timeout)
181190

0 commit comments

Comments
 (0)