Visualize sensor data from any machines
Once you have used the data management service to capture data, you can visualize your data with a variety of third-party tools, including Grafana, Tableau, Google’s Looker Studio, and more. You can choose to visualize data from a component on one machine, from multiple components together, or from many components across a fleet of machines.
For example, you can configure data capture for several sensors across multiple machines to report the ambient operating temperature. You can then visualize that data to easily understand how the ambient temperature affects your machines’ operation.
You can do all of this using the Viam app user interface. You will not need to write any code.
Prerequisites
Configure data query
If you want to query data from third party tools, you have to configure data query to obtain the credentials you need to connect to the third party service.
2. Find your organization ID
To create a database user allowing you to access your data, find your organization ID:
viam organizations list
3. Configure a new database user
Configure a new database user for the Viam organization’s MongoDB Atlas Data Federation instance, which is where your machine’s synced data is stored.
Warning
The command will create a user with your organization ID as the username. If you or someone else in your organization have already created this user, the following steps update the password for that user instead. Dashboards or other integrations relying on this password will then need to be updated.
Provide your organization’s org-id
from step 2, and a password for your database user.
viam data database configure --org-id=<YOUR-ORGANIZATION-ID> --password=<NEW-DBUSER-PASSWORD>
This command configures a database user for your organization for use with data query, and sets the password. If you have run this command before, this command instead updates the password to the new value you set.
4. Determine the connection URI
Determine the connection URI (also known as a connection string) for your organization’s MongoDB Atlas Data Federation instance by running the following command with the organization’s org-id
from step 2:
viam data database hostname --org-id=abcd1e2f-a1b2-3c45-de6f-ab123456c123
# Example output
MongoDB Atlas Data Federation instance hostname: data-federation-abcd1e2f-a1b2-3c45-de6f-ab123456c123-0z9yx.a.query.mongodb.net
MongoDB Atlas Data Federation instance connection URI: mongodb://db-user-abcd1e2f-a1b2-3c45-de6f-ab123456c123:YOUR-PASSWORD-HERE@data-federation-abcd1e2f-a1b2-3c45-de6f-ab123456c123-0z9yx.a.query.mongodb.net/?ssl=true&authSource=admin
This command returns:
hostname: the MongoDB Atlas Data Federation instance hostname
connection URI: the MongoDB Atlas Data Federation instance connection uniform resource indicator. This is the connection URI to your organization’s MongoDB Atlas Data Federation instance, which is of the form:
mongodb://<USERNAME>:<YOUR-PASSWORD>@<HOSTNAME>/?ssl=true&authSource=admin
Most MQL-compatible database clients require the connection URI, along with your user credentials, to connect to this server.
Some MQL-compatible database client instead require a hostname and database name, along with your user credentials, to connect to this server.
You will need the connection URI to query your data in the next section.
Visualize data with third-party tools
When you sync captured data to Viam, that data is stored in the Viam organization’s MongoDB Atlas Data Federation instance. You can use third-party visualization tools, such as Grafana, to visualize your data. Your chosen third-party visualization tool must be able to connect to a MongoDB Atlas Data Federation instance as its data store.
Select a tab below to learn how to configure your visualization tool for use with Viam:
1. Choose Grafana instance
Install or set up Grafana. You can use either a local instance of Grafana Enterprise or Grafana Cloud, and can use the free trial version of Grafana Cloud if desired.
2. Install connector to MongoDB data source
Navigate to your Grafana web UI. Go to Connections > Add new connection and add the Grafana MongoDB data source plugin to your Grafana instance.
Install the datasource plugin.
3. Configure a data connection
Navigate to the Grafana MongoDB data source that you just installed. Select Add new data source.
Enter the following information in the configuration UI for the plugin:
Connection string: Enter the following connection string, and replace
<MONGODB-ATLAS-DF-HOSTNAME>
with your database hostname as configured with theviam data database configure
command, and replace<DATABASE-NAME>
with the desired database name to query. For most use cases with Viam, this database name will besensorData
:mongodb://<MONGODB-ATLAS-DF-HOSTNAME>/<DATABASE-NAME>?directConnection=true&authSource=admin&tls=true
User: Enter the following username, substituting your organization ID as determined earlier, for
<YOUR-ORG-ID>
:db-user-<YOUR-ORG-ID>
Password: Enter the password you provided earlier.
4. Use Grafana for dashboards
With your data connection established, you can then build dashboards that provide insight into your data.
Grafana additionally supports the ability to directly query and transform your data within a dashboard to generate more granular visualizations of specific data. You might use this functionality to visualize only a single day’s metrics, limit the visualization to a select machine or component, or to isolate an outlier in your reported data, for example.
You can query your captured data within a Grafana dashboard using either SQL or MQL.
For example, try the following query to obtain readings from a sensor, replacing sensor-1
with the name of your component:
sensorData.readings.aggregate([
{$match: {
component_name: "sensor-1",
time_received: {$gte: ISODate(${__from})}
}},
{$limit: 1000}
]
)
See the guide on querying sensor data for more information.
1. Install connector to MongoDB data source
Some visualization clients are able to connect to the Viam MongoDB Atlas Data Federation instance natively, while others require that you install and configure an additional plugin or connector. For example, Tableau requires both the Atlas SQL JDBC Driver as well as the Tableau Connector in order to successfully connect and access data.
Check with the documentation for your third-party visualization tool to be sure you have the required additional software installed to connect to a MongoDB Atlas Data Federation instance.
2. Configure a data connection
Most third-party visualization tools require the connection URI (also called the connection string) to that database server, and the credentials to authenticate to that server in order to visualize your data. Some third-party tools instead require a hostname and database name of the database server. This is what they look like:
If your client supports a connection URI, use the following format and replace YOUR-PASSWORD-HERE
with your database password as configured with the viam data database configure
command:
mongodb://db-user-abcdef12-abcd-abcd-abcd-abcdef123456:YOUR-PASSWORD-HERE@data-federation-abcdef12-abcd-abcd-abcd-abcdef123456-e4irv.a.query.mongodb.net/?ssl=true&authSource=admin
You can also specify a desired database name in your connection URI, if desired.
For example, to use the sensorData
database, the default database name for uploaded sensor data, your connection string would resemble:
mongodb://db-user-abcdef12-abcd-abcd-abcd-abcdef123456:YOUR-PASSWORD-HERE@data-federation-abcdef12-abcd-abcd-abcd-abcdef123456-e4irv.a.query.mongodb.net/sensorData?ssl=true&authSource=admin
If you client doesn’t use a connection URI, you can supply the hostname and database name of the database server instead.
Substitute the hostname returned from the viam data database hostname
command for <MONGODB-ATLAS-DF-HOSTNAME>
and the desired database name to query for <DATABASE-NAME>
:
mongodb://<MONGODB-ATLAS-DF-HOSTNAME>/<DATABASE-NAME>?directConnection=true&authSource=admin&tls=true
For example, to use the sensorData
database, the default name for uploaded data, your connection string would resemble:
mongodb://data-federation-abcdef12-abcd-abcd-abcd-abcdef123456-e4irv.a.query.mongodb.net/sensorData?directConnection=true&authSource=admin&tls=true
If you are using a connection URI, the hostname and database name are already included in the URI string.
You database user name is of the following form:
db-user-<YOUR-ORG-ID>
Substitute your organization ID for <YOUR-ORG-ID>
.
3. Use visualization tools for dashboards
Some third-party visualization tools support the ability to directly query your data within their platform to generate more granular visualizations of specific data. You might use this functionality to visualize only a single day’s metrics, limit the visualization to a select machine or component, or to isolate an outlier in your reported data, for example.
While every third-party tool is different, you would generally query your data using either SQL or MQL. See the guide on querying sensor data for more information.
Next steps
For more detailed instructions on using Grafana, including a full step-by-step configuration walkthrough, see visualizing data with Grafana.
On top of visualizing sensor data with third-party tools, you can also query it with the Python SDK or query it with the Viam app.
To see full projects using visualization, check out these resources:
Have questions, or want to meet other people working on robots? Join our Community Discord.
If you notice any issues with the documentation, feel free to file an issue or edit this file.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!