scriptr.io is the Internet of Things Application Platform and Marketplace of extensible IoT Applications. It combines a visual environment and an extensive set of APIs for the rapid design, integration and development of applications that execute on a scalable, secure and robust runtime. scriptr.io is compatible with all major IoT data platforms to accelerate your IoT Digital Transformation.
To use Meshlium with scriptr.io you need the following: (1) Sign-up to scriptr.io, (2) Create a channel in your scriptr.io account, (3) Create a script in your scriptr.io account to receive the data sent by Meshlium, (4) Create a device on scriptr.io to authenticate the requests sent by Meshlium.
You can sign-up for an account by selecting one of the available registration methods from:
https://www.scriptr.io/register
After signing-up, or if you already had an account, sign-in to scriptr.io from https://www.scriptr.io/login using your credentials. Once authenticated, you will be directed to scriptr.io's Web IDE.
scriptr.io's channels are used to broadcast messages to your scripts, widgets or to the client applications that are using your services. To create a channel from scriptr.io's Web IDE (https://www.scriptr.io/workspace), click on the drop-down arrow near your username at the top-right corner of the screen, then select "Settings".
In the configuration dialog that is displayed, select the "Channels" tab. Click on "+Add Channel", then enter a name (e.g. "libelium"). Keep the checkboxes unchecked so that only authorized entities can publish or subscribe to this channel. Click on the check sign on the right to validate your changes.
Scripts are used to implement the logic of your IoT applications, in JavaScript. In the current case, we need a script that receives the data sent by the Meshlium device. To create a new script, click the "+New Script" option on the bottom-left corner of the Web IDE; or select "Script" from the drop-down.
You can configure Meshlium to use HTTP or AMQP to send data to your scriptr.io account. The below code caters to both configurations and parses the received data into a JSON object ("payload" in the below example). Copy & paste the following into the script editing area of the Web IDE:
// require the scriptr.io✬s log module and configure it to the "info" level
var log = require("log");
log.setLevel("info");
try {
var payload = null;
// Check if the payload is available in request.parameters
// (AMQP message) or in request.body (HTTP message)
if (request.parameters && Object.keys(request.parameters).length > 0) {
payload = JSON.parse(request.parameters.data)
}else {
payload = JSON.parse(request.body);
}
log.info("Received the following payload:\n" + JSON.stringify(payload));
// ADD YOUR CUSTOM LOGIC HERE
}catch(exception){
log.error("Something went wrong\n" + JSON.stringify(exception));
}
Give a name to your script (e.g. "libelium") and save it.
To access your resources on scriptr.io, third party clients - such as your Meshlium gateway - should authenticate. For that, they will use the credentials obtained after having been identified as devices in your scriptr.io account.
To create a new device, click on the drop-down near your username in the top right corner of the Web IDE, then select "Device Directory". Enter an ID and a password for your device. Confirm the password, then validate your changes by clicking on the check button on the right.
Your device is added and an authentication token has been generated for it.
To configure the scriptr.io cloud connector on Meshlium's Manager System, go to:
Cloud Connector -> Basic Cloud Partner -> scriptr
The configuration form is divided into 3 sections: a common section and 2 sections that are specific to the protocol (HTTP or AMQP) you will decide to use.
Note: if you have signed-up for a free scriptr.io account you should only choose HTTP.
Shared configuration
In the "Common" section, fill the following:
Using HTTP to send data
In the "Common" section, fill the following:
In the "HTTP" section, fill the following:
Note: if you have only signed-up to a free scriptr.io account don’t use AMQP.
In the "Common" section, fill the following:
In the "AMQP" section, fill the following:
Note: check next paragraph, “Obtaining AMQP configuration from scriptr.io”, for the values obtained from scriptr.io
From scripr.io's Web IDE, click on your username on the top-right corner of the screen and select "Queuing". In the resulting panel:
Copy the value of "Virtual host", "Username", "Password", "Exchange name" and "Routing Key to invoke" and paste them in the "AMQP" section of Meshlium's configuration.
In Meshlium Manager System, click the "Save" button for storing your configuration.
Once the cloud connector is configured, the user can launch it using the "Start" button. At specified intervals, the frames received from the sensors and stored in the local database will be sent to your script on scriptr.io. Check the status indicator of the cloud connector to know if it is "Running" (green light) or "Stopped" (red light).
You can stop the scriptr.io cloud connector anytime clicking on the "Stop" button.