Example of NetPing Devices Integration with the Service thethings.io

  • Published In: Tutorial
  • Created Date: 2015-11-15
  • Hits: 1016

The service thethings.io offers a full range of solutions for the market of Internet of Things (hereinafter IoT) (Internet of things concept), as well as a simple and flexible API for the developers of IoT applications. This service is not related to any certain hardware platform and can be integrated with almost any device if it supports one of the next protocols: HTTP, Websockets, MQTT or CoAP. More detailed information on the issue can be learnt at this page of the project.

One of the interesting peculiarities of using thething.io is a possibility to execute a certain external logic at the service side. There is also a possibility to run own JavaScript code in the cloud thething.io using a special cloud API.

There are three types of executed cloud code: triggers, tasks and functions. Triggers are executed when, for example, an event, received from the sensor, reaches a certain value. The tasks are fulfilled once per hour or once a day. Functions are code fragments, which can be executed by calling REST API. Details can be found on this link.

The service offers a dashboard panel for monitoring and management, which provides a possibility to control all products and applications of IoT in one place. In addition, powerful analytic tools are provided, which are totally built on and allow representing all the information necessary for taking a right solution.

All additional information on the operation of the service can be found at the page for developers: https://developers.thethings.io/

An organisation of monitoring of sensors is described in the article on the example of integrating NetPing devices with the service. HTTP REST API is used for integration, which represents thethings.io and URL-encoded commands, which are supported by NetPing devices. The integration is implemented on the basis of the PowerShell script.

The script is executed according to the schedule with a specified frequency of a planner in Windows in the PowerShell environment. The first step is when the script gathers the data from temperature and humidity sensors, which are connected to the NetPing device. The second step is when the data are sent to the server of thethings.io.

Requirements for Implementing Integration of NetPing Devices with the Cloud Service thethings.io

To implement a represented solution, there is a need to have the next equipment:

If the NetPing equipment uses a router with the NAT and/or Firewall to access the Internet network and it is planned to run the PowerShell script on a PC, which is located outside a local network, there is a need to allow incoming packages via an HTTP protocol to the NetPing device to access it from the Internet. For additional information, see the documentation for the equipment of a router or contact a system administrator.

If necessary, a NetPing device can be connected to a router via a wireless technology Wi-Fi using an adapter VAP11N. The adapter is purchased separately. It is possible to see the user guide for this adapter for the additional information.

Configuring UniPing server solution v4/SMS

Set a UniPing server solution v4/SMS device to operating condition, plug temperature and humidity sensors, connect a device to the Internet – everything according to corresponding sections of the user guide.

It is possible to get an access to a NetPing device via an HTTP protocol in the Internet network using the next parameters:

  • IP address/host: test.netping.ru
  • TCP-port: 8080

Afterward, plugged temperature sensors can be accessed via the next URL addresses:

  • http://test.netping.ru:8080/thermo.cgi?t1
  • http://test.netping.ru:8080/thermo.cgi?t2

A plugged humidity sensor can be accessed via a URL address:

  • http://test.netping.ru:8080/relhum.cgi?h1

Everything is done according to the documentation for URL-encoded commands.

Example of the PowerShell Script

The script takes the readings of sensors from a UniPing server solution v4/SMS device and sends them to the cloud service thething.io.

#UniPing server solution v4/SMS PowerShell Script for thethings.io service

#URLs of sensors and login/password from a NetPing device
$user = "login"
$pass = "password"
$uri1 = "http://test.netping.ru:8080/thermo.cgi?t1"
$uri2 = "http://test.netping.ru:8080/thermo.cgi?t2"
$uri3 = "http://test.netping.ru:8080/relhum.cgi?h1"

$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)

$Temp1Reqest = Invoke-RestMethod -Method Get -Uri $uri1 -Credential $cred
if ($Temp1Reqest.ToLower().Contains("ok")){
else {Write-Host "Sensor Temp1 error!"}

$Temp2Reqest = Invoke-RestMethod -Method Get -Uri $uri2 -Credential $cred
if ($Temp2Reqest.ToLower().Contains("ok")){
else {Write-Host "Sensor Temp2 error!"}

$Humid1Reqest = Invoke-RestMethod -Method Get -Uri $uri3 -Credential $cred
if ($Humid1Reqest.ToLower().Contains("ok")){
else {Write-Host "Sensor Humid1 error!"}

#Account details of thethings.io

$token = "your_token_here"

$body = @{
values = @(@{
key = "temp_sensor1"
value = $temperature1
key = "temp_sensor2"
value = $temperature2
key = "hum_sensor1"
value = $humidity1

Invoke-RestMethod -Method Post -Uri "https://api.thethings.io/v2/things/$token" -Body (ConvertTo-Json $body) -ContentType 'application/json' -Headers @{ "Accept" = "application/json" }

At the beginning of the PowerShell script, write the values of a username and a password from your NetPing device:

  • $user ="login"
  • $pass="password"

Configuring the Service thethings.io

To start working with the service thethings.io, there is a need to get registered via the address:

When adding a new device, there is a need to have an activation code for it. Click the button «Get activation codes» at a control panel to start a procedure of adding a device.

After registering a test account, one free activation code will be available. Thus, you will be able to plug one device to the service. To purchase additional activation codes, follow the button «Get More Things».

Getting the activation code to add the device to the the theings.io service

At the next step it is necessary to click «+» next to a selected activation code:

Adding a new device to thethings.io service

Afterward, a token for working with a device will be available. The token allows to send/receive data via API in a control panel.

Token for device operation with thethings.io service

This token is necessary to be entered into the PowerShell script to make it work properly. To do this, there is a need to change the next field:

  • $token = "your_token_here"

Then configure automatic start of the PowerShell script. A recommended starting interval is 5 minutes. It is possible to use the next article on the Microsoft website or any other similar one from other sources for configuring.

If everything was configured properly, a script will read the data from temperature sensors, a humidity sensor and send them to the server of thethings.io every 5 minutes. You can watch data changing in graphs at the dashboard:

Thethings.io Control Panel

Sensor readings on the chart in thethings.io service


Therefore, thethings.io – is another backend platform for storing, saving, partial processing and transferring the information from different sensors, which can be used when creating own services, such as a smart home or even services of a greater scale.

comments powered by Disqus