# thingsboard-js-sdk

> Thingsboard SDK for Javascript

Latest version **0.1.0** (published 2021-06-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install thingsboard-js-sdk
pnpm add thingsboard-js-sdk
yarn add thingsboard-js-sdk
bun add thingsboard-js-sdk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2021-06-02 |
| First published | 2021-02-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.2 KB |
| Known vulnerabilities | 0 (+23 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 15 |
| Author | ACTE Technology Co., Ltd. |
| Maintainers | actetechnology |
| Keywords | thingsboard, IoT |

## Links

- npm: https://www.npmjs.com/package/thingsboard-js-sdk
- Repository: https://github.com/acte-technology/thingsboard-js-sdk
- Homepage: https://github.com/acte-technology/thingsboard-js-sdk.git
- Issues: https://github.com/acte-technology/thingsboard-js-sdk/issues
- npm.io page: https://npm.io/package/thingsboard-js-sdk

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^0.21.1
- [jwt-decode](https://npm.io/package/jwt-decode.md) ^3.1.2

## Recent versions

- 0.1.0 (latest) — 2021-06-02
- 0.0.11 — 2021-05-29
- 0.0.10 — 2021-05-29
- 0.0.9 — 2021-05-29
- 0.0.8 — 2021-05-03
- 0.0.7 — 2021-02-11
- 0.0.6 — 2021-02-10
- 0.0.5 — 2021-02-10
- 0.0.4 — 2021-02-10
- 0.0.2 — 2021-02-09
- 0.0.1 — 2021-02-09

## README

# Thingsboard Javascript SDK

Thingsboard Javascript SDK

**Dev version, work in progress.**

## Installation

```bash
npm install thingsboard-js-sdk
```

## Examples

* Reactjs, checkout docs/reactjs.js component.


## Methods

- connect
- disconnect
- subscribe (websocket)
- getTenantDevices
- getKeys (timeseries & attributes)
- deleteEntityKeys (timeseries & attributes)
- getAttributesByScope
- getTimeseries

### Import client class

```js
import tbClient from 'thingsboard-js-sdk';
const client = new tbClient(config);
```

### Connect to public device

```js
const client = new tbClient({
  host: 'localhost',
  publicId: 'xxx-xxx-xxx-xxx'
});

const connect = async () => {

  const token = await client.connect(true); //true for public login

}
```

### Connect with user/password

```js
const client = new tbClient({
  host: 'localhost',
  username: 'username',
  password: 'password'
});

const connect = async () => {

  const token = await client.connect();

}
```

### Get Tenant Devices

*must be logged as a tenant*

```js
const params = {
  pageSize: 100,
  page: 0,
  sortProperty: 'name',
  sortOrder: 'ASC'
}
//...
let devices = await client.getTenantDevices(params, callback)
```

### Get Keys

```js
const params = {
  entityId: 'xxx-xxx-xxx',
  scope: 'timeseries', //timeseries | client | shared | server
}
//...
let keys = await client.getKeys(params, callback)
```

### Get Attributes By Scope

```js
const params = {
  entityId: 'xxx-xxx-xxx',
  scope: 'CLIENT_SCOPE', // CLIENT_SCOPE | SHARED_SCOPE | SERVER_SCOPE
  keys: ['temperature', 'humidity']
}
//...
let attrs = await client.getAttributesByScope(params, callback)
```

### Delete keys

```js
const params = {
  entityId: 'xxx-xxx-xxx',
  keys: ['temperature', 'humidity'],
  olderThan: Date.now()-3600, //delete older than 1 hour
  scope: 'timeseries' // timeseries, client, shared, server
}
//...
let response = await client.deleteEntityKeys(params, callback)
```

### Get timeseries

```js
const now = Date.now();

const params = {
  entityId: 'xxx-xxx-xxx',
  keys: ['temperature', 'humidity']
  limit: 500,
  agg: 'AVG',
  interval: 60000,
  startTs: now-3600000,
  endTs: now,
  useStrictDataTypes: true
}
//...
let timeseries = await client.getTimeseries(params, callback)
```

### WSS Websocket subscribe

```js
const params = {
  entityId: 'xxx-xxx-xxx',
  cmdId: 10 //websocket id
}
//...
let keys = await client.subscribe(params, callback)
```

## Issues

Github: https://github.com/acte-technology/thingsboard-js-sdk/issues

---
_Source: https://npm.io/package/thingsboard-js-sdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
