@@ -31,6 +31,7 @@ import mip
3131
3232mip.install(' github:thingsboard/thingsboard-micropython-client-sdk' )
3333```
34+ {: .copy-code}
3435
3536It is recommended to use the following code snippet to make sure that the SDK is installed and imported correctly,
3637and 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
8688result = client.connect(timeout = 20 )
8789```
90+ {: .copy-code}
8891
8992#### disconnect
9093
@@ -107,6 +110,7 @@ client.connect()
107110
108111client.disconnect()
109112```
113+ {: .copy-code}
110114
111115#### send_attributes
112116
@@ -130,6 +134,7 @@ attributes in key-value pairs.
130134attributes = {" sensorModel" : " DHT-22" , " attribute_2" : " value" }
131135client.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 }}]
162167client.send_telemetry(telemetry)
163168```
169+ {: .copy-code}
164170
165171#### request_attributes
166172
@@ -196,6 +202,7 @@ def on_attributes_change(result, exception=None):
196202
197203client.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
204211can activate their hardware without needing platform-level permissions.
205212
206213More 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
228235client.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
259267sub_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
288297sub_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
318328client.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
347358client.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
375387client.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
419432provision_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
449463provisioned_credentials = client.provision(" thingsboard.cloud" , 1883 , provision_request)
450464```
465+ {: .copy-code}
451466
452467### Concepts
453468
@@ -514,7 +529,7 @@ def safe_check_msg():
514529while 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()
549564while 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
578594client.set_server_side_rpc_request_handler(on_server_side_rpc_request)
579595```
596+ {: .copy-code}
580597
581598In 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.
607624while 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
614632By placing this inside the main loop, the device continuously streams its state. Because we use a non-blocking approach,
615633the 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}
0 commit comments