From c38cf3207880f0aa5be31d5f00c43acb6645efef Mon Sep 17 00:00:00 2001 From: Andry925 Date: Fri, 13 Feb 2026 14:58:51 +0200 Subject: [PATCH 1/3] update README.rst --- README.rst | 54 ++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/README.rst b/README.rst index 034d70b..47361fe 100644 --- a/README.rst +++ b/README.rst @@ -50,20 +50,20 @@ To install for current user: .. code-block:: shell - pip3 install circuitpython-thingsboard-client-sdk + pip3 install thingsboard-circuitpython-client-sdk To install system-wide (this may be required in some cases): .. code-block:: shell - sudo pip3 install circuitpython-thingsboard-client-sdk + sudo pip3 install thingsboard-circuitpython-client-sdk To install in a virtual environment in your current project: .. code-block:: shell mkdir project-name && cd project-name - python3 -m venv .venv + python3 -m venv .env source .env/bin/activate pip3 install thingsboard-circuitpython-client-sdk @@ -97,15 +97,45 @@ Client initialization and telemetry publishing .. code-block:: python - from tb_device_mqtt import TBDeviceMqttClient - telemetry = {"temperature": 41.9, "enabled": False, "currentFirmwareVersion": "v1.2.2"} - client = TBDeviceMqttClient(host="127.0.0.1", port=1883, access_token="A1_TEST_TOKEN") - # Connect to ThingsBoard - client.connect() - # Sending telemetry without checking the delivery status - client.send_telemetry(telemetry) - # Disconnect from ThingsBoard - client.disconnect() +import time + +from tb_device_mqtt import TBDeviceMqttClient # ThingsBoard MQTT client wrapper (your SDK) +import wifi # CircuitPython Wi-Fi module + +# Quick sanity-check that Wi-Fi is up before using MQTT +print("WiFi connected:", wifi.radio.connected) +print("IP:", wifi.radio.ipv4_address) + +# ThingsBoard connection settings +HOST = "YOUR_HOST" # e.g. "thingsboard.cloud" or "192.168.1.10" +PORT = "YOUR_PORT" # e.g. 1883 (use an int if your client expects it) +TOKEN = "YOUR_ACCESS_TOKEN" # device access token from ThingsBoard + +# Telemetry payload to send (will appear in the device telemetry in ThingsBoard) +telemetry = {"temperature": 41.9, "enabled": False, "currentFirmwareVersion": "v1.2.2"} + +# Create MQTT client instance +client = TBDeviceMqttClient(host=HOST, port=PORT, access_token=TOKEN) + +try: + print("Connecting...") + client.connect() # open MQTT connection to ThingsBoard + time.sleep(1) # small delay to ensure connection stabilizes on some boards + + print("Sending telemetry...") + client.send_telemetry(telemetry) # publish telemetry message + time.sleep(1) # allow time for message to be sent before disconnecting + +finally: + print("Disconnecting...") + try: + client.disconnect() # close MQTT connection cleanly + except Exception as e: + # Prevent cleanup from crashing the script on disconnect issues + print("Disconnect error:", e) + + + Contributing ============ From f48bf9173d0ce5b05d743f9dd5cd9ed0b023303f Mon Sep 17 00:00:00 2001 From: Andry925 Date: Fri, 13 Feb 2026 14:59:15 +0200 Subject: [PATCH 2/3] add example for telemetry sending --- examples/send_telemetry.py | 42 +++++++++++++++++++ examples/thingsboard-client-sdk_simpletest.py | 4 -- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 examples/send_telemetry.py delete mode 100644 examples/thingsboard-client-sdk_simpletest.py diff --git a/examples/send_telemetry.py b/examples/send_telemetry.py new file mode 100644 index 0000000..7805392 --- /dev/null +++ b/examples/send_telemetry.py @@ -0,0 +1,42 @@ +# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries +# SPDX-FileCopyrightText: Copyright (c) 2026 ThingsBoard Inc. +# +# SPDX-License-Identifier: Unlicense + +import time + +import wifi # CircuitPython Wi-Fi module + +from tb_device_mqtt import TBDeviceMqttClient # ThingsBoard MQTT client wrapper (your SDK) + +# Quick sanity-check that Wi-Fi is up before using MQTT +print("WiFi connected:", wifi.radio.connected) +print("IP:", wifi.radio.ipv4_address) + +# ThingsBoard connection settings +HOST = "YOUR_HOST" # e.g. "thingsboard.cloud" or "192.168.1.10" +PORT = "YOUR_PORT" # e.g. 1883 (use an int) +TOKEN = "YOUR_ACCESS_TOKEN" # device access token from ThingsBoard + +# Telemetry payload to send (will appear in the device telemetry in ThingsBoard) +telemetry = {"temperature": 41.9, "enabled": False, "currentFirmwareVersion": "v1.2.2"} + +# Create MQTT client instance +client = TBDeviceMqttClient(host=HOST, port=PORT, access_token=TOKEN) + +try: + print("Connecting...") + client.connect() # open MQTT connection to ThingsBoard + time.sleep(1) # small delay to ensure connection stabilizes on some boards + + print("Sending telemetry...") + client.send_telemetry(telemetry) # publish telemetry message + time.sleep(1) # allow time for message to be sent before disconnecting + +finally: + print("Disconnecting...") + try: + client.disconnect() # close MQTT connection cleanly + except Exception as e: + # Prevent cleanup from crashing the script on disconnect issues + print("Disconnect error:", e) diff --git a/examples/thingsboard-client-sdk_simpletest.py b/examples/thingsboard-client-sdk_simpletest.py deleted file mode 100644 index bcab459..0000000 --- a/examples/thingsboard-client-sdk_simpletest.py +++ /dev/null @@ -1,4 +0,0 @@ -# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries -# SPDX-FileCopyrightText: Copyright (c) 2026 Vitalii Bidochka for ThingsBoard Inc. -# -# SPDX-License-Identifier: Unlicense From 07358aaa48a6466150766164c7f2b5e1f1a74d29 Mon Sep 17 00:00:00 2001 From: Andry925 Date: Fri, 13 Feb 2026 15:06:13 +0200 Subject: [PATCH 3/3] fix code example formatting --- README.rst | 59 +++++++++++++++++++++++++++--------------------------- 1 file changed, 30 insertions(+), 29 deletions(-) diff --git a/README.rst b/README.rst index 47361fe..21f141b 100644 --- a/README.rst +++ b/README.rst @@ -97,42 +97,43 @@ Client initialization and telemetry publishing .. code-block:: python -import time + import time -from tb_device_mqtt import TBDeviceMqttClient # ThingsBoard MQTT client wrapper (your SDK) -import wifi # CircuitPython Wi-Fi module + import wifi # CircuitPython Wi-Fi module + from tb_device_mqtt import TBDeviceMqttClient # ThingsBoard MQTT client wrapper (your SDK) -# Quick sanity-check that Wi-Fi is up before using MQTT -print("WiFi connected:", wifi.radio.connected) -print("IP:", wifi.radio.ipv4_address) + # Quick sanity-check that Wi-Fi is up before using MQTT + print("WiFi connected:", wifi.radio.connected) + print("IP:", wifi.radio.ipv4_address) -# ThingsBoard connection settings -HOST = "YOUR_HOST" # e.g. "thingsboard.cloud" or "192.168.1.10" -PORT = "YOUR_PORT" # e.g. 1883 (use an int if your client expects it) -TOKEN = "YOUR_ACCESS_TOKEN" # device access token from ThingsBoard + # ThingsBoard connection settings + HOST = "YOUR_HOST" # e.g. "thingsboard.cloud" or "192.168.1.10" + PORT = "YOUR_PORT" # e.g. 1883 (use an int if your client expects it) + TOKEN = "YOUR_ACCESS_TOKEN" # device access token from ThingsBoard -# Telemetry payload to send (will appear in the device telemetry in ThingsBoard) -telemetry = {"temperature": 41.9, "enabled": False, "currentFirmwareVersion": "v1.2.2"} + # Telemetry payload to send (will appear in the device telemetry in ThingsBoard) + telemetry = {"temperature": 41.9, "enabled": False, "currentFirmwareVersion": "v1.2.2"} -# Create MQTT client instance -client = TBDeviceMqttClient(host=HOST, port=PORT, access_token=TOKEN) + # Create MQTT client instance + client = TBDeviceMqttClient(host=HOST, port=PORT, access_token=TOKEN) -try: - print("Connecting...") - client.connect() # open MQTT connection to ThingsBoard - time.sleep(1) # small delay to ensure connection stabilizes on some boards - - print("Sending telemetry...") - client.send_telemetry(telemetry) # publish telemetry message - time.sleep(1) # allow time for message to be sent before disconnecting - -finally: - print("Disconnecting...") try: - client.disconnect() # close MQTT connection cleanly - except Exception as e: - # Prevent cleanup from crashing the script on disconnect issues - print("Disconnect error:", e) + print("Connecting...") + client.connect() # open MQTT connection to ThingsBoard + time.sleep(1) # small delay to ensure connection stabilizes on some boards + + print("Sending telemetry...") + client.send_telemetry(telemetry) # publish telemetry message + time.sleep(1) # allow time for message to be sent before disconnecting + + finally: + print("Disconnecting...") + try: + client.disconnect() # close MQTT connection cleanly + except Exception as e: + # Prevent cleanup from crashing the script on disconnect issues + print("Disconnect error:", e) +