TBRESTClientLib – A ThingsBoard API Client written in Swift

TBRESTClientLib – an abstract picture showing computers, smartphones, tablet PCs and smart devices being interconnected

Implementation of ThingsBoard’s ReST client API – written in Swift:

Motivation

When developing IoT and IIoT solutions, having a reliable IoT platform is crucial. For both private projects and at work, I use ThingsBoard (most of the time the Community Edition).

ThingsBoard provides device management, administration, and multiple options for storing and visualizing time-series data from sensors, field devices, machine control systems, and many more.

If you need to manage your IoT devices and access their time-series data through a mobile app, you have to implement ThingsBoard’s REST API (in Swift). That’s exactly what I’ve done with this library – meet TBRESTClientLib.

Version History

🛠 What’s new in v0.0.11?

  • Released: 2025-06-21
  • Both initializers now support an (optional) logger parameter which takes an Logger? instance (from OSLog) as an argument for improved logging capabilities
import OSLog
import TBRESTClientLib

let logger = Logger(subsystem: "myApp.TBRESTClientLib", category: "Library")
let myClient = try? TBUserApiClient(baseUrlStr: "https://my-thingsboard-iot-server.com",
                                    username: "MyUsername",
                                    password: "MySuperSecretPassword",
                                    logger: logger)

📚 For details check my DocC pages: ThingsBoard Swift Initialization & Login

🛠 What’s new in v0.0.10?

  • ✅ Introduced registerErrorHandler(apiErrorHandler:systemErrorHandler:) for more fine-grained error handling
  • ✅ Now distinguishes between API errors (e.g. HTTP 500) and system-level errors (e.g. DNS failure)
  • ✅ Both handlers are optional and can be registered or updated any time

📦 TBHTTPRequest/registerAppErrorHandler is now deprecated, refer to ThingsBoard Swift Client Initialization

🛠 Development Status (Version 0.0.9)

This library is continuously growing but has not yet implemented all API endpoints. Currently supported functionality:

Please refer to the documentation for further details regarding the development status.

Documentation ToC

Requirements

This library works with and was tested on:

  • iOS >= 17.5
  • macOS >= 14.0

Linux is currently unsupported bceause of an incompatibility in a way this library uses URLSession. A workaround seems to exist but was not further investigated, implemented or tested. (But it was added to my ToDos 😉)

Disclaimer

This library is an independent implementation and is not affiliated with, endorsed by, or officially associated with ThingsBoard Inc. in any way. It is licensed under the MIT License