The analysis is a powerful feature at Tago that experts and software developers can use to implement scripts to analyze and manipulate the data sent by the devices in real time.
Analysis is programmed using Node.js Tago’s SDK. You can get more instructions on how to write an analysis script in our SDK documentation.
By using the Analysis, you have access to all your data, devices, and even to other services provided by Tago. One example of service is Weather that provides real time condition information about the current and forecasted weather for different locations.
Also, if you combine Analysis with Actions you can execute that script whenever a predefined variable with a new value arrives at Tago. For example, you can process your information, convert it, or perform any math transformation for that variable. Also you can add new values in another data bucket, read the data from there, or setup actions that will send email, SMS, or the data back to a specific device. If you are new at Tago, take a look at this short video that will introduce you to Tago Analysis. You will understand how the pieces are put together, and what are the steps that you need to take to start scripting today.
There are three main steps that you need to take in order to create and run your scripts on analysis.
Creating an Analysis¶
Creating your own analysis is easy. First, you need to click on Add Analysis in the upper right of the analysis main screen. Just write a name and a description, and you’re ready to go!
It’s possible to setup the analysis in many ways. For initial purposes, we will only set the analysis to run with an external script. It allows you to run the analysis directly from your machine, and do any changes you want in realtime. After downloading the example, you need to get Analysis-Token from your analysis and set it inside the index.js
2. Code your script¶
Open the example with the editor of your preference, and make the changes that you need in the code as necessary. Currently, if you are wish to run your code at Tago, have in mind that Tago only supports Node.js and Python languages. However, you are free to use any language you want if you select to run the analysis in the ‘external’ server. It means that if you chose to program in another language, you won’t be able to upload the script on Tago; you will need to run the code in your own machine or in another server instead.
To write your code using node.js language, follow these steps:
Node.js and NPM¶
Warning: As you in most cases developers will upload their code to run it automatically on Tago server, it is necessary to make sure that you install the most recent LTS, Long Term Support, version. Current Tago runs on the v6.10. Therefore, don’t use the most recent non-LTS version, unless you will only run it at your machine or another server.
We are still working on a SDK to support the Python language. Check Other Languages if you need to program in Python before our official support.
After you have coded and debuged your code, you can upload the script (only one file) to Tago.
Remember that Tago will run your script using Node version v6.10 LTS or Python 2.7. If you are using a more recent version, you should check for compatibility before uploading it.
All available examples for download are compatible with Tago
When you get inside the analysis section that you created, you will come across some configuration fields that will help you to define how Tago should manage it. In the General Information area, you should define the time interval that your analysis should run(you should select to run it by (1) time based for a fix period of time, or (2) external event only). Also, you can define environment variables that are essential for a successful development of modular scripts.
Enviroment Variable is a very useful resource used to send variables values to the context of your script. You can, for example, add tokens of accounts and devices to be used later in the script when it runs. The Analysis will get these variables as “environment” parameters and used them in the context of your script.
Tago provides a list of examples to help you to understand how to use Tago analysis services. There, you can get great examples on how to get and insert data into your database, send emails, run some calculations, and other interesting things that can be added to your applications.
All examples come with a README.md file that gives instructions to help you put the analysis to work. Remember to read it before starting to modify the code.
Use the console to monitor the variables and status of your script. You can see any error or word generated by “console.log”. The console is also a very good debug tool.