Data SDK

Conceptual Overview

The Data SDK is Formant's TypeScript library for accessing your devices, receiving datapoints from telemetry streams, and establishing real-time connections.

Using the Data SDK to communicate with devices

The toolkit includes high-level APIs for communicating with your fleet. Using the Data SDK, you can use the same pipes Formant uses to build our observability and teleop products to build anything you need.

1045

The Data SDK is used to allow your custom views or modules to communicate with both Formant and each other. You can also talk directly with Formant's servers with the Data SDK without needing to create a custom module or view.

Quickstart 1 – Using the Data SDK as an embedded custom view or module

Using the Data SDK, we can get the current authentication information from the URL parameters. In the "Commands" example, we would use a URL like this:

https://formantio.github.io/toolkit/examples/commands/dist/?module={module}&auth={auth}

Using the Data SDK in your page's JavaScript

import { Authentication, Fleet, App } from "@formant/data-sdk";

// must have the "?auth={auth}" query param set
// The following line is optional, because authentication will happen
// automatically. This will just wait to be sure.
await Authentication.waitTilAuthenticated();

// Get the context of a device is passed along as a query string
const device = await Fleet.getCurrentDevice();

// Get data ...
const data = await device.getLatestTelemetry();

// Are we running as a module?
const isModule = App.isModule();

// Set a data handler when this module gets new data
if (isModule) {
	App.addModuleDataListener((data: ModuleData) => {
  	App.showMessage("recieved data: " + data);
	});
}

For a walkthrough of the code, see the recipe below:

Configure the custom module in Formant

In the Edit Layout section of the setup process for your view, click the "Add Module" button below to add your custom module.

2964

Add the URL to your module's code

970

An example of a module URL

Quickstart 2 – Using the Data SDK from an external location

In this case, when our custom view is not being embedded within the Formant app, we must authenticate with login information. Instead of calling Authentication.waitTilAuthenticated(), you must pass the username and password to the Authentication.login().

import { Authentication, Fleet } from "@formant/data-sdk";

await Authentication.login("[email protected]", "12345");

After authenticating this way, you can continue to use the Data SDK as you would have in the previous step.

👋

If you notice an issue with this page or need help, please reach out to us! Use the 'Did this page help you?' buttons below, or get in contact with our Customer Success team via the Intercom messenger in the bottom-right corner of this page, or at [email protected].