Add sensor types for CPU Load and RAM Usage

application-manager-new
charithag 10 years ago
parent f435d6d1b4
commit e336c4f9f2

@ -43,12 +43,28 @@ if (uriMatcher.match("/{context}/api/stats")) {
} }
log.info("deviceId : " + deviceId + " from : " + from + " to : " + to); log.info("deviceId : " + deviceId + " from : " + from + " to : " + to);
if(deviceType=="firealarm"){
switch (deviceType){
case "firealarm":
result = getFireAlarmData(user.username, deviceId, from, to); result = getFireAlarmData(user.username, deviceId, from, to);
}else if(deviceType=="sensebot"){ break;
case "sensebot":
result = getSensebotData(user.username, deviceId, from, to); result = getSensebotData(user.username, deviceId, from, to);
}else if(deviceType=="arduino"){ break;
case "arduino":
result = getArduinoData(user.username, deviceId, from, to); result = getArduinoData(user.username, deviceId, from, to);
break;
case "digital_display":
result = getDigitalDisplayData(user.username, deviceId, from, to);
break;
case "android_sense":
result = getAndroidSenseData(user.username, deviceId, from, to);
break;
case "raspberrypi":
result = getDigitalDisplayData(user.username, deviceId, from, to);
break;
default:
result = new Object();
} }
} }
@ -57,6 +73,14 @@ if (result) {
print(result); print(result);
} }
function getFireAlarmData(user, deviceId, from, to){
result = new Object();
result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to);
result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY","status",user, deviceId, from, to);
result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY","status",user, deviceId, from, to);
return result;
}
function getSensebotData(user, deviceId, from, to){ function getSensebotData(user, deviceId, from, to){
result = new Object(); result = new Object();
result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY","sonar",user, deviceId, from, to); result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY","sonar",user, deviceId, from, to);
@ -66,22 +90,33 @@ function getSensebotData(user, deviceId, from, to){
return result; return result;
} }
function getArduinoData(user, deviceId, from, to){
function getFireAlarmData(user, deviceId, from, to){
result = new Object(); result = new Object();
result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to);
return result;
}
//result['sonarData'] = getSensorData("SONAR_SENSOR_SUMMARY","sonar",user, deviceId, from, to); function getDigitalDisplayData(user, deviceId, from, to){
//result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to); result = new Object();
//result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_SUMMARY","light",user, deviceId, from, to); result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to);
result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to);
result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to);
return result;
}
function getAndroidSenseData(user, deviceId, from, to){
result = new Object();
result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to);
result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to);
result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to);
result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY","status",user, deviceId, from, to); result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to);
result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY","status",user, deviceId, from, to);
return result; return result;
} }
function getArduinoData(user, deviceId, from, to){ function getDigitalDisplayData(user, deviceId, from, to){
result = new Object(); result = new Object();
result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",user, deviceId, from, to);
result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",user, deviceId, from, to);
result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to); result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY","TEMPERATURE",user, deviceId, from, to);
return result; return result;
} }
@ -96,18 +131,18 @@ function getSensorData(table, column, user, deviceId, from, to) {
log.info(error); log.info(error);
} }
var temperatureData = []; var sensorData = [];
if(fetchedData==null) return []; if(fetchedData==null) return [];
for (var i = 0; i < fetchedData.size(); i++) { for (var i = 0; i < fetchedData.size(); i++) {
temperatureData.push({ sensorData.push({
time: fetchedData.get(i).getTime(), time: fetchedData.get(i).getTime(),
value: fetchedData.get(i).getValue() value: fetchedData.get(i).getValue()
}); });
} }
return temperatureData; return sensorData;
} }
%> %>

@ -37,64 +37,20 @@
</div> </div>
<div class="clear"></div> <div class="clear"></div>
<div id="div-temperatureData"> <div id="div-temperatureData">
<div class="row margin-double">
<div>
<h2 class="grey ">Temperature</h2>
<hr>
<div id="canvas-wrapper1">No data available...</div>
</div>
<hr>
</div>
</div> </div>
<div id="div-lightData"> <div id="div-lightData">
<div class="row margin-double">
<div>
<h2 class="grey ">Light</h2>
<hr>
<div id="canvas-wrapper2">No data available...</div>
</div>
<hr>
</div>
</div> </div>
<div id="div-motionData"> <div id="div-motionData">
<div class="row margin-double">
<div>
<h2 class="grey ">Motion</h2>
<hr>
<div id="canvas-wrapper3">No data available...</div>
</div>
<hr>
</div>
</div> </div>
<div id="div-sonarData"> <div id="div-sonarData">
<div class="row margin-double">
<div>
<h2 class="grey ">Sonar</h2>
<hr>
<div id="canvas-wrapper4">No data available...</div>
</div>
<hr>
</div>
</div> </div>
<div id="div-fanData"> <div id="div-fanData">
<div class="row margin-double">
<div>
<h2 class="grey ">Fan Status</h2>
<hr>
<div id="canvas-wrapper5">No data available...</div>
</div>
<hr>
</div>
</div> </div>
<div id="div-bulbData"> <div id="div-bulbData">
<div class="row margin-double">
<div>
<h2 class="grey ">Bulb Status</h2>
<hr>
<div id="canvas-wrapper6">No data available...</div>
</div> </div>
<hr> <div id="div-CPUData">
</div> </div>
<div id="div-RAMData">
</div> </div>
</div> </div>
</div> </div>
@ -112,4 +68,6 @@
<script src="{{self.publicURL}}/js/graphs/light_graph.js"></script> <script src="{{self.publicURL}}/js/graphs/light_graph.js"></script>
<script src="{{self.publicURL}}/js/graphs/motion_graph.js"></script> <script src="{{self.publicURL}}/js/graphs/motion_graph.js"></script>
<script src="{{self.publicURL}}/js/graphs/sonar_graph.js"></script> <script src="{{self.publicURL}}/js/graphs/sonar_graph.js"></script>
<script src="{{self.publicURL}}/js/graphs/cpu_graph.js"></script>
<script src="{{self.publicURL}}/js/graphs/ram_graph.js"></script>
{{/zone}} {{/zone}}

@ -195,6 +195,22 @@ function updateGraphs(stats) {
$('#div-bulbData').html(""); $('#div-bulbData').html("");
} }
var cpuData = stats['cpuData'];
if (typeof cpuData != 'undefined'){
$('#div-CPUData').html("").html("<div class='row margin-double'><div><h2 class='grey'>CPU Load</h2><hr><div id='canvas-wrapper7'></div></div><hr></div>");
updateCPUGraph(convertStateStatsToGraphData(cpuData));
}else{
$('#div-CPUData').html("");
}
var ramData = stats['ramData'];
if (typeof ramData != 'undefined'){
$('#div-RAMData').html("").html("<div class='row margin-double'><div><h2 class='grey'>RAM Usage</h2><hr><div id='canvas-wrapper8'></div></div><hr></div>");
updateRAMGraph(convertStateStatsToGraphData(ramData));
}else{
$('#div-RAMData').html("");
}
scaleGraphs(); scaleGraphs();
} }

@ -0,0 +1,69 @@
function updateCPUGraph(CPUData) {
renderCPUChart(CPUData);
}
function renderCPUChart(chartDataRaw){
var chartWrapperElmId = "#canvas-wrapper7";
var graphWidth = $(chartWrapperElmId).width() - 50;
if (chartDataRaw.length == 0) {
$(chartWrapperElmId).html("No data available...");
return;
}
var chartData = [];
for (var i = 0; i < chartDataRaw.length; i++){
chartData.push({x:parseInt(chartDataRaw[i].x), y:parseInt(chartDataRaw[i].y)});
}
//var i = parseInt(fromDate);
//while (i < parseInt(toDate)){
// var rnd = Math.random() * (30 - 20) + 20;
// chartData.push({x:i * 1000, y:rnd});
// i += 60 * 5;
//}
var chartDiv = "chart7";
var sliderDiv = "slider7";
var x_axis = "x_axis7";
var y_axis = "y_axis7";
$(chartWrapperElmId).html("").html('<div id="' + y_axis + '" class="custom_y_axis"></div><div id="' + chartDiv + '" class="custom_rickshaw_graph"></div><div id="' + x_axis + '" class="custom_x_axis"></div><div id="' + sliderDiv + '" class="custom_slider"></div>');
var graph = new Rickshaw.Graph({
element: document.getElementById(chartDiv),
width: graphWidth,
height: 400,
strokeWidth: 1,
renderer: 'line',
xScale: d3.time.scale(),
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0},
series:[
{ color: '#2F0B3A', data: chartData }
]
});
graph.render();
var xAxis = new Rickshaw.Graph.Axis.X({
graph: graph,
orientation: 'bottom',
element: document.getElementById(x_axis),
tickFormat: graph.x.tickFormat()
});
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
orientation: 'left',
element: document.getElementById(y_axis),
width: 40,
height: 410
});
yAxis.render();
var slider = new Rickshaw.Graph.RangeSlider.Preview({
graph: graph,
element: document.getElementById(sliderDiv)
});
}

@ -0,0 +1,69 @@
function updateRAMGraph(RAMData) {
renderRAMChart(RAMData);
}
function renderRAMChart(chartDataRaw){
var chartWrapperElmId = "#canvas-wrapper8";
var graphWidth = $(chartWrapperElmId).width() - 50;
if (chartDataRaw.length == 0) {
$(chartWrapperElmId).html("No data available...");
return;
}
var chartData = [];
for (var i = 0; i < chartDataRaw.length; i++){
chartData.push({x:parseInt(chartDataRaw[i].x), y:parseInt(chartDataRaw[i].y)});
}
//var i = parseInt(fromDate);
//while (i < parseInt(toDate)){
// var rnd = Math.random() * (30 - 20) + 20;
// chartData.push({x:i * 1000, y:rnd});
// i += 60 * 5;
//}
var chartDiv = "chart8";
var sliderDiv = "slider8";
var x_axis = "x_axis8";
var y_axis = "y_axis8";
$(chartWrapperElmId).html("").html('<div id="' + y_axis + '" class="custom_y_axis"></div><div id="' + chartDiv + '" class="custom_rickshaw_graph"></div><div id="' + x_axis + '" class="custom_x_axis"></div><div id="' + sliderDiv + '" class="custom_slider"></div>');
var graph = new Rickshaw.Graph({
element: document.getElementById(chartDiv),
width: graphWidth,
height: 400,
strokeWidth: 1,
renderer: 'line',
xScale: d3.time.scale(),
padding: {top: 0.2, left: 0.02, right: 0.02, bottom: 0},
series:[
{ color: '#170B3B', data: chartData }
]
});
graph.render();
var xAxis = new Rickshaw.Graph.Axis.X({
graph: graph,
orientation: 'bottom',
element: document.getElementById(x_axis),
tickFormat: graph.x.tickFormat()
});
xAxis.render();
var yAxis = new Rickshaw.Graph.Axis.Y({
graph: graph,
orientation: 'left',
element: document.getElementById(y_axis),
width: 40,
height: 410
});
yAxis.render();
var slider = new Rickshaw.Graph.RangeSlider.Preview({
graph: graph,
element: document.getElementById(sliderDiv)
});
}

@ -1,5 +1,5 @@
{{#zone "main"}} {{#zone "main"}}
<div class="container container-bg white-bg"> <div class="container container-bg white-bg">
<div class=" margin-top-double"> <div class=" margin-top-double">
<div class="row row padding-top-double padding-bottom-double margin-bottom-double"> <div class="row row padding-top-double padding-bottom-double margin-bottom-double">
<div class="col-lg-12 margin-top-double"> <div class="col-lg-12 margin-top-double">
@ -21,42 +21,29 @@
<span class="fw-stack fw-lg margin-right"> <span class="fw-stack fw-lg margin-right">
<i class="fw fw-ring fw-stack-2x"> </i> <i class="fw fw-ring fw-stack-2x"> </i>
<i class="fw fw-right-arrow-2 fw-stack-1x"></i> <i class="fw fw-right-arrow-2 fw-stack-1x"></i>
</span>Arduino Uno<br><br> </span>Android Phone<br><br>
<span class="fw-stack fw-lg margin-right"> <br/><br/>
<i class="fw fw-ring fw-stack-2x"> </i>
<i class="fw fw-right-arrow-2 fw-stack-1x"></i>
</span>Arduino Ethernet / WiFi Shield
<br /><br />
<form method="POST" class="float-left margin-right" <form method="POST" class="float-left margin-right"
action="{{sketchPath}}"> action="/iotserver/public/downloads/android-app.apk">
<input type="hidden" name="deviceType" value="sensebot" /> <input type="hidden" name="deviceType" value="android_sense"/>
<input type="hidden" name="sketchType" value="sensebot_wifi" /> <input type="hidden" name="sketchType" value="android_sense"/>
<button class="wr-btn" type="submit">Create Sketch for <button class="wr-btn" type="submit">Create apk for Android
Wifi
</button> </button>
</form> </form>
<form method="POST" class="form-login-box float-left"
action="{{sketchPath}}">
<input type="hidden" name="deviceType" value="sensebot" />
<input type="hidden" name="sketchType" value="sensebot" />
<button class="wr-btn margin-right" type="submit">Create
Sketch
for Ethernet</button>
</form>
<br/> <br/>
</div> </div>
<div class ="col-xs-12 col-sm-6 col-md-3 col-lg-12 padding-double grey-bg "> <div class="col-xs-12 col-sm-6 col-md-3 col-lg-12 padding-double grey-bg ">
<h2 class="uppercase">Prepare</h2><hr> <h2 class="uppercase">Prepare</h2>
<hr>
<p class="grey margin-top">Get your device ready </p> <p class="grey margin-top">Get your device ready </p>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom "> <div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom ">
<span class="circle">01 </span> <span class="padding-left"> Mount the Ethernet / Wifi shield on the Arduino Uno device.</span> <span class="circle">01 </span> <span class="padding-left"> Go to android device security settings.</span>
</div> </div>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom"> <div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom">
<span class="circle">02 </span> <span class="padding-left"> Mount the Ethernet / Wifi shield on the Arduino Uno device.</span> <span class="circle">02 </span> <span class="padding-left"> Check unknown sources.</span>
</div>
<div class="margin-doubles padding-top-double margin-bottom-double light-grey margin-left-double margin-bottom">
<span class="circle">03 </span> <span class="padding-left"> Mount the Ethernet / Wifi shield on the Arduino Uno device.</span>
</div> </div>
</div> </div>
</div> </div>
@ -65,20 +52,21 @@
<h2 class="uppercase ">Connect (Quickstart)</h2> <h2 class="uppercase ">Connect (Quickstart)</h2>
<hr> <hr>
<p class="margin-bottom-double light-grey ">Internet of Things Foundation Quickstart connection </p> <p class="margin-bottom-double light-grey ">Internet of Things Foundation Quickstart connection </p>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom "> <div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom ">
<span class="circle">01 </span> <span class="padding-left">Use the following command to download the installer from GitHub:</span><br> <span class="circle">01 </span> <span class="padding-left">Use the following command to download the installer from GitHub:</span><br>
</div> </div>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom "> <div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom ">
<span class="circle">02 </span> <span class="padding-left">Download the Sketch installer from the Arduino website <a href="http://arduino.cc/en/Main/Software">http://arduino.cc/en/Main/Software</a></span><br> <span class="circle">02 </span> <span class="padding-left">Copy downloaded apk in to device</span><br>
</div> </div>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom "> <div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom ">
<span class="circle">03 </span> <span class="padding-left"> Install the Sketch program</span><br> <span class="circle">03 </span> <span
class="padding-left"> Install apk in the device.</span><br>
</div> </div>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom "> <div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom ">
<span class="circle">04 </span> <span class="padding-left">Use the Sketch program to open the samples code: <a href="http://tinyurl.com/EUHackathonRobot">http://tinyurl.com/EUHackathonRobot</a> </span><br> <span class="circle">04 </span> <span
class="padding-left">Open Android Sense application.</span><br>
</div> </div>
<div class="margin-doubles padding-top-double light-grey margin-left-double margin-bottom ">
<span class="circle">05 </span> <span class="padding-left">View the lower part of the Sketch pad window to check that the COM connection is shown as active</span><br>
</div> </div>
</div> </div>
</div> </div>

@ -24,8 +24,8 @@
</span>Raspberry Pi<br><br> </span>Raspberry Pi<br><br>
<form method="POST" class="form-login-box" <form method="POST" class="form-login-box"
action="{{sketchPath}}"> action="{{sketchPath}}">
<input type="hidden" name="deviceType" value="arduino" /> <input type="hidden" name="deviceType" value="raspberrypi" />
<input type="hidden" name="sketchType" value="arduino" /> <input type="hidden" name="sketchType" value="raspberrypi" />
<button class="wr-btn" type="submit">Download DEB</button> <button class="wr-btn" type="submit">Download DEB</button>
</form> </form>
<br/> <br/>

Loading…
Cancel
Save