@empa-electronics/tiremo-sdk-client-js
v0.1.6
Published
Browser JavaScript client for the TIREMO SDK REST and live WebSocket APIs
Maintainers
Readme
@empa-electronics/tiremo-sdk-client-js
Browser / bundler client for the TIREMO SDK. Uses native fetch and WebSocket with no runtime dependencies.
Works with React, Vue, Svelte, Vite, or plain ES modules.
Documentation
| Topic | Link | | --- | --- | | SDK Live Data | docs.tiremo.ai/developer-guide/sdk-live-data | | API Key Security | docs.tiremo.ai/developer-guide/sdk-api-key-security | | HTML examples | TIREMO-SDK/examples |
Getting started
1. Install
npm install @empa-electronics/tiremo-sdk-client-js2. Get an API key
Create a product-scoped API key in the Tiremo Platform Administration → API Credentials UI.
For browser apps use a public key with origin restrictions. Public keys cannot open WebSocket connections directly — mint a short-lived token on your backend first.
3. Create a client
import { TiremoClient } from "@empa-electronics/tiremo-sdk-client-js";
const client = new TiremoClient({
baseUrl: "https://sdk.tiremo.ai",
apiKey: process.env.TIREMO_API_KEY!,
});baseUrl is your SDK host without a trailing slash. apiKey is sent as the X-API-Key header on REST calls.
4. Typical browser flow
- Load the latest stored telemetry over REST (bootstrap gauges/charts).
- On your backend, call
createToken()with a secret key. - Pass the token to the browser and connect with
connectWithToken(). - Subscribe to live channels after the
connectedevent.
Usage examples
TiremoClient — REST
devices.getTelemetryLatest(deviceIdentifier, options?)
Fetch the most recent stored telemetry point for a device.
const latest = await client.devices.getTelemetryLatest("cameradevice9", {
keys: ["temperature", "humidity"],
});
console.log(latest.timestamp);
console.log(latest.data.temperature);
// { deviceIdentifier, timestamp, data: { temperature: 21.4, ... } }Omit keys to receive all keys for the latest point.
live.createToken()
Exchange your API key for a short-lived WebSocket token. Call this from a server route, not from browser code with a secret key.
const { token, expiresAt } = await client.live.createToken();
// Pass `token` to the browser (e.g. JSON API response)live.connectWithToken(token)
Create a live client authenticated with a short-lived token (browser-safe).
const live = client.live.connectWithToken(token);live.connectWithSecretKey()
Connect with the secret API key directly. Do not use in browser code — only for trusted server-side scripts.
const live = client.live.connectWithSecretKey();TiremoLiveClient — WebSocket
connect() / disconnect()
live.connect();
// ...
live.disconnect();on(event, handler)
Register event handlers. Returns an unsubscribe function.
const off = live.on("telemetry", (event) => {
console.log(event.subscriptionId, event.data);
});
off(); // remove handlerEvents: connected, telemetry, presence, alarm, error, message.
live.on("connected", (event) => {
console.log(event.productIdentifier, event.protocolVersion);
});
live.on("presence", (event) => {
console.log(event.deviceIdentifier, event.isOnline);
});
live.on("alarm", (event) => {
console.log(event.alarmType, event.severity, event.code);
});
live.on("error", (event) => {
console.error(event.code, event.message);
});subscribeTelemetry({ id, deviceIdentifier, keys? })
live.on("connected", () => {
live.subscribeTelemetry({
id: "temp-sub",
deviceIdentifier: "cameradevice9",
keys: ["temperature"],
});
});subscribePresence({ id, deviceIdentifier })
live.subscribePresence({
id: "presence-sub",
deviceIdentifier: "cameradevice9",
});subscribeAlarm({ id, deviceIdentifier })
live.subscribeAlarm({
id: "alarm-sub",
deviceIdentifier: "cameradevice9",
});unsubscribe(subscriptionId)
live.unsubscribe("temp-sub");Ping/pong heartbeats are handled automatically.
Full example
import { TiremoClient } from "@empa-electronics/tiremo-sdk-client-js";
const client = new TiremoClient({
baseUrl: "https://sdk.tiremo.ai",
apiKey: process.env.TIREMO_API_KEY!,
});
const latest = await client.devices.getTelemetryLatest("cameradevice9", {
keys: ["temperature"],
});
const { token } = await client.live.createToken();
const live = client.live.connectWithToken(token);
live.on("connected", () => {
live.subscribeTelemetry({
id: "temp",
deviceIdentifier: "cameradevice9",
keys: ["temperature"],
});
});
live.on("telemetry", (event) => {
console.log(latest.data, "→", event.data);
});
live.connect();Related packages
| Package | Use case |
| --- | --- |
| @empa-electronics/tiremo-sdk-client-node | Node.js 18+ |
| tiremo-sdk-client | Python |
License
ISC — Empa Electronics
