Skip to main content
All CollectionsConnect your Devices
Integrate Ubidots + vNode to send data through HTTP
Integrate Ubidots + vNode to send data through HTTP

This article explains how to integrate vNode with Ubidots through HTTPS protocol.

Alejandro Mora Chica avatar
Written by Alejandro Mora Chica
Updated over 3 months ago

This article will be useful for sending data to Ubidots via vNode through HTTPS protocol.

Requirements

1. Creating a RestApiClient Instance Module

Once vNode is running on your computer, you have to create a RestApiClient module:

  • Open vNode and head to “Config” in the navigation bar.

  • Click on “Modules” in the "Explorer" bar and create a new RestApiClient module.

Where:

  • Pause links while unavailable: This option pauses data reception from other vNode while the module is offline.

  • Start: Controls the module’s behavior when vNode services start, including a restart option.

    • Enabled: Starts automatically when the vNode services start.

    • Start delay: Controls the delay in starting.

2. Create a Tag

To send data to Ubidots, it's important to have a tag. With this tag we generate a variable that contains the value, the timestamp, and the context that will be sent to Ubidots.

You can create as many tags as variables you want to send to Ubidots. In this case, to better organize them, we created a group of tags called HTTP.

To create the tags, click on "Tags":

  • Navigate to “Config” in the navigation bar.

  • Click on “Tags” in the "Explorer" bar and create a new group.

  • Right-click on the group you have created and create a new tag.

After creating the tag, enable the simulation selecting “Yes” in the box, and configure with the following information:

  • Source: Provides the tag’s value, quality and timestamp.

    • Enabled: Yes (provides the tag’s value, quality and timestamp).

    • Module type: RestApiClient. Module used to obtain the tag’s information.

    • Module name: HTTP (the name of the module used to obtain the tag’s information).

Note: You can modify the name of the group, the tag’s name and the scaling of the values as you prefer.

3. Channel and Request configuration

After creating the RestApiClient module, it's necessary to create the connection to a REST endpoint, which in this case is known as "channel".

  • Click on "HTTP Module", in the "Explorer" bar, and then create a “New Channel” in the model window.

To configure the channel to connect with Ubidots, it's necessary to modify the following information:

  • Connection: To make you request, you can base it on the following table

For more information about making a request with HTTP/HTTPS protocol to Ubidots, please refer to this article.

  • Requests: Represent the REST request that is sent to the server. In this instance, you have to create a new request with the following information:

  • Method: POST to execute a REST POST request.

  • Triggers: The rate of the execution. Guarantees that the request will execute after this rate has passed.

    • Scan rate: 30000 miliseconds

    • Type: Fixed time

    • Reschedule timer: No

  • Parameters: The list of parameters that will be available to all scripts in the request. In this case, we use the tag created in the 2nd step (the name of the variable created in Ubidots will take the name of the parameter we set up).

  • Path: The remaining portion of the URL that specifies the resource you want to consume

    • Type: Plain text

    • Text: /api/v1.6/devices/<replace with the device where you want to send the data to>/

  • Headers: Define the operating parameters of the HTTP request.

    • Custom Headers

      • Content-Type

        • Type: Raw text

        • Value: application/json

      • X-Auth-Token:

        • Raw text

        • TOKEN of your Ubidots account.

  • Body: The body is the data sent to the server.

    • Body format:

      • Serialization: JSON

      • Encoding: UFT8

    • Body Serializer:

      • Type: Custom

      • Options:

        • Script: <javascript> Is the format in which Ubidots receives data.

          Note: To modify the default JavaScript code, click on the "</>" symbol and paste the following code:

    $.logger.info("Parsing message: %j", $.parameter);
    const value = $.parameter.Current.value;
    const timestamp = $.parameter.Current.ts;
    const quality = $.parameter.Current.quality;
    // Construye la respuesta con la estructura deseada
    const response = {
    [Object.keys($.parameter)[0]]: {
    value: value,
    timestamp: timestamp,
    context: {
    quality: quality
    }
    }
    };

    $.logger.info("Response: %j", response);
    $.output = response;
  • Response format: Decode the message

    • Encoding: UFT8

    • Serialization: Text

  • Response parser:

    • Type: Custom

    • Options:

      • Script: <javascript>

        Note: To modify the default JavaScript code, click on the "</>" symbol and paste the following code:

    $.logger.info("Parsing message: %j", $.parameter);
    const value = $.parameter.Current.value;
    const timestamp = $.parameter.Current.ts;
    const quality = $.parameter.Current.quality;
    // Construye la respuesta con la estructura deseada
    const response = {
    [Object.keys($.parameter)[0]]: {
    value: value,
    timestamp: timestamp,
    context: {
    quality: quality
    }
    }
    };

    $.logger.info("Response: %j", response);
    $.output = response;

4. Check if the module is working

Once you have saved all the configuration changes, we will check that the module is running. Follow these steps:

Go to "System" in the "Navigation" bar and click on “Diagnostics”.

  • Then click on “Modules” and check if the HTTP module is running.

After confirming that HTTP module is running, proceed with the following steps:

  • Go to “Real time logs” in the "Explorer" bar.

  • Activate the checkbox of “Enabled”.

  • Select the TRACE level and the HTTP module to check the communication with Ubidots. Here you can see the information sent to Ubidots.

The variable that has been created on the device you selected in the third step on your Ubidots account will now be displayed as follows:

Did this answer your question?