How to send a stream using cURL
This tutorial will show how to send data streams to Carriots with cURL.
First, we need to know what we want to send and how to send it. Data is sent to Carriots REST API. You need:
- A device in Carriots
- A valid Apikey
- Your data
- A REST client
If youre registered in Carriots, 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@carriots 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 hurl (http://www.hurl.it/) or Poster plugin (https://addons.mozilla.org/en-us/firefox/addon/poster/)
Your payload, the stream to send to Carriots, 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 Carriots along with checksum. Let it be v1 or whatever for the protocol and leave it blank for the checksum. Both will be ignored for the actual REST API version.
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.carriots.com/streams/
Lets send it to Carriots!
Type the cURL command (payload in JSON format):
Type the cURL command (payload in XML format):
This command send a POST request to Carriots 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.