scriptr.io

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.

Using Meshlium with scriptr.io

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.

Sign-up to scriptr.io

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.

Create a channel in your scriptr.io account

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.

Figure : Configure your channel

Create a script to receive data

Figure : Create a new script

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.

Figure : Name and save your script

Create a device to authenticate the requests

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.

Figure : Create a new device

Your device is added and an authentication token has been generated for it.

Figure : Every new device gets an authentication token to authenticate against scriptr.io

Configuration

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:

  • Script name: enter the name of the script you created in the section (e.g. "libelium").
  • Message template: configure the message to send to scriptr.io (this depends on the measures sent by your sensors).
  • Log level: specify a log level.
  • Interval: specify a time in seconds between 2 synchronizations with your scriptr.io account. This value cannot be less than 30.

Using HTTP to send data

In the "Common" section, fill the following:

  • Server adddress: type "api.scriptrapps.io".
  • Protocol: choose "HTTP" (default value).

In the "HTTP" section, fill the following:

  • Auth token: enter the value of the authentication token that was generated by scriptr.io for your Meshlium device, as described in the "Create a device to authenticate the requests" section.

Using AMQP to send data

Note: if you have only signed-up to a free scriptr.io account don’t use AMQP.

In the "Common" section, fill the following:

  • Server address: type "amqp.scriptr.io".
  • Protocol: choose "AMQP".

In the "AMQP" section, fill the following:

Note: check next paragraph, “Obtaining AMQP configuration from scriptr.io”, for the values obtained from scriptr.io

  • User: paste the value of the "Username" field from scriptr.io.
  • Password: paste the value of the "Password" field from scriptr.io.
  • Virtual host: paste the value of the "Virtual host" field from scriptr.io.
  • Exchange: paste the value of the "Exchange" field from scriptr.io.
  • Routing key: paste the value of the "Routing key" field from scriptr.io.

Obtaining AMQP configuration 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:

  • Select "AMQP" as protocol.
  • In the "Credentials" section, select the device you have created in the “Create a device to authenticate the requests”.
  • In the "Publishing Details" section, select the channel you have created in “Create a channel in your scriptr.io account”.

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.

Figure : AMQP configuration from scriptr.io

In Meshlium Manager System, click the "Save" button for storing your configuration.

Controlling the synchronization

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).

Figure : scriptr.io cloud connector is stopped

You can stop the scriptr.io cloud connector anytime clicking on the "Stop" button.

Figure : scriptr.io cloud connector is running