ALTA products are a leading enterprise-grade remote monitoring and control solution for businesses and institutions. Some highlights of ALTA products include the 900 MHz products which use a frequency-hopping spread spectrum (FHSS), and the ALTA 868 and 433 MHz products which are frequency-agile, providing better RF interference immunity to be used in the most demanding environments.

One of  Monnit’s flagship features is their new Encrypt-RF™ bank level security, featuring a 256-bit exchange to establish a global unique key, and an AES-128 CTR for all data messages. These features help maintain security from sensor to gateway, gateway to cloud, and back again.

In this tutorial, we will to demostrate how to integrate Monnit’s ALTA Ethernet Gateway with Ubidots, using UbiFunction.

Requirements

  • Ethernet connection with Internet access
  • ALTA Monnit Ethernet Gateway
  • ALTA Monnit sensors (in this example, we’ll use Temperature, Humidity and 0-5 voltage meter)
  • Mini USB to USB cable
  • 2 X AA batteries
  • A Ubidots account with the UbiFunctions add-on enabled

Setting up Monnit

ALTA Monnit Gateway/Sensors Setup

    1. To get started, log into your premium iMonnit account. If you don’t have one, you can create a new one here if you do not have one.

    2. Add the gateway to the account. For this, use the “ID” and “SC” fields printed on the device.

    3. Once the gateway is added, it’s time to register the sensor devices. For this, use the “ID” and “SC” fields printed on the device.

Give a name to the sensor, select and complete "how the sensor is to be used," and click continue.

Gateway Setup

    4. Now, let's configure the ALTA Monnit Ethernet Gateway:

  • Connect an Ethernet cable to the gateway (make sure it has Internet access) then turn on the gateway and wait for the 3 front-facing LEDs to display as green backlight. In case this does not happen, this troubleshooting guide can help.
  • Go to the iMonnit platform and check if the gateway is sending messages to iMonnit’s platform by looking at the message history:

    5. Insert batteries to any of the sensor devices and check if the platform confirms the sensor is connected.

Creating an iMonnit Webhook to send data to Ubidots

At this moment we can be sure data is being received at iMonnit's hardware platform. Now we need to connect iMonnit to Ubidots to develop our control and/or monitoring App to extract value from the iMonnit sensors. 

6. To connect both platforms we will use the iMonnit’s Webhook tool. Go to the Username drop-down, then click in “Back to Classic View” option.

7. In the upper-right, click the "sprocket" icon, and then “API/Webhook”. Under the Webhook tab you can find gateway and sensor parameters, then click on “Configure Webhook”.

8. The Webhook tool allows sending data continuously or only when a sensor message arrives, this is up to you. In our case, we’ll select the option “Always”.

9. In the steps below, we'll learn how to create an UbiFunction URL to receive data from iMonnit.

Ubidots Setup

Creating an UbiFunction to receive data from iMonnit in Ubidots

A function is a Node.js cloud function triggered when a GET or POST HTTPS request is made to the Function's Endpoint URL. Effectively we are building a URL Endpoint or API in a single sub-system of Ubidots.

10. In your Ubidots account, go to the “Data” drop-down and select “Functions”, and create a new function using the blue "+" icon in the top-right corner.

Note: In case you don’t have an Ubidots account, you can create one here.

11. In your newly created Function, add a name and select the POST method

12. To make your Function public and accessible, click “Make it live”.

13. Now let's code the parsing functions using Node.js. By default, the function receives “params” as a JSON content-type dictionary. iMonnit’s platform sends data out as a JSON content-type dictionary, as the image below. Note that ‘gatewayMessage’ and ‘sensorMessages’ correspond to gateway and sensor data, respectively:

You can learn more about iMonnit’s message structure in their documentation

Use the following sample code to parse the Gateway’s message and sensor’s messages (name, message's date, Signal, Data and Battery) to then make a POST request to the Ubidots cloud and get the data from the Monnit hardware cloud to the Ubidots software cloud. 

Copy and paste the sample code below into your function; modifying as you see fit:

var request = require('request-promise');
var ubidotsToken = "YOUR-UBIDOTS-TOKEN";

//Make POST request to Ubidots
async function ubidotsPostRequest(deviceLabel, data) {
    var options = {
        method: 'POST',
        url: 'https://industrial.api.ubidots.com/api/v1.6/devices/' + deviceLabel,
        body: data,
        json: true,
        headers: {
            'Content-Type': 'application/json',
            'X-Auth-Token': ubidotsToken
        }
    };

    return await request.post(options);

}
async function main(params) {

    // Gateway's name, message's date, Signal, Battery is obtained and sended,calling ubidotsPostRequest function.
    var payloadGateway = params.gatewayMessage;
    var gate_Time = new Date(payloadGateway.date);
    var gate_Time = Date.parse(gate_Time);
    var args = {
        "Signal": [{ "value": payloadGateway.signalStrength, "timestamp": gate_Time }],
        "Battery": [{ "value": payloadGateway.batteryLevel, "timestamp": gate_Time }]
    };
    var device_label = "Gateway" + payloadGateway.gatewayID;
    var U_post = await ubidotsPostRequest(device_label, args);

    // Sensor's name, message's date, Data, Signal, Battery is obtained and sent, calling ubidotsPostRequest function.
    if(params.sensorMessages) {
        var payloadSensor = params.sensorMessages[0];
        var sensorTime = new Date(payloadSensor.messageDate);
        var sensorTime = Date.parse(sensorTime);
        var args = {
            "Data": [{ "value": payloadSensor.dataValue, "timestamp": gate_Time }],
            "Battery": [{ "value": payloadSensor.batteryLevel, "timestamp": gate_Time }],
            "Signal": [{ "value": payloadSensor.signalStrength, "timestamp": gate_Time }]
        };
        device_label = payloadSensor.dataType + "-" + payloadSensor.sensorID;
        var U_post = await ubidotsPostRequest(device_label, args);

    }
    console.log(args)
    return {U_post}
}


14. (Optional) To test the code, click on “Run function”. A pop-up window will appear, where you can enter sample data in the same format that would be sent out by iMonnit’s.

15. Click “Run with this input” to complete the function. 

A console window will appear with the results. The below states the expected output when things are functioning properly - status_code 201 :

The “status_code” : 201 output is the response from the Ubidots servers to your function, meaning data was successfully received. To learn more about Ubidots’ status codes, see our documentation.

Connect iMonnit and Ubidots

Finally, copy the Ubidots function URL and paste it into iMonnit’s webhook configuration screen as the “Base URL (required)”, then click Save.

Ubidots Function URL:

iMonnit's Webhook configuration:

We’re now ready to receive data from iMonnit inside an UbiFunction.

Results

As data starts flowing in from the ALTA-Monnit devices to iMonnit, a webhook will be triggered forwarding all data to Ubidots' function - with all data appearing as variables within the Device in Ubidots. 

In less an hour we were able to integrate Monnit’s Alta devices with Ubidots to power your IoT solution with Ubidots data visualization, alerts, and customizable end-user data experience. 

Need help coding your function? Feel free to reach out to Ubidots via the in-app chat channel or email at support@ubidots.com to learn more.

Want to share a helpful function to teach others how to connect the dots to build an data driven solution? Post your project at community.ubidots.com and help others achieve their IoT goals. 

Did this answer your question?