Merge pull request #786 from lasanthaDLPDS/master

Fixing wso2/product-iots/issues#1242
revert-dabc3590
Madhawa Perera 7 years ago committed by GitHub
commit 8ac016f30f

@ -20,29 +20,43 @@ function onRequest(context) {
var log = new Log("stats.js");
var carbonServer = require("carbon").server;
var device = context.unit.params.device;
// graph configuration
var graphData = {
Sensors:["accelerometer","magnetic", "gravity", "pressure", "proximity", "gyroscope"],
Realtime_Data:['battery','light','rotation']
};
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
var constants = require("/app/modules/constants.js");
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
var websocketEndpoint = devicemgtProps["wssURL"].replace("https", "wss");
var jwtService = carbonServer.osgiService(
'org.wso2.carbon.identity.jwt.client.extension.service.JWTClientManagerService');
var jwtClient = jwtService.getJWTClient();
var encodedClientKeys = session.get(constants["ENCODED_TENANT_BASED_WEB_SOCKET_CLIENT_CREDENTIALS"]);
var token = "";
var tokenPair = null;
var user = userModule.getCarbonUser();
var tenantDomain = user.domain;
if (encodedClientKeys) {
var tokenUtil = require("/app/modules/oauth/token-handler-utils.js")["utils"];
var resp = tokenUtil.decode(encodedClientKeys).split(":");
var tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {});
if (tokenPair) {
token = tokenPair.accessToken;
if (tenantDomain == "carbon.super") {
tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username,"default", {});
if (tokenPair) {
token = tokenPair.accessToken;
}
websocketEndpoint = websocketEndpoint + "/secured-websocket/org.wso2.iot.android.sense/1.0.0?" +
"deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
} else {
tokenPair = jwtClient.getAccessToken(resp[0], resp[1], context.user.username + "@" + tenantDomain,"default", {});
if (tokenPair) {
token = tokenPair.accessToken;
}
websocketEndpoint = websocketEndpoint + "/secured-websocket/t/"+tenantDomain+"/org.wso2.iot.android.sense/1.0.0?" +
"deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
}
websocketEndpoint = websocketEndpoint + "/secured-websocket/org.wso2.iot.android.sense/1.0.0?" +
"deviceId=" + device.deviceIdentifier + "&deviceType=" + device.type + "&websocketToken=" + token;
}
return {"device": device, "websocketEndpoint": websocketEndpoint, "graphData":graphData};
}

@ -158,6 +158,15 @@ function threeDlineGraph(type, xChartData, yChartData, zChartData) {
graph: graph
});
new Rickshaw.Graph.HoverDetail({
graph: graph,
formatter: function (series, x, y) {
var date = '<span class="date">' + moment(x * 1000).format('Do MMM YYYY h:mm:ss a') + '</span>';
var swatch = '<span class="detail_swatch" style="background-color: ' + series.color + '"></span>';
return swatch + series.name + ": " + parseInt(y) + '<br>' + date;
}
});
graph.render();
return graph;
@ -234,58 +243,61 @@ function connect(target) {
if (ws) {
ws.onmessage = function (event) {
var dataPoint = JSON.parse(event.data);
if (dataPoint) {
var time = parseInt(dataPoint[4]) / 1000;
switch (dataPoint[typeId]) {
case "battery":
graphUpdate(batteryData, time, dataPoint[batteryId], graphMap["battery"]);
graphUpdate(batteryData, time, dataPoint[batteryId]);
graphMap["battery"].update();
break;
case "light":
graphUpdate(lightData, time, dataPoint[lightId], graphMap["light"]);
graphUpdate(lightData, time, dataPoint[lightId]);
graphMap["light"].update();
break;
case "pressure":
graphUpdate(pressureData, time, dataPoint[pressureId], graphMap["pressure"]);
graphUpdate(pressureData, time, dataPoint[pressureId]);
graphMap["pressure"].update();
break;
case "proximity":
graphUpdate(proximityData, time, dataPoint[proximityId], graphMap["proximity"]);
graphUpdate(proximityData, time, dataPoint[proximityId]);
graphMap["proximity"].update();
break;
case "accelerometer":
dataUpdate(accelerometer_xData, time, dataPoint[accelerometer_xId]);
dataUpdate(accelerometer_yData, time, dataPoint[accelerometer_yId]);
dataUpdate(accelerometer_zData, time, dataPoint[accelerometer_zId]);
graphUpdate(accelerometer_xData, time, dataPoint[accelerometer_xId]);
graphUpdate(accelerometer_yData, time, dataPoint[accelerometer_yId]);
graphUpdate(accelerometer_zData, time, dataPoint[accelerometer_zId]);
graphMap["accelerometer"].update();
break;
case "magnetic":
dataUpdate(magnetic_xData, time, dataPoint[magnetic_xId]);
dataUpdate(magnetic_yData, time, dataPoint[magnetic_yId]);
dataUpdate(magnetic_zData, time, dataPoint[magnetic_zId]);
graphUpdate(magnetic_xData, time, dataPoint[magnetic_xId]);
graphUpdate(magnetic_yData, time, dataPoint[magnetic_yId]);
graphUpdate(magnetic_zData, time, dataPoint[magnetic_zId]);
graphMap["magnetic"].update();
break;
case "gyroscope":
dataUpdate(gyroscope_xData, time, dataPoint[gyroscope_xId]);
dataUpdate(gyroscope_yData, time, dataPoint[gyroscope_yId]);
dataUpdate(gyroscope_zData, time, dataPoint[gyroscope_zId]);
graphUpdate(gyroscope_xData, time, dataPoint[gyroscope_xId]);
graphUpdate(gyroscope_yData, time, dataPoint[gyroscope_yId]);
graphUpdate(gyroscope_zData, time, dataPoint[gyroscope_zId]);
graphMap["gyroscope"].update();
break;
case "rotation":
dataUpdate(magnetic_xData, time, dataPoint[rotation_xId]);
dataUpdate(magnetic_yData, time, dataPoint[rotation_yId]);
dataUpdate(magnetic_zData, time, dataPoint[rotation_zId]);
graphUpdate(magnetic_xData, time, dataPoint[rotation_xId]);
graphUpdate(magnetic_yData, time, dataPoint[rotation_yId]);
graphUpdate(magnetic_zData, time, dataPoint[rotation_zId]);
graphMap["rotation"].update();
break;
case "gravity":
dataUpdate(gravity_xData, time, dataPoint[gravity_xId]);
dataUpdate(gravity_yData, time, dataPoint[gravity_yId]);
dataUpdate(gravity_zData, time, dataPoint[gravity_zId]);
graphUpdate(gravity_xData, time, dataPoint[gravity_xId]);
graphUpdate(gravity_yData, time, dataPoint[gravity_yId]);
graphUpdate(gravity_zData, time, dataPoint[gravity_zId]);
graphMap["gravity"].update();
break;
}
@ -294,16 +306,7 @@ function connect(target) {
}
}
function graphUpdate(chartData, xValue, yValue, graph) {
chartData.push({
x: parseInt(xValue),
y: parseFloat(yValue)
});
chartData.shift();
graph.update();
}
function dataUpdate(chartData, xValue, yValue) {
function graphUpdate(chartData, xValue, yValue) {
chartData.push({
x: parseInt(xValue),
y: parseFloat(yValue)

Loading…
Cancel
Save