Example of NetPing Integration with the Service IoT dweet.io

  • Published In: Tutorial
  • Created Date: 2015-11-26
  • Hits: 1564

In the previous publications on an integration of NetPing devices, two examples with cloud services of Internet of things concept (IoT) were examined: xively.com and thethings.io. Now it is a turn for the integration of NetPing devices with a similar service dweet.io to be examined.

A distinctive feature of this service is the fact that there is no need to sign up or configure something to work with it – data from your devices can be transferred at once. The service is built on the principle of objects named "things", into which a data is transferred through HTTP requests. In case if there is no object with such name, it is created automatically. A name for a future object must be unique.

Data can be transferred into objects both by placing them directly to the URL as a pair of a paramater=value, and transferred as JSON structures in the request body POST. At  each request, a service gets a returned response in a form of a JSON response.

To read data from objects, there is HTTP API, which allows receiving last values of parameters or all values for a specified period. A service allows storing up to 500 values for the last 24 hours. A history is cleared if data are not received during 24 hours.

In the free version of the service, all objects and data with their values are in an open access (public). The service provides a possibility to create locked objects and reserve a name for them at an extra charge. Such objects can be accessed using a specific key.

For locked objects, there is a possibility to send a notification to e-mail, if the value in them leaves the range of specified thresholds. A condition is set by a simple Javаscript expression and is also transferred through HTTP API request.

When creating client applications, you can use ready libraries for:

  • Node.js
  • Javascript
  • Python
  • Ruby

More detailed information can be found at the official site of the service - dweet.io.

In this article, a simple example of integrating a UniPing server solution v4/SMS device with this service will be described. For the integration, HTTP REST API is used, which represents dweet.io and URL-encoded commands, which are supported by a UniPing server solution v4/SMS device. The integration is implemented on the basis of a PowerShell script.

A script is executed according to a schedule – with a specified interval of a Windows planner in a Powershell environment. The first step for a script is to gather data from temperature and humidity sensors, which are connected to a NetPing device. At the second step, the data are sent to the server dweet.io.

Requirements for Integrating NetPing Devices with the Cloud Service dweet.io

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

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

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

Configuring UniPing server solution v4/SMS

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

A path to a NetPing device via HTTP protocol in the Internet network can be obtained according to the next parameters:

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

Then connected temperature sensors can be accessed via the next URL addresses:

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

An access to a connected humidity sensor can be received via a URL-address:

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

Everything is implemented according to a documentation for URL-encoded commands.

Example of a PowerShell Script

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

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

##########################################################
#URLs of sensors and login/password from a NetPing device
##########################################################
$user = "login"
$pass = "password"
$uri1 = "http://dweet.netping.ru:8080/thermo.cgi?t1"
$uri2 = "http://dweet.netping.ru:8080/thermo.cgi?t2"
$uri3 = "http://dweet.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")){
$temperature1=[convert]::ToInt32($Temp1Reqest.Split(",").Trim("")[1])
}
else {Write-Host "Sensor Temp1 error!"}

$Temp2Reqest = Invoke-RestMethod -Method Get -Uri $uri2 -Credential $cred
if ($Temp2Reqest.ToLower().Contains("ok")){
$temperature2=[convert]::ToInt32($Temp2Reqest.Split(",").Trim("")[1])
}
else {Write-Host "Sensor Temp2 error!"}

$Humid1Reqest = Invoke-RestMethod -Method Get -Uri $uri3 -Credential $cred
if ($Humid1Reqest.ToLower().Contains("ok")){
$humidity1=[convert]::ToInt32($Humid1Reqest.Split(",").Trim("")[1])
}
else {Write-Host "Sensor Humid1 error!"}

#############################
#Details of dweet.io account
#############################
$thing_name = "object_name"
$key = " "
#############################

$body = @{}
$body.TempSensor1=$temperature1
$body.TempSensor2=$temperature2
$body.HumidSensor1=$humidity1

Invoke-RestMethod -Method Post -Uri "https://dweet.io/dweet/for/$thing_name" -Body $body -Headers @{ "key" = $key }

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

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

Configuring the Service IoT dweet.io

As said above, there is no need to sign up or perform any initial configuration to start working with the service. Everything necessary is to choose a unique name of the dweet.io object and add it into the script:

  • $thing_name = "object_name"

If a locked name for an object is used, there is a need to add a key for authorization into the script besides the name. There is a need to add key values between " " for the variable $key = " ". More detailed information is at the project web page.

Then, configure an automatic start of the PowerShell script. A recommended interval for a start is 5 minutes. For configuring, it is possible to use the article at the Microsoft website or any similar one from other sources.

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

In addition, it is possible to configure data representation in the more convenient and beautiful form using a free service https://freeboard.io.

Result

Therefore, dweet.io – is another backend platform for gathering, storing, and partial processing of the information from different sensors, which can be used when creating own services, such as a smart home or projects of a bigger scale.


comments powered by Disqus