Go
Streaming sensor data into Sift using Go
Credentials
Before starting this section be sure to retrieve your API key and the appropriate Sift URL for your provisioned environment. Instructions on how to retrieve the API key and URL and can be found in the authentication section of the documentation.
This exercise demonstrates how to stream data into Sift using the Go client library.
The goal is to read in data from a mock data source representing sensor data from our asset,
NostromoLV426
, and then stream that data to Sift.
NostromoLV426
will contain a single mainmotor.velocity
channel whose
values are of type double
.
For full code examples, documentation, as well as the library's source code, refer to the following:
Installing Dependencies
For this exercise we just need to install the Sift Go module inside of a new Go project:
Imports
With our Sift module installed, we're going to begin by importing everything we will use for this example in advance. Inside of main.go
:
Data Source
Next we're going to define a data source which will provide us with mock sensor data. The data source will simply send a timestamp and a float
over the course of a minute and sleep for 0.5s
between each send. This will represent the time-series coming from the velocity
channel:
Config
Now we will define our channels in a function called configs
. Right now we only have one velocity
channel but
we are free to add more later.
Next, we will define a function called get_or_create_ingestion
config which retrieves an existing
ingestion config
by client key or creates it if it does not exist. This function will use the configs
function that we created
in the previous step:
Client Keys
As mentioned in the ingestion config section, specifying a client key is highly recommended as it simplifies lookups for users after creation as shown above.
Creating a Run
Now we will make a create_run
function so we can group together our asset data.
Runs are Optional
Creating a run is not required to send data to Sift. It's a mechanism to group together data for a single asset or multiple assets. Read more.
Sending Data
Now all that's left to do is to assemble our main
function:
And that's it! In Sift, you should see the asset, NostromoLV426
, the run we just created, as well as
data for the velocity
channel.