Giter VIP home page Giter VIP logo

thingsboard-telemetry-stream's Introduction

thingsboard-telemetry-stream

Fetch data from the Thingsboard telemetry WebSocket API.

npm version ISC-licensed minimum Node.js version support me via GitHub Sponsors chat with me on Twitter

Installation

npm install thingsboard-telemetry-stream

Usage

const {connect} = require('thingsboard-telemetry-stream')

const connection = await connect({
	token: '<API token here>',
})
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

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

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])
{
	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.

thingsboard-telemetry-stream's People

Contributors

derhuerst avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

thingsboard-telemetry-stream's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.