Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 42 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -97,15 +97,46 @@ Client initialization and telemetry publishing

.. code-block:: python

from tb_device_mqtt import TBDeviceMqttClient
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 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"}
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()

# 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
============
Expand Down
42 changes: 42 additions & 0 deletions examples/send_telemetry.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 0 additions & 4 deletions examples/thingsboard-client-sdk_simpletest.py

This file was deleted.