IoT Hub
IoT Hub Documentation
Temperature upload over MQTT using Nettra RTU
Getting Started Documentation Guides API FAQ

On this page

Temperature upload over MQTT using Nettra RTU

Introduction

This guide contains step-by-step instructions on how to connect your Nettra RTU device to IoT Hub Community Edition through ethernet, using as sample, one of the many applications that the Nettra RTU has. In particular, this sample application will allow you to monitor temperature using IoT Hub web UI to display the data coming from the sensor.

Nettra RTU

Nettra RTU called “RTU+” is a powerful IoT electronic device that has digital and analog inputs and outputs, as well as several integrated communication interfaces as modem, ethernet, 802.15.4, RS485, RS232 and GPS. It is an ideal product to implement monitoring, acquisition and control applications over a distributed data network.

The RTU+ is easly configurable via a RTU+ Configuration Interface. To adapt the RTU+ to each application, it runs a fully customizable script, accessible and editable from the Configuration Interface. In this guide we will provide one as an example quite simple and easy to understand.

Once you complete this sample/tutorial, you will see your sensor data on a dashboard like the following on the right.

image image

Prerequisites

Hardware

  • 1x RTU+
  • 1x Temperature sensor (Operation range: 4-20mA or 0-20V)
  • 1x 12VDC supply voltage
  • 1x USB to Serial cable
  • 1x Ethernet cable

Software

Connection diagram

The following picture summarizes the connections for this simple project:

image

IoT Hub configuration

This step contains instructions that are necessary to connect your device to IoT Hub.

Sign up IoT Hub Web UI as live-demo. See Live Demo page for more details how to get your account.

Device

  1. Go to “Devices” section.
  2. Click ”+” button and create a device with the name “RTU+”. Set “Device type” to “default”.

    image

  3. Once device created, open its details and click “Manage credentials”.
  4. Copy auto-generated access token from the “Access token” field. Please save this device token. It will be referred to later as $RTU_DEMO_TOKEN.

    image

Dashboard

Download the dashboard file (.json) using this link. Use import/export instructions to import the dashboard to your IoT Hub instance.

Connect RTU+ to PC

  • Download and install last version of RTU+ Configuration Interface.

  • Once you have the RTU+ connected to the temperature sensor and the 12VDC power supply as shown in Connection Diagram section, connect the RTU+ to the PC using the USB-Serial cable (make sure you have all the necessary drivers installed for that).

  • Open the RTU+ Configuration Interface.

    1. Go to “Inicio”.
    2. Click “Serial”.
    3. Select the USB port “Puerto” you have connected the RTU+, “Baud rate”: “9600” (by default), and “Paridad”: “Sin paridad”.
    4. Click “Connect”.

    image

    Once you are connected you should see this icon :

    image

RTU+ configuration

Once you have your RTU+ connected to the PC, we can proceed with its configuration.

Ethernet

  1. Go to “Comunicaciones”.
  2. Click “Serial y Ethernet”.
  3. Tick the box “DHCP” as shown in next image.
  4. Save clicking “Aplicar cambios”.

    image

MQTT

  1. Go to “Comunicaciones”.
  2. Click “MQTT y Hora”.
  3. Fill the MQTT boxes as follow:

    Interfaz : Ethernet    Puerto : 1883
    Servidor : IoT Hub HOST/IP address that is accessible within your local network. Specify iothub.magenta.at if you are using live demo server.
    Usuario : $RTU_DEMO_TOKEN (provided in Device subsection)
    Contraseña : Leave empty
    Client ID : RTU+
    Telemetry Topic : v1/devices/me/telemetry
    Attributes Topic : v1/devices/me/attributes
    Formato : Telemetry+
  4. Fill the Time Synchronization boxes as follow:

    Interfaz : NTP Ethernet
    Servidor : IoT Hub HOST/IP address that is accessible within your local network. Specify iothub.magenta.at if you are using live demo server.
    Frecuencia : 10
    Huso : Write your time zone

  5. Click “Aplicar cambios” to save.

    image

    You should see in “Estado”: “Conectado” (MQTT status: Connected) (It could take some minutes the first time)

    image

Time

  1. Go to “Inicio”

  2. Click “Configurar Hora”.

    image

Analog input

  1. Go to “Escalado de Entradas Analógicas”.

  2. Here we have two possibles configurations, depending on your temperature sensor.

    If your temperature sensor output range is between 4-20mA :
    Select “Corriente” in “Entrada Analógica 0: “. Fill “X0” with “819” and “X1” with “4096”. Fill “Y0” with minimum sensor temperature and “Y1” with maximum sensor temperature.
    Example: Sensor Range: -10°C to 100°C. “X0” = 819, “Y0” = -10, “X1” = 4096 and “Y1” = 100

    image

    If your temperature sensor output range is between 0-20V :
    Select “Tensión” in “Entrada Analógica 0: “. Fill “X0” with “0” and “X1” with “4096”. Fill “Y0” with minimum sensor temperature and “Y1” with maximum sensor temperature.
    Example: Sensor Range: -10°C to 100°C. “X0” = 0, “Y0” = -10, “X1” = 4096 and “Y1” = 100

    image

  3. Click “Aplicar cambios” to save.

Script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * DESCRIPTION :
 * - Monitor temperature each 20 seconds.
 * 
 * INPUTS:
 * - Temperature sensor : Analog Input 0 
 */

// Constants
const TLOG = 20000;  // [Miliseconds]
 
// Variables definition
loggable float temperature;   // [ºC]
ulong logTimer;
<span style="color: green"> Some green text </span>
// Alias
alias sensorTemperature as AInEscalado[0];

// Variables initialization
logTimer = ConfigurarTimeout(0); 

// Code
while(1)
{
   if (Timeout(logTimer))
   {
      logTimer = ConfigurarTimeout(TLOG);
      temperature = sensorTemperature;
      Log(temperature);
   }
}
  1. Go to “Nettra-C”
  2. Import the script clicking “Cargar”. If you want to make your own script, you can see the Nettra C user manual.

    image

  3. Compile and save the script in the RTU+ by clicking “Compilar y Aplicar”.

    image

Data visualization

Finally, open IoT Hub Web UI in the Live Demo server with same user and password as IoT Hub configuration section.

Go to “Devices” section and locate “RTU+ Device”, open device details and switch to “Latest telemetry” tab. If all is configured correctly you should be able to see latest values of “temperature” in the table.

image

After, open “Dashboards” section then locate and open “RTU+” dashboard. As a result, you will see a time-series chart displaying temperature level (similar to dashboard image in the introduction).

image

See also

Browse other samples or explore guides related to main IoT Hub features:

Next steps

  • Getting started guides - These guides provide quick overview of main IoT Hub features. Designed to be completed in 15-30 minutes.