Ursalink UC1122 is designed as a cost-effective industrial machine monitoring device that controls up to 1 DC signal, 1 derivable relay output and 2 analog inputs. UC1122 supports standard LoRaWAN class C protocol, which is perfectly used as a remote data logger or a remote I/O controller. Coupled with Ursalink UG85/UG87 LoRaWAN gateway, UC1122 enables users to build up a LoRa-Based IoT solution for data collection, remote control and monitoring of field devices

This guide is intended to provide detailed explanation on how to integrate your UC1122 (LoRaWAN Datalogger) to Ubidots using The Things Network (TTN) as LoRaWAN Network server to integrate all the services.

Requirements

Step by Step

1. TTN Device Registration
2. Uplink message management
     a. Custom payload setup
     b. Ubidots integration setup
3. Data visualization / Dashboard Creation

1. TTN Device Registration

1. Go to the TTN console and enter to the Gateway section to add a new LoRaWAN gateway. 

Refer to the following guide for detailed information:

2. Enter the Application section to add a new application. To create the application, click “add application”, 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.

3. Into the application previously created register a new device. To do this, refer to the Device tab of the application. Then click “Register Device” to register an UC1122.

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 registration is 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.

2. Uplink Messages Management

a. Custom Payload

  1. Go to Application overview, and then to the “Payload Formats” tab. Paste the following code into the decoder section to format the payload into a JSON object, which is compatible with Ubidots API.
//UC1122 Decoder
function Decoder(bytes, port) {
    var decoded = {};

    for (i = 0; i < bytes.length;) {
        // GPIO INPUT 1
        if (bytes[i] == 0x01) {
            decoded.din1 = bytes[i + 2] === 0 ? "0" : "1";
            i += 3;
            continue;
        }

        // GPIO INPUT 2
        if (bytes[i] == 0x02) {
            decoded.din2 = bytes[i + 2] === 0 ? "0" : "1";
            i += 3;
            continue;
        }

        // GPIO OUTPUT 1
        if (bytes[i] == 0x09) {
            decoded.dout1 = bytes[i + 2] === 0 ? "0" : "1";
            i += 3;
            continue;
        }

        // GPIO OUTPUT 2
        if (bytes[i] == 0x0a) {
            decoded.dout2 = bytes[i + 2] === 0 ? "0" : "1";
            i += 3;
            continue;
        }

        // ADC OUTPUT 1
        if (bytes[i] == 0x11) {
            decoded.ain1_cur = readInt16LE(bytes.slice(i + 2, i + 4)) / 100;
            decoded.ain1_min = readInt16LE(bytes.slice(i + 4, i + 6)) / 100;
            decoded.ain1_max = readInt16LE(bytes.slice(i + 6, i + 8)) / 100;
            decoded.ain1_avg = readInt16LE(bytes.slice(i + 8, i + 10)) / 100;
            i += 10;
            continue;
        }

        // ADC OUTPUT 2
        if (bytes[i] == 0x12) {
            decoded.ain2_cur = readInt16LE(bytes.slice(i + 2, i + 4)) / 100;
            decoded.ain2_min = readInt16LE(bytes.slice(i + 4, i + 6)) / 100;
            decoded.ain2_max = readInt16LE(bytes.slice(i + 6, i + 8)) / 100;
            decoded.ain2_avg = readInt16LE(bytes.slice(i + 8, i + 10)) / 100;
            i += 10;
            continue;
        }

    }

    return decoded;
}


/* ******************************************
* bytes to number
********************************************/
function readUInt8LE(bytes) {
    return (bytes & 0xFF);
}

function readInt8LE(bytes) {
    var ref = readUInt8LE(bytes);
    return (ref > 0x7F) ? ref - 0x100 : ref;
}

function readUInt16LE(bytes) {
    var value = (bytes[1] << 8) + bytes[0];
    return (value & 0xFFFF);
}

function readInt16LE(bytes) {
    var ref = readUInt16LE(bytes);
    return (ref > 0x7FFF) ? ref - 0x10000 : ref;
}

function readUInt32LE(bytes) {
    var value = (bytes[3] << 24) + (bytes[2] << 16) + (bytes[1] << 8) + bytes[0];
    return (value & 0xFFFFFFFF);
}

function readInt32LE(bytes) {
    var ref = readUInt32LE(bytes);
    return (ref > 0x7FFFFFFF) ? ref - 0x100000000 : ref;
}

function readFloatLE(bytes) {
    // JavaScript bitwise operators yield a 32 bits integer, not a float.
    // Assume LSB (least significant byte first).
    var bits = bytes[3] << 24 | bytes[2] << 16 | bytes[1] << 8 | bytes[0];
    var sign = (bits >>> 31 === 0) ? 1.0 : -1.0;
    var e = bits >>> 23 & 0xff;
    var m = (e === 0) ? (bits & 0x7fffff) << 1 : (bits & 0x7fffff) | 0x800000;
    var f = sign * m * Math.pow(2, e - 150);
    return f;
}

2. After placing the code, fill in the Payload and click “test” to show the JSON output.

Example:
 12 02 90 01 90 01 90 01 90 01

Finally, save the changes by clicking on “Save Payload Functions”.

3. Go to “Data” tab, the decoded humidity and temperature data will be displayed in the TTN.

Ubidots Integration Setup

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

2. Then, select Ubidots as integration:

3. In the next window, assign the following parameters: 

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

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

5. Once a new value is received in TTN from the device, a new device will be automatically created into your Ubidots account. Go to the device section of your Ubidots account (Devices > Devices) to verify the new device created identified with the device EUI.

6. Select the device created to verify all the variables received:

3. Data visualization

Now it’s time to build your own dashboard to start monitoring the data from your Ursalink devices.

1.Go to the Dashboard (Data -> Dashboard) 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.

Other users also found helpful:


Did this answer your question?