Getting Started
Introduction
The goal of this tutorial is to demonstrate the basic usage of the most popular NDU features.
You will learn how to:
- Provision Assets and Devices in the system;
- Define relations between Assets and Devices;
- Push data from a device to NDU;
- Build real-time end-user Dashboards;
- Define thresholds and trigger alarms;
- Push notification about new alarms over email.
The tutorial is based on a popular facility monitoring use-case.
We will show how to monitor temperature in a different parts of the building,
raise alarms when temperature exceeds certain threshold and visualize collected data and alarms.
Video tutorial
We recommend you to review the following video tutorial.
All the resources used in this tutorial are listed below for your convenience.
Tutorial resources
Pushing data from the device
In order to simplify this guide, we will push data using HTTP, MQTT or CoAP protocol from your local PC.
Please review connect your device guides for all available connectivity solutions and options and
hardware samples to learn how to connect various hardware platforms to NDU.
Client-side libraries installation
Install preferred HTTP (cURL), MQTT (Mosquitto or MQTT.js) or CoAP (CoAP.js) client using following commands.
resources/curl-win.sh  |
1
2
3
| NOTE: Starting Windows 10 b17063, cURL is available by default.
More info here: https://blogs.msdn.microsoft.com/commandline/2018/01/18/tar-and-curl-come-to-windows/
If you are using older version of Windows OS, you may find official installation guides here: https://curl.haxx.se/
|
|
resources/node-mqtt.sh  |
1
2
| # Assuming you have Node.js and NPM installed on your Windows/Linux/MacOS machine
npm install mqtt -g
|
|
Sample cURL command used in the video tutorial
This command works for Windows, Ubuntu and macOS, assuming that cURL tool is installed.
1
2
3
4
5
| # Please replace $ACCESS_TOKEN with corresponding values.
# For example, $HOST_NAME in case of live demo server:
curl -v -X POST -d "{\"temperature\": 25}" https://smartapp.netcad.com/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"
|
Sample generator script
1
2
3
4
5
| var msg = { temperature: +(Math.random()*5 + 25).toFixed(1)};
var metadata = {};
var msgType = "POST_TELEMETRY_REQUEST";
return { msg: msg, metadata: metadata, msgType: msgType };
|
Rule Engine guides
Rule Engine overview - learn the Rule Engine basics and architecture.
Rule Engine guides - learn how to use NDU Rule Engine.
Mail settings
Use this guide to configure SendGrid or use any other SMTP server available.
Other sample data files
Create some folder to store all necessary files for this tutorial.
Download to this folder or create the following data files:
Please note that data in this files is basically in key-value format. You can use your own keys and values.
See MQTT, CoAP
or HTTP protocol reference for more details.
Pushing data using MQTT, CoAP or HTTP
Download the following files to previously created folder according to the preferred client:
- MQTT.js (MQTT)
- Mosquitto (MQTT)
- CoAP.js (CoAP)
- cURL (HTTP)
If you are using a shell script (*.sh) make sure that it is executable:
Before executing script don’t forget to:
- replace $ACCESS_TOKEN with one from Device credentials window.
- replace $THINGSBOARD_HOST with either 127.0.0.1 (in case of local installation) or smartapp.netcad.com (in case of live-demo).
Finally, execute corresponding *.sh or *.bat script to push data to the server.
Below are tabs with the content of the scripts provided.
resources/mqtt-js.sh  |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
| #!/bin/sh
# Set NDU host to "smartapp.netcad.com" or "localhost"
export THINGSBOARD_HOST=smartapp.netcad.com
# Replace YOUR_ACCESS_TOKEN with one from Device details panel.
export ACCESS_TOKEN=YOUR_ACCESS_TOKEN
# Read serial number and firmware version attributes
ATTRIBUTES=$( cat attributes-data.json )
export ATTRIBUTES
# Read timeseries data as an object without timestamp (server-side timestamp will be used)
TELEMETRY=$( cat telemetry-data.json )
export TELEMETRY
# publish attributes and telemetry data via mqtt client
node publish.js
|
|
resources/mqtt-js.bat  |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| @echo off
REM Set NDU host to "smartapp.netcad.com" or "localhost"
set THINGSBOARD_HOST=smartapp.netcad.com
REM Replace YOUR_ACCESS_TOKEN with one from Device details panel.
set ACCESS_TOKEN=YOUR_ACCESS_TOKEN
REM Read serial number and firmware version attributes
set /p ATTRIBUTES=<attributes-data.json
REM Read timeseries data as an object without timestamp (server-side timestamp will be used)
set /p TELEMETRY=<telemetry-data.json
REM publish attributes and telemetry data via mqtt client
node publish.js
|
|
resources/publish.js  |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| var mqtt = require('mqtt');
console.log('Connecting to: %s using access token: %s', process.env.THINGSBOARD_HOST, process.env.ACCESS_TOKEN);
var client = mqtt.connect('mqtt://'+ process.env.THINGSBOARD_HOST,{
username: process.env.ACCESS_TOKEN
});
client.on('connect', function () {
console.log('Client connected!');
client.publish('v1/devices/me/attributes', process.env.ATTRIBUTES);
console.log('Attributes published!');
client.publish('v1/devices/me/telemetry', process.env.TELEMETRY);
console.log('Telemetry published!');
client.end();
});
|
|
resources/mosquitto.sh  |
1
2
3
4
5
6
7
8
9
10
| #!/bin/sh
# Set NDU host to "smartapp.netcad.com" or "localhost"
THINGSBOARD_HOST="smartapp.netcad.com"
# Replace YOUR_ACCESS_TOKEN with one from Device details panel.
ACCESS_TOKEN="YOUR_ACCESS_TOKEN"
# Publish serial number and firmware version attributes
mosquitto_pub -d -h "$THINGSBOARD_HOST" -t "v1/devices/me/attributes" -u "$ACCESS_TOKEN" -f "attributes-data.json"
# Publish timeseries data as an object without timestamp (server-side timestamp will be used)
mosquitto_pub -d -h "$THINGSBOARD_HOST" -t "v1/devices/me/telemetry" -u "$ACCESS_TOKEN" -f "telemetry-data.json"
|
|
resources/coap-js.sh  |
1
2
3
4
| # Publish serial number and firmware version attributes
cat attributes-data.json | coap post coap://$THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/attributes
# Publish timeseries data as an object without timestamp (server-side timestamp will be used)
cat telemetry-data.json | coap post coap://$THINGSBOARD_HOST/api/v1/$ACCESS_TOKEN/telemetry
|
|
resources/curl.sh  |
1
2
3
4
5
6
| # Publish serial number and firmware version attributes
# replace $THINGSBOARD_PORT with 8080 (in case of local installation) or 80 (in case of live-demo).
curl -v -X POST -d @attributes-data.json http://$THINGSBOARD_HOST:$THINGSBOARD_PORT/api/v1/$ACCESS_TOKEN/attributes --header "Content-Type:application/json"
# Publish timeseries data as an object without timestamp (server-side timestamp will be used)
# replace $THINGSBOARD_PORT with 8080 (in case of local installation) or 80 (in case of live-demo).
curl -v -X POST -d @telemetry-data.json http://$THINGSBOARD_HOST:$THINGSBOARD_PORT/api/v1/$ACCESS_TOKEN/telemetry --header "Content-Type:application/json"
|
|
Next steps