All Collections
Connect your Devices
Connect a Decentlab: DL-LP8P sensor over LoRaWAN to Ubidots
Connect a Decentlab: DL-LP8P sensor over LoRaWAN to Ubidots

Learn how to connect the DL-LP8P, a CO₂, Temperature, Humidity and Barometric Pressure Sensor to Ubidots.

Isabel Lopez avatar
Written by Isabel Lopez
Updated over a week ago

Decentlab provides a variety of wireless sensor devices for distributed, cost-effective monitoring solutions in applications areas such as environmental and air quality monitoring, hydrological measurements, smart agriculture, and smart cities.

The sensors devices communicate wirelessly over LoRaWAN and are ready to be deployed in any harsh indoor or outdoor environment, also being able to operate on batteries for several years thanks to their ultra-low power consumption design.

Following up, this article will guide you through the process of integrating your DL-LP8P (CO₂, Temperature, Humidity and Barometric Pressure Sensor) to Ubidots using The Things Network (TTN) as LoRaWAN Network server to integrate all the services. 

IMPORTANT NOTES: 

  1. Sensor Devices are compatible to LoRaWAN™ standard and are successfully operating within networks of various providers. Learn more.

  2. This guide can serve as a reference for the integration of any Decentlab device (DL-PR36CTD, DL-IAM, DL-PR26, DL-PR21, DL-MBX), the only change required is the decoder based on the device used. For this, check out the decoders provided by Decentlab and adapt it based on the Ubidots API Requirements.

Requirements

Step-by-Step

  1. TTN Device Registration

  2. Uplink messages management
    a. Custom payload setup
    b. Ubidots integration setup

  3. Data visualization / Dashboard Creation

  4. Summary

1. TTN Device registration

IMPORTANT NOTE: To start managing your Decentlab devices’ data with TTN as LoRaWAN network provider, please contact support@decentlab.com to set up the requirements.

This guide assumes your device is already connected and transmitting data to TTN successfully. However, below you can find brief information on how to register a new device in TTN.

1. Go to the TTN console and enter to the application section to add a new application. To create the application, just press “add application”:

Then, in the following page, assign the parameters below and press “Add application” to continue:

  • Application ID: The unique identifier of your application on the network.

  • Description (optional): a human readable description.

  • Handler registration: handler where you want to register the application. 

Once the application is created, you will be redirected to the application overview. 

2. To register a device, go to the device tab. Then press “Register Device

Then, in the following page, assign the parameters below:

  • Device ID: the unique identifier for the device in the application. The device ID will be immutable.

  • Device EUI: the unique identifier for the device on the network.

The rest of the parameters (App Key, and App EUI) are automatically assigned by TTN. Once the device’s registration its done, you will be redirected to the device overview. At this point, the device’s status is “never seen” because is waiting for its first message.

Once the device receives the first message, you will see how the device's status change, as well as the log of the data sent by the device.

 

2. Uplink messages management

To start sending data (uplink messages) to Ubidots, you need to establish some configurations in the TTN side. Please follow the steps below carefully to establish the proper communication between your device, TTN, and Ubidots. 

  • Custom Payload

1. Go to the Application overview, and refer to the “Payload Formats” tab. Then, assign the following code into the decoder section to format the payload in a JSON objects, which is the one allowed by Ubidots.

function Decoder(bytes, port) {
  return decentlab_decoder.decode(bytes);
}


/* https://www.decentlab.com/support */

var decentlab_decoder = {
  PROTOCOL_VERSION: 2,
  SENSORS: [
    {length: 2,
     values: [{name: 'Air-temperature',
               convert: function (x) { return 175.72 * x[0] / 65536 - 46.85; },
               unit: '°C'},
              {name: 'Air-humidity',
               convert: function (x) { return 125 * x[1] / 65536 - 6; },
               unit: '%'}]},
    {length: 2,
     values: [{name: 'Barometer-temperature',
               convert: function (x) { return (x[0] - 5000) / 100; },
               unit: '°C'},
              {name: 'Barometric-pressure',
               convert: function (x) { return x[1] * 2; },
               unit: 'Pa'}]},
    {length: 8,
     values: [{name: 'CO2-concentration',
               convert: function (x) { return x[0] - 32768; },
               unit: 'ppm'},
              {name: 'CO2-concentration-LPF',
               convert: function (x) { return x[1] - 32768; },
               unit: 'ppm'},
              {name: 'CC2-sensor-temperature',
               convert: function (x) { return (x[2] - 32768) / 100; },
               unit: '°C'},
              {name: 'Capacitor-voltage-1',
               convert: function (x) { return x[3] / 1000; },
               unit: 'V'},
              {name: 'Capacitor-voltage-2',
               convert: function (x) { return x[4] / 1000; },
               unit: 'V'},
              {name: 'CO2-sensor-status',
               convert: function (x) { return x[5]; }},
              {name: 'Raw-IR-reading',
               convert: function (x) { return x[6]; }},
              {name: 'Raw-IR-reading-LPF',
               convert: function (x) { return x[7]; }}]},
    {length: 1,
     values: [{name: 'Battery-voltage',
               convert: function (x) { return x[0] / 1000; },
               unit: 'V'}]}
  ],

  read_int: function (bytes) {
    return (bytes.shift() << 8) + bytes.shift();
  },

  decode: function (msg) {
    var bytes = msg;
    var i, j;
    if (typeof msg === 'string') {
      bytes = [];
      for (i = 0; i < msg.length; i += 2) {
        bytes.push(parseInt(msg.substring(i, i + 2), 16));
      }
    }

    var version = bytes.shift();
    if (version != this.PROTOCOL_VERSION) {
      return {error: "protocol version " + version + " doesn't match v2"};
    }

    var deviceId = this.read_int(bytes);
    var flags = this.read_int(bytes);
    var result = {'Protocol-version': version, 'Device-ID': deviceId};
    // decode payload
    for (i = 0; i < this.SENSORS.length; i++, flags >>= 1) {
      if ((flags & 1) !== 1)
        continue;

      var sensor = this.SENSORS[i];
      var x = [];
      // convert data to 16-bit integer array
      for (j = 0; j < sensor.length; j++) {
        x.push(this.read_int(bytes));
      }

      // decode sensor values
      for (j = 0; j < sensor.values.length; j++) {
        var value = sensor.values[j];
        if ('convert' in value) {
          result[value.name] = {value: value.convert(x)};
        }
      }
    }
    return result;
  }
};

IMPORTANT NOTE: If you are using a different device check out the decoders provided by Decentlab and adapt it based on the Ubidots API Requirements to start sending data.

2. [OPTIONAL] Once you have the decoder code defined in TTN, you can test the payload which is being sent from the device to verify if the decoded value is right.

Let’s say the value sent from the device is:

020578000F67BD618D1CEDBD10810D981F4895B0BD80BB500009598953900C25

Assign the same payload sent and the result should be in a JSON format payload:

3. To finish, press the “Save payload functions” button. At this point, if you refer to the data section you will notice how the data is being automatically decoded after saving the decoder function. 

  • Ubidots integration setup

  1. Go to the “Integration” tab to add a new integration. To create a new integration, just press “add integration”.

Then, select Ubidots as integration: 

In the next window, assign the following parameters: 

With all the parameters assigned, your integration should look like the one below:

To finish, press “Add integration”. You’ll be redirected to the integration overview:

At this point, once a new value is received in TTN from the device, a new device is going to be automatically created into your Ubidots account. 

  • Data verification

1. Go to the device section of your Ubidots account (Devices > Devices) to verify the new device created identified with the device EUI.

Select the device created to verify all the variables received:

2. [ OPTIONAL - PRO TIP]: If you are using multiple devices to transmit data, we recommend editing the device name, assigning a friendly and readable name for easier identification:

3. Data visualization

Now it’s time to build your own dashboard to start monitoring the data sensed by decentlab devices

1. Go to the Dashboard (Data > Dashboards) section of your Ubidots account.

2. Select the plus (+) icon located a the right-upper side of the page. Then select the widget types desired to display your data. Learn more about Ubidots’ Dashboards.

6. Summary

LPWAN applications are having a huge impact on the IoT ecosystem, even more if the integrations required have a rapid set-up, like we just did with Decentlab sensor devices and Ubidots. We aim to enable the management of “things” easier for the IoT community, empowering more IoT engineers to grow their deployments fast and reliably.

Other users also found helpful:

Did this answer your question?