LORIOT’s LoRaWAN Network Server offers the solution to build and operate private LoRaWAN networks. Manage and monitor your remote devices and gateways with an elaborate toolset, and route telemetry data securely to your Ubidots powered IoT cloud application.
IMPORTANT NOTE: This article assumes LoRaWAN Gateways and Devices have been already provisioned within the LORIOT instance and are sending data regularly.
Requirements
Ubidots Industrial account.
LORIOT Instance.
Gateway and devices connected to the LORIOT instance.
1. Integration Workflow
Connecting/upstreaming data from LORIOT to Ubidots is known as an HTTP Cloud-to-Cloud Integration. Those integrations often, if not always, require middle steps to ensure compatibility between the sender and receiving cloud data formats. In this case, LORIOT’s integration with Ubidots is not the exception as it requires a parsing step to convert LORIOT’s output JSON format into an Ubidots-compatible one. That parsing step is where Ubidots Functions as a Service (FaaS) module, UbiFunctions, comes into place to take LORIOT’s native JSON format and make it an Ubidots API compatible one.
The below image depicts this workflow:
2. Ubidots Setup: UbiFunctions
From the UbiFunctions module follow the below steps to create and launch the UbiFunction which will handle LORIOT’s native JSON format conversion into an Ubidots’ compatible one:
Step 1: Click the “+” button in the upper-right corner
Step 2: Name your UbiFunction. For example, “LORIOT Integration”
Step 3: Select POST as the Method
Step 4: Select NodeJS 10 as the default Runtime
NOTE: Leave the “Time-based trigger” option disabled
Step 5: Enter the below code in the Editor
const axios = require('axios');
const TOKEN = 'PUT-YOUR-TOKEN-HERE';
const BASE_URL = 'https://industrial.api.ubidots.com';
const APIV1 = '/api/v1.6';
async function main(args) {
console.log(`args: ${JSON.stringify(args)}`);
const {ts, EUI, data, port} = args;
var bytes = Buffer.from(data, 'hex');
const input = {
bytes: bytes,
fport: port
}
let payload = decoder(input);
let res;
await ubidotsPostData(TOKEN, EUI, payload, ts)
.then(response => {res = response.data})
.catch(err => {res = err});
return res;
}
function decoder(input) {
/*
Put your decoder here
Note that input should be a JSON with the form:
input = {
bytes: bytes, // Buffer of bytes
fport: port
}
*/
return {} // Should be an Ubidots compatible JSON
}
function ubidotsPostData(token, devLabel, body, timestamp) {
const url = `${BASE_URL}${APIV1}/devices/${devLabel}/?timestamp=${timestamp}`;
let config = {
method: 'post',
url: url,
data: body,
headers: {
'Content-Type': 'application/json',
'X-Auth-Token': token
}
}
return axios.request(config).then(response => response)
}
Step 6: Enter an Ubidots account token where asked (line 3)
Step 7: Input your specific decoder in the decoder
function on line 24
Step 7: Click on the “Make it live” button.
Step 8: Copy the “HTTPS Endpoint URL” by clicking the “Copy” icon and Save it for later.
3. LORIOT HTTP Uplink Integration
Having the UbiFunction setup is time to complete the integration to start forwarding data to Ubidots. To that, these steps will get you through this final process:
Step 1: Click “Applications” and select the one you’d like to start forwarding data from
Step 2: Select the Output option in the left panel and then “Add new output”
Step 3: Choose the HTTP Push option. Enter the following information
– Target URL for POSTs: HTTPS Endpoint URL saved from the last section
– Custom "Authorization" header value: leave blank
Step 4: Save the new output by clicking the "Add output" button
After completing this process, you’ll start seeing your LoRaWAN devices being created in your account and reporting data as it becomes available.