Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/derhuerst/thingsboard-telemetry-stream
Fetch data from the Thingsboard telemetry WebSocket API.
https://github.com/derhuerst/thingsboard-telemetry-stream
api iot thingsboard
Last synced: about 1 month ago
JSON representation
Fetch data from the Thingsboard telemetry WebSocket API.
- Host: GitHub
- URL: https://github.com/derhuerst/thingsboard-telemetry-stream
- Owner: derhuerst
- License: isc
- Created: 2021-06-05T17:30:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-05-07T13:47:51.000Z (almost 2 years ago)
- Last Synced: 2024-12-25T00:30:10.457Z (about 2 months ago)
- Topics: api, iot, thingsboard
- Language: JavaScript
- Homepage:
- Size: 20.5 KB
- Stars: 9
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.md
Awesome Lists containing this project
- awesome-thingsboard - thingsboard-telemetry-stream - fetch data from the Thingsboard telemetry [WebSocket API](https://thingsboard.io/docs/user-guide/telemetry/#websocket-api) (SDKs and REST clients)
README
# thingsboard-telemetry-stream
**Fetch data from the [Thingsboard](https://thingsboard.io/) [telemetry WebSocket API](https://thingsboard.io/docs/user-guide/telemetry/#websocket-api).**
[](https://www.npmjs.com/package/thingsboard-telemetry-stream)


[](https://github.com/sponsors/derhuerst)
[](https://twitter.com/derhuerst)## Installation
```shell
npm install thingsboard-telemetry-stream
```## Usage
```js
const {connect} = require('thingsboard-telemetry-stream')const connection = await connect({
token: '',
})
connection.addEventListener('error', abortWithError)
```If you pass in `token` or set the `THINGSBOARD_TOKEN` environment variable, only this token will be used. To let it periodically generate new token instead, pass in `user` & `password` or set the `THINGSBOARD_USER` & `THINGSBOARD_PASSWORD` environment variables.
### subscribing to devices' telemetry data
```js
const {fetchDevices, subscribeToTimeseries} = require('.')const deviceGroupId = '780c1435-cac2-4be7-8d85-0961239e02e4'
const devices = await fetchDevices(connection, deviceGroupId)
const deviceIds = devices.map(d => d.entityId.id)
const sub = await subscribeToTimeseries(connection, deviceIds)// all devices's telemetry
sub.on('data', (deviceId, data) => console.log(deviceId, data))
// a single device's telemetry
sub.on('338e9c33-988f-4314-9e46-cb8c94236942:data', (data) => console.log(data))
```### sending commands manually
```js
const {sendCommands, getCommandId} = require('.')const res = await sendCommands(connection, {
entityDataCmds: [{
cmdId: getCommandId(connection),
query: {
entityFilter: {
type: 'entityGroup',
groupType: 'DEVICE',
entityGroup: '780c1435-cac2-4be7-8d85-0961239e02e4',
},
pageLink: {pageSize: 10},
},
}],
})
console.log(res.entityDataCmds[0])
``````js
{
data: [
{
entityId: {
entityType: 'DEVICE',
id: '338e9c33-988f-4314-9e46-cb8c94236942'
},
readAttrs: true, readTs: true,
latest: {}, timeseries: {},
},
{
entityId: {
entityType: 'DEVICE',
id: 'cf59aeaa-7a09-457a-bd04-4f3a2596b960'
},
readAttrs: true, readTs: true,
latest: {}, timeseries: {},
},
],
totalPages: 1,
totalElements: 2,
hasNext: false,
}
```## Contributing
If you have a question or need support using `thingsboard-telemetry-stream`, please double-check your code and setup first. If you think you have found a bug or want to propose a feature, use [the issues page](https://github.com/derhuerst/thingsboard-telemetry-stream/issues).