Today we will be talking about the factors that enabled and boosted the Internet of Things (IoT).
1. Miniaturization Of Devices
The size (and cost) of electronic components that are needed to support capabilities such as sensing, tracking and control has been reducing and will continue to reduce as per Moore’s law.
2. Radio Frequency Identification (RFID)
Moving into the future, RFID has the potential to provide streams of data that will provide information systems with real-time, item-specific data and be flexible enough to be placed in extremely small spaces and locations, i.e., coil-on-chip technology.
3. Internet Protocol Version 6 (IPv6)
IPv6 is the next Internet addressing protocol that is used to replace IPv4. With IPv6, there are approximately 3.4×1038 (340 trillion) unique IPv6 addresses, allowing the Internet to continue to grow and innovate.
4. Communication Throughput And Lower Latency
Low latency makes it possible for IOT applications to query or receive quicker updates from sensor devices. LTE networks have latencies about 50-75 ms, which will open up new types of programming possibilities for application developers.
5. Low Power Consumption Devices
Low Power consumption devices will allow the devices to run for longer duration. Some devices will use solar capability to run, which will be self-sustained.
6. Cloud Computing
IOT connects billions of devices and sensors to create new and innovative applications. In order to support these applications, a reliable, elastic, and agile platform is essential. Cloud computing is one of the enabling platforms to support IOT, which provides required storage, processing power, and scaling capability.
7. Improved Security And Privacy
This allows the communication channel to be trustworthy. Critical business data can be passed by encryption or authentication code (MAC), protecting the confidentiality and authenticity of transaction data as it “transits” between networks.
There is still evolving standards in IoT security and with IPv6, IPsec support is integrated into the protocol design and connections can be secured when communicating with other IPv6 devices.
What is The Internet of Things (IoT) ? What is its value ?
IoT Concept and Examples
The IOT concept was initially coined by a member of the Radio Frequency Identification (RFID) development community in 1999, and it has recently become more relevant to the practical world largely because of the growth of mobile devices, embedded and ubiquitous communication, cloud computing and data analytics.
Since then, many have seized on the phrase “Internet of Things” to refer to the general idea of things, especially everyday objects, that are readable, recognisable, locatable, addressable, and/or controllable via the Internet, irrespective of the communication means (whether via RFID, wireless LAN, wide- area networks, or other means).
Everyday objects include not only the electronic devices we encounter or the products of higher technological development such as vehicles and equipment but things that we do not ordinarily think of as electronic at all – such as food and clothing.
Examples of “things” include:
People
Animals and Natural ecosystem
Location (of objects)
Time Information (of objects)
Condition (of objects)
These “things” of the real world shall seamlessly integrate into the virtual world, enabling anytime, anywhere connectivity.
Internet of Things (IoT) Global Economic Value
In 2010, the number of everyday physical objects and devices connected to the Internet was around 1 billion.
Cisco forecasts that this figure will reach to 25 billion in 2015 as the number of more smart devices per person increases, and to a further 50 billion by 2020.
In addition, the global economic impact, which IoT will collectively have, will be more than $14 Trillion; if we compare this to the world population, then by 2020 we will have around more than six connected devices per person.
All the components are now setup individually and all we need to do is to run them synchronously.
We should double check the URLs of the services, that links Raspberry Pi to SAP HANA system, from the sensor side; and SAP HANA system to SAPUI5, from the front end user’s side.
Let’s go for the go-live.
We are going to open the SAPUI5 app screen and start the Java program that reads the serial data and sends it back to HANA:
Now, once we start the Java program, we will instantly see the SAPUI5 app starts updating all the sensors data, on near real time basis.
A video result is shown here:
Congratulations we have now a working prototype ready of application leveraging Internet of Things with Raspberry Pi, Arduino Uno, sensors, SAP HANA and SAPUI5.
We have covered all the steps related to hardware setup and have also configured the backend SAP HANA.
We’ll configure now the UI which is going to show the sensor information.
The UI is simple and we have kept two tiles
The first tile is showing the value of the sensor ie. the LUX value or light intensity. The small window, below the reading value, tells how the sensor looks like (used custom CSS mapping).
We are going to create a simple view and controller and place the tiles in the view.The tiles will be placed in the tile container and the tile container will be returned inside the content of the page.
sap.ui.jsview("shiot_ui_02.shiot_ui_02", {
/** Specifies the Controller belonging to this View.
* In the case that it is not implemented, or that "null" is returned, this View does not have a Controller.
* @memberOf shiot_ui_02.shiot_ui_02
*/
getControllerName : function() {
return "shiot_ui_02.shiot_ui_02";
},
/** Is initially called once after the Controller has been instantiated. It is the place where the UI is constructed.
* Since the Controller is given to this method, its event handlers can be attached right away.
* @memberOf shiot_ui_02.shiot_ui_02
*/
createContent : function(oController) {
var content = new sap.suite.ui.commons.NumericContent("idInRateValue", {
size: "S",
scale: "LUX",
value: "{/value}",
valueColor: "Good",
indicator: "{/direction}"
});
var tileContent = new sap.suite.ui.commons.TileContent("idInTileCont", {
unit: "",
size: "L",
content: [
content
]
});
var tileInInfo = new sap.suite.ui.commons.GenericTile("idTileInInfo", {
header: "In",
size: "S",
frameType: "TwoByOne",
tileContent: [
tileContent
]
});
var tileCompr = new sap.suite.ui.commons.GenericTile("idAllGTStatus", {
header: "Compare Level",
size: "L",
scale: "L",
frameType: "TwoByOne",
press: function(){
sap.m.MessageToast.show("Demo");
},
tileContent: [
new sap.suite.ui.commons.TileContent("idDaysComprDash", {
size: "S",
scale: "S",
content: [
new sap.suite.ui.commons.ComparisonChart("idDaysCompr", {
size: "XS",
width: "18rem",
data: [
new sap.suite.ui.commons.ComparisonData({
title: "Maximum Limit",
value: "{/comparisonValue1}",
color: sap.suite.ui.commons.InfoTileValueColor.Error
}),
new sap.suite.ui.commons.ComparisonData({
title: "Current",
value: "{/comparisonValue2}",
color: sap.suite.ui.commons.InfoTileValueColor.Critical
}),new sap.suite.ui.commons.ComparisonData({
title: "Mimumim Limit",
value: "{/comparisonValue3}",
color: sap.suite.ui.commons.InfoTileValueColor.Good
})
]
})
]
})
]
});
tileCompr.addStyleClass("sapMTile backGroundWhite");
var custeReading = new sap.m.CustomTile({
content: [
tileContent
]
});
var custeCompare = new sap.m.CustomTile({
content: [
tileCompr
]
});
var tileContainer = new sap.m.TileContainer("idMainTiles", {
tiles: [
custeReading,
custeCompare
]
});
//Polling implementation
setInterval(oController.changeKPITest, 1000 * 3);
// create the page holding the List
var page1 = new sap.m.Page({
title: "HANA IoT KPI",
enableScrolling: false,
content : [
tileContainer
]
});
return page1;
}
});
Controller:
sap.ui.controller("shiot_ui_02.shiot_ui_02", {
/**
* Called when a controller is instantiated and its View controls (if available) are already created.
* Can be used to modify the View before it is displayed, to bind event handlers and do other one-time initialization.
* @memberOf shiot_ui_02.shiot_ui_02
*/
//onInit: function() {
//
//},
/**
* Similar to onAfterRendering, but this hook is invoked before the controller's View is re-rendered
* (NOT before the first rendering! onInit() is used for that one!).
* @memberOf shiot_ui_02.shiot_ui_02
*/
onBeforeRendering: function() {
var data = {
"value": 0,
"direction": "Down",
"comparisonValue1": 0,
"comparisonValue2": 0,
"comparisonValue3": 0
};
var oModel = new sap.ui.model.json.JSONModel();
oModel.setData(data);
sap.ui.getCore().setModel(oModel);
},
//Triggers automatically for display test
changeKPITest: function(){
/*var min = 0;
var max = 100;
var newRandomreading = Math.floor(Math.random() * (max - min)) + min;*/
var url = "http:///demoApp/demo01/app01/services/getSensorReading.xsjs?id=";
var _SENSORID = "A001";
var _MAXLIMIT = 170;
var _MINLIMIT = 25;
var data = {
"value": 0,
"direction": "Down",
"comparisonValue1": _MAXLIMIT,
"comparisonValue2": 0,
"comparisonValue3": _MINLIMIT
};
var oModel;
var newColorCode;
//for now hardcoding the sensor ID
url = url + _SENSORID;
//Doing the asyn call to HANA system
jQuery.ajax({
url: url,
async: true,
dataType: 'json',
type: 'GET',
success: function(oData) {
if (!oData) {
sap.m.MessageToast.show("Not able to get Data");
} else {
data["value"] = oData["value"];
data["comparisonValue2"] = oData["value"];
oModel = sap.ui.getCore().getModel();
if(oModel.getData()["comparisonValue2"] > data["comparisonValue2"]){
data["direction"] = "Down";
}else{
data["direction"] = "Up";
}
oModel.setData(data);
oModel.refresh();
//changing the color as well
newColorCode = parseInt(data["value"])*2 ;
if(newColorCode > 255){
newColorCode = 255;
}
$('#idInTileCont-footer-text').css("background-color", "rgba("+newColorCode+", "+newColorCode+", "+newColorCode+", 0.99)");
}
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
sap.m.MessageToast.show("Connection not able to establish");
}
});
},
/**
* Called when the View has been rendered (so its HTML is part of the document). Post-rendering manipulations of the HTML could be done here.
* This hook is the same one that SAPUI5 controls get after being rendered.
* @memberOf shiot_ui_02.shiot_ui_02
*/
//onAfterRendering: function() {
//
//},
/**
* Called when the Controller is destroyed. Use this one to free resources and finalize activities.
* @memberOf shiot_ui_02.shiot_ui_02
*/
//onExit: function() {
//
//}
});
Here the controller function changeKPITest is polled every 3 sec and we have the new data bound to model, which is returned from SAP HANA XSJS AJAX call .
It is better to have a push notification feature in here instead of polling which, is called web-sockets, but for simplicity purpose we have kept the configuration minimal.
In part 7, we are tying the loose ends and going live.
Once you have activate the code, you need to create two tables demo02sensor_active_TS and demo02sensor_info_MD .
demo02sensor_active_TS: Stores the transactional Data of the sensors (readings with timestamp).
demo02sensor_info_MD: Stores the Master Data of the sensors (Sensor Id’s)
Step2 – Create the SQL procedures to do data operations
We have to create two SQL procedures for data operations: insert_sensor_reading.hdbprocedure and sensor_read.hdbprocedure.
As the names suggest, the first one is going to insert sensor data in sensor table and second one is going to read the recent sensor data from the table.
insert_sensor_reading.hdbprocedure is inside the folder Procedures. It is taking sensor ID and sensor Reading as input:
PROCEDURE
"DemoSchema"."demoApp.demo01.app02.SHIOT_02.Procedures::insert_sensor_reading" (
IN SENSORID NVARCHAR(10),
IN sensor_reading INTEGER )
LANGUAGE SQLSCRIPT AS
BEGIN
/*****************************
Inserting sensor Data
*****************************/
insert into "demoApp.demo01.app02.SHIOT_02.Data::demos02sensorNetwork.demo02sensor_active_TS"
VALUES(:SENSORID, CURRENT_TIMESTAMP , sensor_reading
);
END;
sensor_read.hdbprocedure is inside the folder Procedures. It is taking sensor ID as input and returns one data set of demo02sensor_active_TS.
PROCEDURE
"DemoSchema"."demoApp.demo01.app02.SHIOT_02.Procedures::sensor_read(
IN id NVARCHAR(10),
OUT result "DemoSchema"."demoApp.demo01.app02.SHIOT_02.Data::demo02sensorNetwork.demo02sensor_active_TS")
LANGUAGE SQLSCRIPT
SQL SECURITY INVOKER
--DEFAULT SCHEMA
READS SQL DATA <u>AS</u>
BEGIN
/*****************************
Reading sensors Data
*****************************/
result = select *
from "DemoSchema"."demoApp.demo01.app02.SHIOT_02.Data::demo02sensorNetwork.demo02sensor_active_TS"
where "ID" = :id and "time_stamp" = (select max("time_stamp") from
"DemoSchema"."demoApp.demo01.app02.SHIOT_02.Data::demo02sensorNetwork.demo02sensor_active_TS"
where "ID"= :id);
END;
Step3: Create the XSJS services
Create the XSJS services to act as a Gateway between the SQL Procedures calls and the service calls for Raspberry Pi and SAP UI5 application:
We have two services.
The first one is getSensorReading.xsjs which reads the recent sensor reading for the sensor id, passed in the URL. It uses sensor_read.hdbprocedure for database call.
var sensorId = $.request.parameters.get("id");
var body = "error";
var data ={
"id":"error",
"timestamp":"error",
"value":0
};
body = sensorId;
if(sensorId === undefined){
$.response.setBody( "Invalid key !!!");
}
else{
$.response.contentType = "text/plain";
$.response.setBody(sensorId);
try {
var conn = $.db.getConnection();
var query = 'call \"demoApp.demo01.app02.SHIOT_02.Procedures::sensor_read\"(?,?)';
var cst = conn.prepareCall(query);
cst.setString(1, sensorId);
var rs = cst.execute();
conn.commit();
rs = cst.getResultSet();
while(rs.next()){
data.id = rs.getNString(1);
data.timestamp= rs.getTimestamp(2) ;
data.value= rs.getInteger(3);
}
body = JSON.stringify(data);
conn.close();
} catch (e) {
body = e.stack + "\nName:"+ e.name+"\nMsg" + e.message;
$.response.status = $.net.http.BAD_REQUEST;
}
}
$.response.contentType = "text/plain";
$.response.setBody(body);
Then after that, we use putSensorReading.xsjs which reads the recent sensor reading for the sensor id and sensor value passed in the URL. It uses insert_sensor_reading.hdbprocedurefor database call to store the data.
var sensorId = $.request.parameters.get("id");
var sensorReading = $.request.parameters.get("value");
sensorReading = parseInt(sensorReading,10);
var body = "error";
if(sensorId === undefined){
$.response.setBody( "Invalid key !!!");
}
else{
$.response.contentType = "text/plain";
$.response.setBody(sensorId);
try {
var conn = $.db.getConnection();
var query = 'call \"demoApp.demo01.app02.SHIOT_02.Procedures::insert_sensor_reading\"(?,?)';
var cst = conn.prepareCall(query);
cst.setString(1, sensorId);
cst.setInteger(2, sensorReading);
var rs = cst.execute();
conn.commit();
//as no record returned
if(rs == 0){
body = true;
}
conn.close();
} catch (e) {
body = e.stack + "\nName:"+ e.name+"\nMsg" + e.message;
$.response.status = $.net.http.BAD_REQUEST;
}
}
$.response.contentType = "text/plain";
$.response.setBody(body);
In the real world setup we need also to assign the security key to each sensor and pass it to verify the readings.
Also it would be better to have the timestamp taken from the sensor source and store it in the database but for keeping the coding and complexity minimum we are focusing on the core steps.
In part 6, we are going to setup the SAPUI5 App and integrate it with the backend.