Skip to content

Commit 4e39122

Browse files
authored
Added documentation for CircuitPython SDK (#2586)
1 parent 4aadd99 commit 4e39122

9 files changed

Lines changed: 689 additions & 15 deletions

File tree

_data/api.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,6 @@ toc:
4242
- title: Python Client SDK
4343
path: /docs/reference/python-client-sdk/
4444
- title: MicroPython Client SDK
45-
path: /docs/reference/micropython-client-sdk/
45+
path: /docs/reference/micropython-client-sdk/
46+
- title: CircuitPython Client SDK
47+
path: /docs/reference/circuitpython-client-sdk/

_data/paas-eu/api.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ toc:
4343
- title: Python Client SDK
4444
path: /docs/reference/python-client-sdk
4545
- title: MicroPython Client SDK
46-
path: /docs/reference/micropython-client-sdk/
46+
path: /docs/reference/micropython-client-sdk/
47+
- title: CircuitPython Client SDK
48+
path: /docs/reference/circuitpython-client-sdk/

_data/paas/api.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,6 @@ toc:
4343
- title: Python Client SDK
4444
path: /docs/reference/python-client-sdk
4545
- title: MicroPython Client SDK
46-
path: /docs/reference/micropython-client-sdk/
46+
path: /docs/reference/micropython-client-sdk/
47+
- title: CircuitPython Client SDK
48+
path: /docs/reference/circuitpython-client-sdk/

_data/pe/api.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,6 @@ toc:
4343
path: /docs/pe/reference/python-client-sdk/
4444
- title: MicroPython Client SDK
4545
path: /docs/reference/micropython-client-sdk/
46+
- title: CircuitPython Client SDK
47+
path: /docs/reference/circuitpython-client-sdk/
48+

_includes/docs/api.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Server-side API is available as REST API:
3030
Software development kits:
3131

3232
* [**Python Client SDK**](/docs/{{docsPrefix}}reference/python-client-sdk) - Software development kit for client-side integration of your Python projects.
33-
* [**MicroPython Client SDK**](/docs/reference/micropython-client-sdk)
33+
* [**MicroPython Client SDK**](/docs/reference/micropython-client-sdk) - Software development kit for client-side integration of your MicroPython projects.
34+
* [**CircuitPython Client SDK**](/docs/reference/circuitpython-client-sdk) - Software development kit for client-side integration of your CircuitPython projects.
3435

3536
{% endif %}

_includes/docs/reference/circuitpython-client-sdk.md

Lines changed: 633 additions & 0 deletions
Large diffs are not rendered by default.

_includes/docs/reference/micropython-client-sdk.md

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import mip
3131

3232
mip.install('github:thingsboard/thingsboard-micropython-client-sdk')
3333
```
34+
{: .copy-code}
3435

3536
It is recommended to use the following code snippet to make sure that the SDK is installed and imported correctly,
3637
and also to not install the SDK every time you run your code:
@@ -45,6 +46,7 @@ except ImportError:
4546
mip.install('github:thingsboard/thingsboard-micropython-client-sdk')
4647
from thingsboard_sdk.tb_device_mqtt import TBDeviceMqttClient
4748
```
49+
{: .copy-code}
4850

4951
### Methods
5052

@@ -85,6 +87,7 @@ client.connect(timeout=20)
8587
# Connecting with waiting for connection result
8688
result = client.connect(timeout=20)
8789
```
90+
{: .copy-code}
8891

8992
#### disconnect
9093

@@ -107,6 +110,7 @@ client.connect()
107110

108111
client.disconnect()
109112
```
113+
{: .copy-code}
110114

111115
#### send_attributes
112116

@@ -130,6 +134,7 @@ attributes in key-value pairs.
130134
attributes = {"sensorModel": "DHT-22", "attribute_2": "value"}
131135
client.send_attributes(attributes)
132136
```
137+
{: .copy-code}
133138

134139
#### send_telemetry
135140

@@ -161,6 +166,7 @@ telemetry = [{"ts": 1451649600000, "values": {"temperature": 42.2, "humidity": 7
161166
{"ts": 1451649601000, "values": {"temperature": 42.3, "humidity": 72}}]
162167
client.send_telemetry(telemetry)
163168
```
169+
{: .copy-code}
164170

165171
#### request_attributes
166172

@@ -196,6 +202,7 @@ def on_attributes_change(result, exception=None):
196202

197203
client.request_attributes(client_keys=["atr1", "atr2"], callback=on_attributes_change)
198204
```
205+
{: .copy-code}
199206

200207
#### claim_device
201208

@@ -204,7 +211,7 @@ key, the device is automatically linked to the user’s account. This simplifies
204211
can activate their hardware without needing platform-level permissions.
205212

206213
More information about device claiming can be found in
207-
the [Device claiming](/docs/{{docsPrefix}}user-guide/device-claiming/) section of the documentation.
214+
the [Device claiming](/docs/user-guide/claiming-devices/) section of the documentation.
208215

209216
**Method Syntax**
210217

@@ -227,6 +234,7 @@ client.claim_device("my_claim_code")
227234
# Claiming a device with a claim code that will be valid for 60 seconds
228235
client.claim_device("my_claim_code", duration_ms=60000)
229236
```
237+
{: .copy-code}
230238

231239
#### subscribe_to_attribute
232240

@@ -258,6 +266,7 @@ def callback(result, *args):
258266

259267
sub_id = client.subscribe_to_attribute("frequency", callback)
260268
```
269+
{: .copy-code}
261270

262271
#### subscribe_to_all_attributes
263272

@@ -287,6 +296,7 @@ def callback(result, *args):
287296

288297
sub_id = client.subscribe_to_all_attributes(callback)
289298
```
299+
{: .copy-code}
290300

291301
#### unsubscribe_from_attribute
292302

@@ -317,6 +327,7 @@ sub_id = client.subscribe_to_attribute("frequency", callback)
317327
# Unsubscribing from attribute updates
318328
client.unsubscribe_from_attribute(sub_id)
319329
```
330+
{: .copy-code}
320331

321332
#### set_server_side_rpc_request_handler
322333

@@ -346,6 +357,7 @@ def handler(request_id, request_body):
346357

347358
client.set_server_side_rpc_request_handler(handler)
348359
```
360+
{: .copy-code}
349361

350362
#### send_rpc_reply
351363

@@ -374,6 +386,7 @@ def handler(request_id, request_body):
374386

375387
client.set_server_side_rpc_request_handler(handler)
376388
```
389+
{: .copy-code}
377390

378391
#### get_provision_request
379392

@@ -418,6 +431,7 @@ provision_request = TBDeviceMqttClient.get_provision_request("my_provision_key",
418431
# Forming provision request for a gateway device
419432
provision_request = TBDeviceMqttClient.get_provision_request("my_provision_key", "my_provision_secret", gateway=True)
420433
```
434+
{: .copy-code}
421435

422436
#### provision
423437

@@ -448,6 +462,7 @@ provision_request = TBDeviceMqttClient.get_provision_request("my_provision_key",
448462
# Sending provision request to ThingsBoard for device provisioning
449463
provisioned_credentials = client.provision("thingsboard.cloud", 1883, provision_request)
450464
```
465+
{: .copy-code}
451466

452467
### Concepts
453468

@@ -514,7 +529,7 @@ def safe_check_msg():
514529
while True:
515530
# Non-blocking: poll for incoming MQTT packets, then continue doing other work
516531
safe_check_msg()
517-
client.send_telemetry({"CPU", 12.0})
532+
client.send_telemetry({"CPU": 12.0})
518533
time.sleep_ms(50)
519534
```
520535
{:.copy-code.expandable-15}
@@ -549,8 +564,9 @@ client.connect()
549564
while True:
550565
# some tasks with ThingsBoard
551566
```
567+
{: .copy-code}
552568

553-
Before communicating with the cloud, the device must bridge the gap between the hardware and the network:
569+
Before communicating with the ThingsBoard, the device must bridge the gap between the hardware and the network:
554570

555571
- The network module initializes the Wi-Fi instance. We use STA_IF (Station Interface) to connect the device to an existing
556572
access point.
@@ -577,6 +593,7 @@ def on_server_side_rpc_request(request_id, request_body):
577593

578594
client.set_server_side_rpc_request_handler(on_server_side_rpc_request)
579595
```
596+
{: .copy-code}
580597

581598
In the SDK, we don't "wait" for a command, instead we provide a callback function (`on_server_side_rpc_request`):
582599

@@ -607,9 +624,10 @@ timestamp, which is useful for sending historical data to ThingsBoard.
607624
while True:
608625
# Non-blocking: poll for incoming MQTT packets, then continue doing other work
609626
safe_check_msg()
610-
client.send_telemetry({"CPU", 12.0})
627+
client.send_telemetry({"CPU": 12.0})
611628
time.sleep_ms(50)
612629
```
630+
{: .copy-code}
613631

614632
By placing this inside the main loop, the device continuously streams its state. Because we use a non-blocking approach,
615633
the device can simultaneously send telemetry and receive RPC commands without one interrupting the other.
@@ -625,12 +643,13 @@ GitHub.
625643

626644
- **Mip installation failed with OSError: -202**
627645

628-
This error can occur when the device is not connected to the internet or when there are issues with the network
629-
connection. To resolve this issue, make sure that your device is connected to the internet and that there are no
630-
issues with the network connection. You can also try restarting your device and running the installation command again.
631-
632-
Recommended firstly to establish a connection to the internet and then run the installation command:
633-
646+
This error can occur when the device is not connected to the internet or when there are issues with the network
647+
connection. To resolve this issue, make sure that your device is connected to the internet and that there are no
648+
issues with the network connection. You can also try restarting your device and running the installation command
649+
again.
650+
651+
Recommended firstly to establish a connection to the internet and then run the installation command:
652+
634653
```python
635654
import network
636655
import mip
@@ -648,3 +667,4 @@ GitHub.
648667

649668
mip.install('github:thingsboard/thingsboard-micropython-client-sdk')
650669
```
670+
{: .copy-code}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
layout: docwithnav
3+
assignees:
4+
- Andry925
5+
title: CircuitPython Client SDK
6+
description: Software development kit for client-side integration of your CircuitPython project
7+
8+
---
9+
10+
{% include get-hosts-name.html %}
11+
{% include docs/reference/circuitpython-client-sdk.md %}

docs/reference/micropython-client-sdk.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
layout: docwithnav
33
assignees:
4-
- zbeacon
4+
- samson0v
55
title: MicroPython Client SDK
66
description: Software development kit for client-side integration of your MicroPython project
77

0 commit comments

Comments
 (0)