{"id":13834446,"url":"https://github.com/derhuerst/thingsboard-telemetry-stream","last_synced_at":"2025-10-05T07:36:17.319Z","repository":{"id":66219608,"uuid":"374174729","full_name":"derhuerst/thingsboard-telemetry-stream","owner":"derhuerst","description":"Fetch data from the Thingsboard telemetry WebSocket API.","archived":false,"fork":false,"pushed_at":"2023-05-07T13:47:51.000Z","size":21,"stargazers_count":11,"open_issues_count":1,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-28T16:11:43.859Z","etag":null,"topics":["api","iot","thingsboard"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/derhuerst.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2021-06-05T17:30:51.000Z","updated_at":"2025-01-22T12:17:51.000Z","dependencies_parsed_at":"2024-01-15T18:46:38.957Z","dependency_job_id":"9270ac64-e69e-4212-a300-59730ce1596d","html_url":"https://github.com/derhuerst/thingsboard-telemetry-stream","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fthingsboard-telemetry-stream","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fthingsboard-telemetry-stream/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fthingsboard-telemetry-stream/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/derhuerst%2Fthingsboard-telemetry-stream/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/derhuerst","download_url":"https://codeload.github.com/derhuerst/thingsboard-telemetry-stream/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248681494,"owners_count":21144700,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","iot","thingsboard"],"created_at":"2024-08-04T14:00:34.769Z","updated_at":"2025-10-05T07:36:12.290Z","avatar_url":"https://github.com/derhuerst.png","language":"JavaScript","funding_links":["https://github.com/sponsors/derhuerst"],"categories":["SDKs and REST clients"],"sub_categories":[],"readme":"# thingsboard-telemetry-stream\n\n**Fetch data from the [Thingsboard](https://thingsboard.io/) [telemetry WebSocket API](https://thingsboard.io/docs/user-guide/telemetry/#websocket-api).**\n\n[![npm version](https://img.shields.io/npm/v/thingsboard-telemetry-stream.svg)](https://www.npmjs.com/package/thingsboard-telemetry-stream)\n![ISC-licensed](https://img.shields.io/github/license/derhuerst/thingsboard-telemetry-stream.svg)\n![minimum Node.js version](https://img.shields.io/node/v/thingsboard-telemetry-stream.svg)\n[![support me via GitHub Sponsors](https://img.shields.io/badge/support%20me-donate-fa7664.svg)](https://github.com/sponsors/derhuerst)\n[![chat with me on Twitter](https://img.shields.io/badge/chat%20with%20me-on%20Twitter-1da1f2.svg)](https://twitter.com/derhuerst)\n\n\n## Installation\n\n```shell\nnpm install thingsboard-telemetry-stream\n```\n\n\n## Usage\n\n```js\nconst {connect} = require('thingsboard-telemetry-stream')\n\nconst connection = await connect({\n\ttoken: '\u003cAPI token here\u003e',\n})\nconnection.addEventListener('error', abortWithError)\n```\n\nIf 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` \u0026 `password` or set the `THINGSBOARD_USER` \u0026 `THINGSBOARD_PASSWORD` environment variables.\n\n### subscribing to devices' telemetry data\n\n```js\nconst {fetchDevices, subscribeToTimeseries} = require('.')\n\nconst deviceGroupId = '780c1435-cac2-4be7-8d85-0961239e02e4'\n\nconst devices = await fetchDevices(connection, deviceGroupId)\nconst deviceIds = devices.map(d =\u003e d.entityId.id)\nconst sub = await subscribeToTimeseries(connection, deviceIds)\n\n// all devices's telemetry\nsub.on('data', (deviceId, data) =\u003e console.log(deviceId, data))\n// a single device's telemetry\nsub.on('338e9c33-988f-4314-9e46-cb8c94236942:data', (data) =\u003e console.log(data))\n```\n\n### sending commands manually\n\n```js\nconst {sendCommands, getCommandId} = require('.')\n\nconst res = await sendCommands(connection, {\n\tentityDataCmds: [{\n\t\tcmdId: getCommandId(connection),\n\t\tquery: {\n\t\t\tentityFilter: {\n\t\t\t\ttype: 'entityGroup',\n\t\t\t\tgroupType: 'DEVICE',\n\t\t\t\tentityGroup: '780c1435-cac2-4be7-8d85-0961239e02e4',\n\t\t\t},\n\t\t\tpageLink: {pageSize: 10},\n\t\t},\n\t}],\n})\nconsole.log(res.entityDataCmds[0])\n```\n\n```js\n{\n\tdata: [\n\t\t{\n\t\t\tentityId: {\n\t\t\t\tentityType: 'DEVICE',\n\t\t\t\tid: '338e9c33-988f-4314-9e46-cb8c94236942'\n\t\t\t},\n\t\t\treadAttrs: true, readTs: true,\n\t\t\tlatest: {}, timeseries: {},\n\t\t},\n\t\t{\n\t\t\tentityId: {\n\t\t\t\tentityType: 'DEVICE',\n\t\t\t\tid: 'cf59aeaa-7a09-457a-bd04-4f3a2596b960'\n\t\t\t},\n\t\t\treadAttrs: true, readTs: true,\n\t\t\tlatest: {}, timeseries: {},\n\t\t},\n\t],\n\ttotalPages: 1,\n\ttotalElements: 2,\n\thasNext: false,\n}\n```\n\n\n## Contributing\n\nIf 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).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Fthingsboard-telemetry-stream","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fderhuerst%2Fthingsboard-telemetry-stream","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fderhuerst%2Fthingsboard-telemetry-stream/lists"}