Building an IoT Sensor Dashboard

The ultimate goal is to launch a large number of companies of Industry 4.0 capable of adapting to the needs of the business and production processes in a way more effective way, thus making a more efficient management of resources.

The key concept of Internet of Things has been introduced by Ashton, 2009 and one important challenge is to provide Solution in order to manage sensor telemetry by real time platform. The conventional business intelligence solutions not allow to manage this kind of devices and the setup of this system is usually complex.

This key concept is crucial for implementing smart cities capabilities on Industry 4.0 (Zanella, 2014)  and therefore is important to develop newest solutions for managing telemetry data from sensor devices  (Jeschke, 2016). The real-time visualization data, it own transformation and it use of intelligence artificial algorithms can improve and optimize the industrial process.

This white paper describes how to send sensor telemetry connected to Arduino UNO R3. This sensors collect the distance from the nearest pot to the sensor. The data is processed by PaaS architecture from Azure catalog  Event Hub, Stream Analytics and Power BI.

Architecture

myCloudDoor is specialist in deploy of managing real time data form different sources by using PaaS resources and server less architecture (figure 1)

Figure 1. Architecture Lambda Azure for managing  IoT telemetry

 

[qodef_blockquote text=”The ultimate goal is to launch a large number of companies of Industry 4.0 capable of adapting to the needs of the business and production processes in a way more effective way, thus making a more efficient management of resources” title_tag=”h3″ width=””]

 

How to send sensor date

The first step is to setup the sensor by connecting Arduino motherboard

https://www.luisllamas.es/medir-distancia-con-arduino-y-sensor-de-ultrasonidos-hc-sr04/.

Then we need to collect data using this Powershell script:

$ehName = "your name" # hub name
$ehNameSpace = "your space" # namespace
$keyname = "your name" # name of the policy
$key = "OUR KEY"

# Load the System.Web assembly to enable UrlEncode
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null

$URI = "{0}.servicebus.windows.net/{1}" -f @($ehNameSpace,$ehName)
$encodedURI = [System.Web.HttpUtility]::UrlEncode($URI)

# Calculate expiry value one hour ahead
$expiry = [string](([DateTimeOffset]::Now.ToUnixTimeSeconds())+3600)

# Create the signature
$stringToSign = [System.Web.HttpUtility]::UrlEncode($URI) + "`n" + $expiry

$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::ASCII.GetBytes($key)

$signature = $hmacsha.ComputeHash([Text.Encoding]::ASCII.GetBytes($stringToSign))
$signature = [System.Web.HttpUtility]::UrlEncode([Convert]::ToBase64String($signature))


$port= new-Object System.IO.Ports.SerialPort COM3,9600,None,8,one
$port.Open()
$port.ReadLine()

$assoc = New-Object psobject -Property @{
    Id = 42
     Name = "{'Distance':"
    Owner = "}"
}

# create Request Body


$body = $assoc.Name +$port.ReadLine()+$assoc.Owner
 



# API headers
#
$headers = @{
            "Authorization"="SharedAccessSignature sr=" + $encodedURI + "&sig=" + $signature + "&se=" + $expiry + "&skn=" + $keyname;
            "Content-Type"="application/atom+xml;type=entry;charset=utf-8"; # must be this
            "Content-Length" = ("{0}" -f ($body.Length))
            }

# execute the Azure REST API
$method = "POST"
$dest = 'https://' +$URI  +'/messages?timeout=60&api-version=2014-01'

<# used for turning off certificate checking in case you are using fiddler or other man in the middle#>
<#
add-type -TypeDefinition  @"
        using System.Net;
        using System.Security.Cryptography.X509Certificates;
        public class TrustAllCertsPolicy : ICertificatePolicy {
            public bool CheckValidationResult(
                ServicePoint srvPoint, X509Certificate certificate,
                WebRequest request, int certificateProblem) {
                return true;
            }
        }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
#>
Invoke-RestMethod -Uri $dest -Method $method -Headers $headers -Body $body -Verbose

$port.Close()

After, we get data from COM 3 port (this method also works in Linux system). We have to user the keys provided by Event hub resources. (figure 2)

Figure 2. Azure Event Hub

 

After that we can check if event hub is working into overview tab. Additional functionality form event hub allows to collect telemetry into an Azure Blob Storage

At this point we setup the stream Analytics services. We define Event Hub as input and power Bi as output. We creates the next query into 2 seconds screen and aggregate getting the average value in order to reduce the value fluctuation.

SELECT
       AVG(CAST(DISTANCE AS BIGINT)) as [Distance],
       System.TimeStamp AS Time
       INTO OutputPBI
FROM
    [InputEH] 

    GROUP BY
    TumblingWindow(second, 2)

For setting up the Power Bi dashboard we carried out the following steps:

https://docs.microsoft.com/es-es/azure/stream-analytics/stream-analytics-power-bi-dashboard

Conclusions

This solution shows the capabilities of lambda architectures by using PaaS solutions from cortana Intelligence Suite for managing real-time data from IoT Sensor telemetry.

References

Jeschke, S. (2016). Industrial Internet of Things and Cyber Manufacturing Systems. Industrial Internet of Things.

Zanella, A. (2014). Internet of Things for Smart Cities. IEEE INTERNET OF THINGS JOURNAL. Obtenido de http://industria4.es/empresa/entender-la-industria-4-0/

Leave a Reply

Your email address will not be published.

Share This

Copy Link to Clipboard

Copy