TTVC Workshop

Controlling room climate with TTN and The ThingsBoard

A step-by-step tutorial

Agenda

Part I

What’s its ability? For what can it be used? 

PART II

Registration and Configuration of the device in TTN

PART III

A general introduction to ThingsBoard and an explanation of the integration between TTN and the ThingsBoard

Part IV

Explanation of the concept and an introduction to your first own dashboard

Things needed

Getting started!

I. Explanation of the device ERS Lite

  • Temperature 0 to 40 °C 

 

  • LoRaWAN® 1.0.3

 

  • Expected Battery Life up to 10 years (Depending on configuration and environment)
  • Humidity 0 to 85 % RH (non-condensing)

 

  • Accuracy +- 2%

 

  • Configurable via NFC and downlink configuration

II. TTN Registration of the device​

  1. Create a new application:
    • Go to Applications and press add application 
      • Enter an Application ID. The Application ID is the unique name of your application
      • AppEUI can be left as it is 
      • Handler registration must match your region (for EU = ttn-handler-eu)  
      • Press Save
    • You will find yourself in the overview page of your application
  2.  Register a new device:
    • Go to devices and press “add device” 
      • Enter a Device ID (Device ID is the unique name of the Device within the application) 
      • Enter DEVEUI: Do you wonder where to find it?
        •  On the back/front of your device
        • Or in the app: Open app “Sensor Settings”, choose the right sensor (ERS Lite) and hold the mobile phone on the device 
      • Simply leave the AppKey and AppEUI 
      • Press Save
    • Your device is now registered, but the device itself don’t know where to send the data
  3. Configuration of the device via Smartphone/NFC:
    • Open the app “Sensor Settings” while NFC is on  
      • Choose the right sensor type (ERS Lite) and hold the smartphone on the front of the device 
      • It will update the screen with the current configurations of the device
      • Switch on “Sensor Keys” 
      • Enter AppKey and APPEUI and transfer to device via the “write” button
    • Now your device knows where to send the data
    • You see the data in the menu under “Data”. As it’s in hexadecimal we need a decoder to make it human-readable…

II. Payload decoding

  1. What is a payload? What is a payload decoder? 
    • Payload = user data which are coded differently depending on the end device and sent via LoRaWAN 
    • Payload Decoder = on the server side, converts payload to human readable data 
  2. Find the right decoder:
  3. Paste the code in your application:
    • Go back to your application overview
    • In the menu, go to “Payload Formats”
    • Make sure you’re in the “decoder” field
    • Paste the code 
    • Scroll to the bottom of the page and press “Save payload functions”
    •  Go back to “Data” and you will see some human-readable data

Let’s switch to the ThingsBoard!

III. ThingsBoard Integration

  1. What is the ThingsBoard? For what can you use it? 
    • Open Source IoT Platform   
    • Different License Models:
      • Community Edition (free)
      • Professional Edition (starts with 10$/month, there is a trial account available here) –> WE NEED THIS VERSION!
    • Manage Users, Devices and Assets
    • Collect, analyze and visualize data 
  2. For the integration we first need an uplink and a downlink converter:
    • Go to “Data Converter” and create a new Data Converter:
      • Name: ttn_uplink_converter  
      • Type: Uplink  
      • Activate Debug Mode  
      • Copy and paste code (you find the code below this chapter) 
      • press save
    • create another Data Converter as a downlink converter:
      • Name: ttn_downlink_converter  
      •  Type: Downlink  
      • Activate Debug Mode 
      • Copy and paste code (you find the code below this chapter) 
      • Press save
  3. Now we can build the integration:
    •  Go to “Integration” and create a new integration:
      • Name: ttn_integration  
      • Type: TheThingsNetwork   
      • Uplink data converter: ttn_uplink_converter  
      • Downlink data converter:ttn_downlink_converter
      • Region (region where your application was registered inside TTN)eu 
      • Application ID: use the Application ID from TTN  
      • Access Key: use the Access Key from TTN
      • Press save
    • Check if your device was created:
      • Go to “Devices”
      • You should see your device (maybe you have to wait a few minutes until the next data has been sent)
      • If not, create a new device (the device name must match the Device ID in TNN and the type must match with your Application ID in TTN)
    • Now the integration works and the data comes from TTN over the integration to the device in ThingsBoard

Uplink Converter

// Uplink Converter

var data = decodeToJson(payload);
var deviceName = data.dev_id;
var deviceType = data.app_id;

var result = {
      deviceName: deviceName,
      deviceType: deviceType,
      telemetry: {
             temperature: data.payload_fields.temperature,
             humidity: data.payload_fields.humidity
             }
      };

function decodeToString(payload) {
      return String.fromCharCode.apply(String, payload);
      }

function decodeToJson(payload) {
      var str = decodeToString(payload);
      var data = JSON.parse(str);
      return data;
      }

return result;

Downlink Converter

// Downlink Converter
var data = {
      port: 1,
      confirmed: false,
      payload_fields: {
            version: msg.version
            }
      };

var result = {
      contentType: “JSON”,
      data: JSON.stringify(data),
      metadata: {
             devId: “ers_lite” //change this to your own device ID in TTN
            }
      };

return result;

IV. Building your own Dashboard​

  1. Create a new dashboard:
    • Go to “Dashboard Groups” and click on “All”
    • If you want to, you can use our template
      • For that, just download the template here
      • Then import it to ThingsBoard
    • If not, just add a new dashboard
  2. Create an alias for the device:
    •  Open your dashbaord and enter the edit mode (press the pencil on the right bottom of the screen)
    •  Click on “Entity aliases” in the right menu
    • Create a new alias:
      • Click “Add Alias”
      • Name: Roomsensors
      • Filter Type: Single Entity
      • Type: Device
      • Device: ers_lite (Device name in ThingsBoard)
      • Press “Add”
      • Press”Save”
    • Press “Apply Changes” on the right bottom of the screen
  3. Add the widgets:
    • Enter the edit mode
    • Press “Add new Widget” and then “Create new widget”
      • You find yourself in the Widget-Selection-Menu: Here you can choose between different bundles of widgets
      • For this workshop we take the “Timeseries – Flot” widget of the “Charts”-bundle. Just click on it
      • Click on “Add” for adding a data source
      • Enter your alias name in “Entity alias” and in the next field the two timeseries variables “humidity” and “temperature”
      • Switch to “Settings” in the menu
    • In “Title” type in a comprehensible title, e.g. “Temperature & Humiditycurve”
    • Press “Add”
    • Press “Apply Changes” on the right bottom of the screen
    • Repeat the process for the current temperature using the “temperature gauge” widget of the “analogue gauges” bundle and the current humidity using the “New Gauge – justGage” widget of the “digital gauges” bundle

That's it. You created your first LoRaWAN application!

Any Questions?

Leave a Reply

Your email address will not be published.