How to send a stream using cURL
This tutorial will show how to send data streams to Altair SmartWorks with cURL.
First, we need to know what we want to send and how to send it. Data is sent to Altair SmartWorks REST API. You need:
- A device in Altair SmartWorks
- A valid Apikey
- Your data
- A REST client
If youre registered in Altair SmartWorks, you have a default device already created for you.
Check your control panel and see what it looks like.
Basically you need the device id_developer that might be something like defaultDevice@myusername.
We will assume we have the test@smartcore device for this tutorial.
Now, go to your control panel “My account menu” and check your Apikey.
Its a big alphanumeric token like 98346673a6377ef1fde2357ebdcb0da582b150b00cabcd5a0d83045425407ab4.
Now we define our data. It will be a simple data set with temperature and humidity:
Finally we need a REST client. This client can be whatever you want that can create full HTTP request including headers, verbs and so on.
In this tutorial we will use cURL. If you are not familiar with cURL you might want to check the official page: http://curl.haxx.se/ for installation instructions and documentation. We will assume you will have it installed and running. You can also follow this tutorial with other REST clients such as APItester (https://apitester.com/) or Poster plugin (https://addons.mozilla.org/en-us/firefox/addon/poster/)
Your payload, the stream to send to Altair SmartWorks, will be:
If you prefer to send the stream in XML format, then your payload will be:
Protocol will be used in future versions of Altair SmartWorks along with checksum. Use v2 for the protocol.
The at field is the epoch time for the stream you can run date +%s to get it in Unix/Linux shell or go to http://www.epochconverter.com/ hre and grab one. data field contains your data.
Create a file containing the payload: payload.txt
The target URL is: http://api.altairsmartcore.com/streams/
Lets send it to Altair SmartWorks!
Type the cURL command (payload in JSON format):
Type the cURL command (payload in XML format):
This command send a POST request to Altair SmartWorks REST API including the data from payload.txt file. The corresponding apikey
--verbose is there because you like to see it all.
Your response must be something like:
Now you can see your stream listed in the control panel stream list. Go to “Data management” → “Data streams” and you will see your data.