Create a custom web interface

Create and deploy custom web interfaces for your machines as single-page applications without managing hosting and authentication. Once deployed, apps are accessible from a dedicated URL (appname_publicnamespace.viamapplications.com) and hosting and authentication is handled for you.

When opening an app, users log in and then select a machine they have access to. Then your app is rendered and ready for use.

App screen asking for the org, location, and machine.

Requirements

Install the Viam CLI and authenticate.

Install the Viam CLI using the option below that matches your system architecture:

To download the Viam CLI on a macOS computer, install brew and run the following commands:

brew tap viamrobotics/brews
brew install viam

To download the Viam CLI on a Linux computer with the aarch64 architecture, run the following commands:

sudo curl -o /usr/local/bin/viam https://storage.googleapis.com/packages.viam.com/apps/viam-cli/viam-cli-stable-linux-arm64
sudo chmod a+rx /usr/local/bin/viam

To download the Viam CLI on a Linux computer with the amd64 (Intel x86_64) architecture, run the following commands:

sudo curl -o /usr/local/bin/viam https://storage.googleapis.com/packages.viam.com/apps/viam-cli/viam-cli-stable-linux-amd64
sudo chmod a+rx /usr/local/bin/viam

You can also install the Viam CLI using brew on Linux amd64 (Intel x86_64):

brew tap viamrobotics/brews
brew install viam

Download the binary and run it directly to use the Viam CLI on a Windows computer.

If you have Go installed, you can build the Viam CLI directly from source using the go install command:

go install go.viam.com/rdk/cli/viam@latest

To confirm viam is installed and ready to use, issue the viam command from your terminal. If you see help instructions, everything is correctly installed. If you do not see help instructions, add your local go/bin/* directory to your PATH variable. If you use bash as your shell, you can use the following command:

echo 'export PATH="$HOME/go/bin:$PATH"' >> ~/.bashrc

For more information see install the Viam CLI.

Then authenticate your CLI session with Viam using one of the following options:

viam login

This will open a new browser window with a prompt to start the authentication process. If a browser window does not open, the CLI will present a URL for you to manually open in your browser. Follow the instructions to complete the authentication process.

Use your organization, location, or machine part API key and corresponding API key ID in the following command:

viam login api-key --key-id <api-key-id> --key <organization-api-key-secret>

Create a single page app

1

Build your application using your preferred framework like React, Vue, Angular, or others. While you’re developing use any machine’s credentials. For deploying your app you must add code to read the machine API key from your browsers local storage:

import Cookies from "js-cookie";

let apiKeyId = "";
let apiKeySecret = "";
let hostname = "";
let machineId = "";

machineId = window.location.pathname.split("/")[2];
({
  id: apiKeyId,
  key: apiKeySecret,
  hostname: hostname,
} = JSON.parse(Cookies.get(machineId)!));
2

Create a meta.json file using this template:

{
  "module_id": "your-namespace:your-module",
  "visibility": "public",
  "url": "https://github.com/your-org/your-repo",
  "description": "Your module description",
  "applications": [
    {
      "name": "your-app-name",
      "type": "single_machine",
      "entrypoint": "dist/index.html"
    }
  ]
}
{
  "module_id": "acme:dashboard",
  "visibility": "public",
  "url": "https://github.com/acme/dashboard",
  "description": "An example dashboard for a fictitious company called Acme.",
  "applications": [
    {
      "name": "dashboard",
      "type": "single_machine",
      "entrypoint": "dist/index.html"
    }
  ]
}
Click to view
NameTypeInclusionDescription
module_idstringRequiredThe module ID, which includes the organization name and the module name. module_id uniquely identifies your module.
visibilitystringRequiredMust be "public".
descriptionstringRequiredA description of your module and what it provides.
urlstringOptionalThe URL of the GitHub repository containing the source code of the module.
applicationsarrayOptionalObjects that provide information about the single page apps associated with the module.
modelsarrayOptionalEmpty unless you are shipping the app alongside models. For information on how to add models, see Integrate other hardware.

The applications field is an array of application objects with the following properties:

PropertyTypeDescription
namestringThe name of your application, which will be a part of the app’s URL (name_publicnamespace.viamapplications.com). For more information on valid names see .
typestringThe type of application (currently only "single_machine" is supported).
entrypointstringThe path to the HTML entry point for your application. The entrypoint field specifies the path to your application’s entry point. For example:
  • “dist/index.html”: Static content rooted at the dist directory
  • “dist/foo.html”: Static content rooted at the dist directory, with foo.html as the entry point
  • “dist/": Static content rooted at the dist directory (assumes dist/index.html exists)
  • “dist/bar/foo.html”: Static content rooted at dist/bar with foo.html as the entry point
3

Register your module with Viam:

viam module create --name="app-name" --public-namespace="namespace"
viam module create --name="air-quality" --public-namespace="naomi"
4

Package your static files and your meta.json file and upload them to the Viam Registry:

tar -czvf module.tar.gz <static-website-files> meta.json
viam module upload module.tar.gz --platform=any --version=0.0.1

For subsequent updates run these commands again with an updated version number.

Accessing your Single Page App

After uploading your module with the application configuration, your application will be available at:

https://your-app-name_your-public-namespace.viamapplications.com

Users will be prompted to authenticate with their Viam credentials before accessing your application:

  1. User navigates to your-app-name_your-public-namespace.viamapplications.com
  2. User authenticates with Viam credentials
  3. User selects an organization, location, and machine
  4. User is redirected to your-app-name_your-public-namespace.viamapplications.com/machine/{machine-id}
  5. Your application is rendered with access to the selected machine

Example

For an example see Monitor Air Quality with a Fleet of Sensors.

Limitations

  • Single page apps currently only support single-machine applications
  • All modules with apps must have public visibility
  • There is no separate deploy step; the page will always render the latest version
  • Browsers with cookies disabled are not supported

Security Considerations

  • Customer apps are stored in GCS buckets that are publicly available on the internet
  • Avoid uploading sensitive information in your application code or assets
  • API keys and secrets are stored in the browser’s localStorage or sessionStorage
  • Single page apps authenticate users with FusionAuth