|
|
@ -31,118 +31,111 @@ var statsClient = new Packages.org.wso2.carbon.device.mgt.iot.common.analytics.s
|
|
|
|
|
|
|
|
|
|
|
|
if (uriMatcher.match("/{context}/api/stats")) {
|
|
|
|
if (uriMatcher.match("/{context}/api/stats")) {
|
|
|
|
|
|
|
|
|
|
|
|
deviceId = request.getParameter("deviceId");
|
|
|
|
deviceId = request.getParameter("deviceId");
|
|
|
|
deviceType = request.getParameter("deviceType");
|
|
|
|
deviceType = request.getParameter("deviceType");
|
|
|
|
from = request.getParameter("from");
|
|
|
|
from = request.getParameter("from");
|
|
|
|
to = request.getParameter("to");
|
|
|
|
to = request.getParameter("to");
|
|
|
|
|
|
|
|
|
|
|
|
user = session.get(constants.USER_SESSION_KEY);
|
|
|
|
user = session.get(constants.USER_SESSION_KEY);
|
|
|
|
if (!user) {
|
|
|
|
if (!user) {
|
|
|
|
response.sendRedirect(dcProps.appContext + "login?#login-required");
|
|
|
|
response.sendRedirect(dcProps.appContext + "login?#login-required");
|
|
|
|
exit();
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log.info("deviceId : " + deviceId + " from : " + from + " to : " + to);
|
|
|
|
log.info("deviceId : " + deviceId + " from : " + from + " to : " + to);
|
|
|
|
|
|
|
|
|
|
|
|
switch (deviceType){
|
|
|
|
switch (deviceType) {
|
|
|
|
case "firealarm":
|
|
|
|
case "firealarm":
|
|
|
|
result = getFireAlarmData(user.username, deviceId, from, to);
|
|
|
|
result = getFireAlarmData(user.username, deviceId, from, to);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "sensebot":
|
|
|
|
case "sensebot":
|
|
|
|
result = getSensebotData(user.username, deviceId, from, to);
|
|
|
|
result = getSensebotData(user.username, deviceId, from, to);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "arduino":
|
|
|
|
case "arduino":
|
|
|
|
result = getArduinoData(user.username, deviceId, from, to);
|
|
|
|
result = getArduinoData(user.username, deviceId, from, to);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "digital_display":
|
|
|
|
case "digital_display":
|
|
|
|
result = getDigitalDisplayData(user.username, deviceId, from, to);
|
|
|
|
result = getDigitalDisplayData(user.username, deviceId, from, to);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "android_sense":
|
|
|
|
case "android_sense":
|
|
|
|
result = getAndroidSenseData(user.username, deviceId, from, to);
|
|
|
|
result = getAndroidSenseData(user.username, deviceId, from, to);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "raspberrypi":
|
|
|
|
case "raspberrypi":
|
|
|
|
result = getDigitalDisplayData(user.username, deviceId, from, to);
|
|
|
|
result = getDigitalDisplayData(user.username, deviceId, from, to);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
result = new Object();
|
|
|
|
result = new Object();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// returning the result.
|
|
|
|
// returning the result.
|
|
|
|
if (result) {
|
|
|
|
if (result) {
|
|
|
|
print(result);
|
|
|
|
print(result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getFireAlarmData(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);
|
|
|
|
result['cpuTemperatureData'] = getSensorData("DEVICE_CPU_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to);
|
|
|
|
result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY","status",user, deviceId, from, to);
|
|
|
|
result['temperatureData'] = getSensorData("DEVICE_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to);
|
|
|
|
result['bulbData'] = getSensorData("DEVICE_BULB_USAGE_SUMMARY","status",user, deviceId, from, to);
|
|
|
|
result['fanData'] = getSensorData("DEVICE_FAN_USAGE_SUMMARY", "status", user, deviceId, from, to);
|
|
|
|
return result;
|
|
|
|
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);
|
|
|
|
result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to);
|
|
|
|
result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, deviceId, from, to);
|
|
|
|
result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_SUMMARY","light",user, deviceId, from, to);
|
|
|
|
result['lightData'] = getSensorData("LDR_LIGHT_SENSOR_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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getArduinoData(user, deviceId, from, to){
|
|
|
|
function getArduinoData(user, deviceId, from, to) {
|
|
|
|
result = new Object();
|
|
|
|
result = new Object();
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getDigitalDisplayData(user, deviceId, from, to){
|
|
|
|
function getAndroidSenseData(user, deviceId, from, to) {
|
|
|
|
result = new Object();
|
|
|
|
result = new Object();
|
|
|
|
result['ramData'] = getSensorData("RAM_USAGE_SUMMARY","motion",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['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;
|
|
|
|
result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY", "motion", user, deviceId, from, to);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getAndroidSenseData(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['ramData'] = getSensorData("RAM_USAGE_SUMMARY", "motion", user, deviceId, from, to);
|
|
|
|
result['cpuData'] = getSensorData("CPU_LOAD_SUMMARY","light",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['cpuTemperatureData'] = getSensorData("DEVICE_CPU_TEMPERATURE_SUMMARY", "TEMPERATURE", user, deviceId, from, to);
|
|
|
|
result['motionData'] = getSensorData("PIR_MOTION_SENSOR_SUMMARY","motion",user, deviceId, from, to);
|
|
|
|
return result;
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function getDigitalDisplayData(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);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function getSensorData(table, column, user, deviceId, from, to) {
|
|
|
|
function getSensorData(table, column, user, deviceId, from, to) {
|
|
|
|
|
|
|
|
|
|
|
|
var fetchedData = null;
|
|
|
|
var fetchedData = null;
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to);
|
|
|
|
fetchedData = statsClient.getDeviceStats(table, column, user, deviceId, from, to);
|
|
|
|
}catch(error){
|
|
|
|
} catch (error) {
|
|
|
|
log.error(error);
|
|
|
|
log.error(error);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var sensorData = [];
|
|
|
|
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++) {
|
|
|
|
sensorData.push({
|
|
|
|
sensorData.push({
|
|
|
|
time: fetchedData.get(i).getTime(),
|
|
|
|
time: fetchedData.get(i).getTime(),
|
|
|
|
value: fetchedData.get(i).getValue()
|
|
|
|
value: fetchedData.get(i).getValue()
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return sensorData;
|
|
|
|
return sensorData;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
%>
|
|
|
|
%>
|