From 096bade36b619117300bc5357a82c817a5855521 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Sun, 24 Jan 2016 17:41:23 +0530 Subject: [PATCH 1/3] bug fixed --- .../api/impl/DroneControllerService.java | 23 ++--- .../api/impl/DroneRealTimeService.java | 24 +++-- .../transport/DroneAnalyzerXMPPConnector.java | 47 +++++----- .../impl/trasformer/MessageTransformer.java | 53 +++++------ .../impl/util/DroneAnalyzerServiceUtils.java | 52 ++++------- ...oneAnalyzerManagementServiceComponent.java | 2 - .../src/main/resources/agent/src/util.py | 1 + .../main/resources/agent/src/xmppClient.py | 6 +- .../src/main/resources/agent/start_service.sh | 2 +- .../public/css/main-app.css | 49 +++++++++++ .../public/js/config/config.js | 4 +- .../public/js/mainHandler | 2 +- .../public/js/modules/flight_dynamics.js | 12 ++- .../statistics.hbs | 88 +------------------ 14 files changed, 155 insertions(+), 210 deletions(-) diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java index 5df17dde2..278df4079 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java @@ -29,13 +29,8 @@ import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.impl.DroneControllerImpl; -import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.Response; import java.util.concurrent.ConcurrentHashMap; @@ -57,11 +52,10 @@ public class DroneControllerService { --------------------------------------------------------------------------------------- */ @Path("controller/register/{owner}/{deviceId}/{ip}/{port}") @POST - public String registerDeviceIP(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId, + public Response registerDeviceIP(@PathParam("owner") String owner, @PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, @PathParam("port") String devicePort, - @Context HttpServletResponse response, - @Context HttpServletRequest request) { + @Context HttpServletResponse response) { String result; log.info("Got register call from IP: " + deviceIP + " for Device ID: " + deviceId + " of owner: " + owner); String deviceHttpEndpoint = deviceIP + ":" + devicePort; @@ -72,17 +66,16 @@ public String registerDeviceIP(@PathParam("owner") String owner, @PathParam("dev log.debug(result); } log.info(owner + deviceId + deviceIP + devicePort ); - return result; - + return Response.ok(Response.Status.OK.getStatusCode()).build(); } @Path("controller/send_command") @POST - @Feature( code="send_command", name="Send Command", type="operation", - description="Send Commands to Drone") + /*@Feature( code="send_command", name="Send Command", type="operation", + description="Send Commands to Drone")*/ public Response droneController(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, - @QueryParam("action") String action, @QueryParam("duration") String duration, - @QueryParam("speed") String speed){ + @FormParam("action") String action, @FormParam("duration") String duration, + @FormParam("speed") String speed){ try { DeviceValidator deviceValidator = new DeviceValidator(); if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId, diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java index 4c239998b..2fa265164 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneRealTimeService.java @@ -38,8 +38,7 @@ public class DroneRealTimeService { public DroneRealTimeService() { messageController = new MessageTransformer(); xmppConnector = new DroneAnalyzerXMPPConnector(messageController); - - if (XmppConfig.getInstance().isEnabled()){ + if (!XmppConfig.getInstance().isEnabled()){ xmppConnector.connect(); } else { log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, DroneAnalyzerXMPPConnector not started."); @@ -58,24 +57,23 @@ public void onOpen(Session session){ @OnMessage public void onMessage(String message, Session session){ - try { while(true){ - if((messageController !=null) && (!messageController.isEmptyQueue())){ - String message1 = messageController.getMessage(); - session.getBasicRemote().sendText(message1); + try{ + if((messageController !=null) && (!messageController.isEmptyQueue())){ + String message1 = messageController.getMessage(); + session.getBasicRemote().sendText(message1); + } + Thread.sleep(DroneConstants.MINIMUM_TIME_DURATION); + } catch (IOException ex) { + log.error(ex.getMessage() + "\n" + ex); + } catch (InterruptedException e) { + log.error(e.getMessage(), e); } - Thread.sleep(DroneConstants.MINIMUM_TIME_DURATION); } - } catch (IOException ex) { - log.error(ex.getMessage() + "\n" + ex); - } catch (InterruptedException e) { - log.error(e.getMessage(), e); - } } @OnClose public void onClose(Session session){ - try { xmppConnector.disconnect(); log.info("XMPP connection is disconnected"); diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java index 6a9038697..90f42adec 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/transport/DroneAnalyzerXMPPConnector.java @@ -35,33 +35,29 @@ public class DroneAnalyzerXMPPConnector extends XMPPTransportHandler { private static Log log = LogFactory.getLog(DroneAnalyzerXMPPConnector.class); private static String xmppServerIP; - private static int xmppServerPort; private static String xmppAdminUsername; private static String xmppAdminPassword; private static String xmppAdminAccountJID; private MessageTransformer messageTransformer; - private ScheduledFuture connectorServiceHandler; private ScheduledExecutorService service = Executors.newSingleThreadScheduledExecutor(); public DroneAnalyzerXMPPConnector(MessageTransformer messageTransformer) { - super(XmppConfig.getInstance().getXmppServerIP(), - XmppConfig.getInstance().getSERVER_CONNECTION_PORT()); + super(XmppConfig.getInstance().getXmppServerIP(),XmppConfig.getInstance().getSERVER_CONNECTION_PORT()); this.messageTransformer = messageTransformer; - } @Override public void connect() { Runnable connector = new Runnable() { + @Override public void run() { if (!isConnected()) { try { initConnector(); connectToServer(); loginToServer(xmppAdminUsername, xmppAdminPassword, null); - setFilterOnReceiver(DroneConstants.DEVICE_ID+ "@" + xmppServerIP); - + setFilterOnReceiver(xmppAdminAccountJID); } catch (TransportHandlerException e) { if (log.isDebugEnabled()) { log.warn("Connection/Login to XMPP server at: " + server + " as " + @@ -84,18 +80,28 @@ public void initConnector() { @Override public void processIncomingMessage(Message message) throws TransportHandlerException { - String from = message.getFrom(); - String subject = message.getSubject(); - String inbound_message = message.getBody(); - int indexOfAt = from.indexOf("@"); - int indexOfSlash = from.indexOf("/"); - String deviceId = from.substring(0, indexOfAt); - String resource = from.substring(indexOfSlash + 1, from.length()); - - if ((inbound_message != null)&&(resource.equals(DroneConstants.MESSAGE_RESOURCE)) ){ - messageTransformer.messageTranslater(inbound_message); - } else { - log.error("Message is empty or it is not belongs to "+ DroneConstants.DEVICE_ID); + try{ + String from = message.getFrom(); + String inbound_message = message.getBody(); + int indexOfSlash = from.indexOf("/"); + if(indexOfSlash==0){ + if(log.isDebugEnabled()){ + log.debug("Required resource not available."); + } + }else{ + String resource = from.substring(indexOfSlash + 1, from.length()); + if ((inbound_message != null)&&(resource.equals(DroneConstants.MESSAGE_RESOURCE)) ){ + messageTransformer.messageTranslater(inbound_message); + } else { + if(log.isDebugEnabled()){ + log.debug("Message is empty or it is not belongs to " + xmppAdminUsername); + } + } + } + }catch(ArrayIndexOutOfBoundsException e){ + log.error("Wrong message format: input message", e); + }catch(RuntimeException e){ + log.error("Unexpected error has been occurred, ", e); } } @@ -117,18 +123,15 @@ public void run() { log.warn("Unable to 'STOP' connection to XMPP server at: " + server + " for user - " + xmppAdminUsername); } - try { Thread.sleep(timeoutInterval); } catch (InterruptedException e1) { log.error("XMPP-Terminator: Thread Sleep Interrupt Exception for " + DroneConstants.DEVICE_TYPE + " type.", e1); } - } } }; - Thread terminatorThread = new Thread(stopConnection); terminatorThread.setDaemon(true); terminatorThread.start(); diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java index 07ed89876..74d080771 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/trasformer/MessageTransformer.java @@ -35,11 +35,11 @@ public class MessageTransformer { private Log log = LogFactory.getLog(MessageTransformer.class); private CircularFifoQueue sharedQueue; - private String outbound_message_format_for_simulator = "{\"quatanium_val\":[%f, %f, %f, %f]," + - "\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f, \"device_type\":\"IRIS_DRONE\"}"; - private String outbound_message_format_for_iris_drone = "{\"quatanium_val\":[%f, %f, %f]," + + private String outboundMessageFormatForSimulator = "{\"quatanium_val\":[%f, %f, %f, %f]," + + "\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f, \"device_type\":\"SIMULATOR\"}"; + private String outboundMessageFormatForIrisDrone = "{\"quatanium_val\":[%f, %f, %f]," + "\"basicParam\":{\"velocity\":[%f, %f, %f], \"global_location\":[%f, %f, %f]},\"battery_level\":%f," + - "\"device_type\":\"SIMULATOR\"}"; + "\"device_type\":\"IRIS_DRONE\"}"; public MessageTransformer(){ sharedQueue = new CircularFifoQueue(DroneConstants.MAXIMUM_BUFFERE_SIZE_OF_SHARED_QUEUE); @@ -47,19 +47,18 @@ public MessageTransformer(){ private void messageTranslaterForSimulator(JsonNode inbound_message){ JsonNode node = inbound_message; - String outbound_message; - + String outboundMessage; try { JsonNode velocity = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(MessageConfig.OUT_BASIC_PARAM_VELOCITY); - JsonNode global_location = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get( + JsonNode globalLocation = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get( MessageConfig.OUT_BASIC_PARAM_GLOBAL_LOCATION); - JsonNode quatanium_vals = node.get(MessageConfig.OUT_QUATANNIM_VAL); - JsonNode battery_level = node.get(MessageConfig.OUT_BATTERY_LEVEL); - outbound_message = String.format(outbound_message_format_for_simulator, sTd(quatanium_vals.get(0)), - sTd(quatanium_vals.get(1)), sTd(quatanium_vals.get(2)), sTd(quatanium_vals.get(0)), - sTd(velocity.get(0)), sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(global_location.get(0)), - sTd(global_location.get(1)), sTd(global_location.get(2)), sTd(battery_level)); - sharedQueue.add(outbound_message); + JsonNode quataniumVals = node.get(MessageConfig.OUT_QUATANNIM_VAL); + JsonNode batteryLevel = node.get(MessageConfig.OUT_BATTERY_LEVEL); + outboundMessage = String.format(outboundMessageFormatForSimulator, sTd(quataniumVals.get(0)), + sTd(quataniumVals.get(1)), sTd(quataniumVals.get(2)), sTd(quataniumVals.get(0)), + sTd(velocity.get(0)), sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(globalLocation.get(0)), + sTd(globalLocation.get(1)), sTd(globalLocation.get(2)), sTd(batteryLevel)); + sharedQueue.add(outboundMessage); } catch (Exception e) { log.error(e.getMessage()+",\n"+ e); } @@ -67,19 +66,19 @@ private void messageTranslaterForSimulator(JsonNode inbound_message){ private void messageTranslaterForIRISDrone(JsonNode inbound_message){ JsonNode node = inbound_message; - String outbound_message; + String outboundMessage; try { JsonNode velocity = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get(MessageConfig.OUT_BASIC_PARAM_VELOCITY); - JsonNode global_location = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get( + JsonNode globalLocation = node.get(MessageConfig.OUT_BASIC_PARAM_VAL).get( MessageConfig.OUT_BASIC_PARAM_GLOBAL_LOCATION); - JsonNode quatanium_vals = node.get(MessageConfig.OUT_QUATANNIM_VAL); - JsonNode battery_level = node.get(MessageConfig.OUT_BATTERY_LEVEL); - outbound_message = String.format(outbound_message_format_for_iris_drone, sTd(quatanium_vals.get(0)), - sTd(quatanium_vals.get(1)), sTd(quatanium_vals.get(2)), sTd(velocity.get(0)), - sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(global_location.get(0)), - sTd(global_location.get(1)), sTd(global_location.get(2)), sTd(battery_level)); - sharedQueue.add(outbound_message); + JsonNode quataniumVals = node.get(MessageConfig.OUT_QUATANNIM_VAL); + JsonNode batteryLevel = node.get(MessageConfig.OUT_BATTERY_LEVEL); + outboundMessage = String.format(outboundMessageFormatForIrisDrone, sTd(quataniumVals.get(0)), + sTd(quataniumVals.get(1)), sTd(quataniumVals.get(2)), sTd(velocity.get(0)), + sTd(velocity.get(1)), sTd(velocity.get(2)), sTd(globalLocation.get(0)), + sTd(globalLocation.get(1)), sTd(globalLocation.get(2)), sTd(batteryLevel)); + sharedQueue.add(outboundMessage); }catch (Exception e) { log.error(e.getMessage()+",\n"+ e); @@ -87,20 +86,22 @@ private void messageTranslaterForIRISDrone(JsonNode inbound_message){ } public void messageTranslater(String inbound_message){ - JsonNode actualMessage = null; + JsonNode actualMessage; ObjectMapper objectMapper = new ObjectMapper(); - try { actualMessage = objectMapper.readValue(inbound_message, JsonNode.class); JsonNode deviceType = actualMessage.get(MessageConfig.IN_DEVICE_TYPE); switch (deviceType.getTextValue()) { - case MessageConfig.IN_IRIS_DRONE: messageTranslaterForIRISDrone(actualMessage); break; case MessageConfig.IN_SIMULATOR: messageTranslaterForSimulator(actualMessage); break; + default: + if(log.isDebugEnabled()){ + log.debug("Wrong message format"); + } } } catch (JsonProcessingException e) { log.error("Incoming message might be corrupted, "+ e); diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java index fa507a4a0..02af8a808 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java @@ -19,16 +19,14 @@ package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.util; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.constants.DroneConstants; import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.controller.DroneController; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.exception.DroneAnalyzerException; -import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector; import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException; import java.io.File; @@ -46,8 +44,7 @@ public static void sendCommandViaXMPP(String deviceOwner, String deviceId, Strin String xmppServerDomain = XmppConfig.getInstance().getXmppEndpoint(); int indexOfChar = xmppServerDomain.lastIndexOf(File.separator); if (indexOfChar != -1) { - xmppServerDomain = xmppServerDomain.substring((indexOfChar + 1), - xmppServerDomain.length()); + xmppServerDomain = xmppServerDomain.substring((indexOfChar + 1), xmppServerDomain.length()); } indexOfChar = xmppServerDomain.indexOf(":"); if (indexOfChar != -1) { @@ -58,43 +55,47 @@ public static void sendCommandViaXMPP(String deviceOwner, String deviceId, Strin droneXMPPConnector.publishDeviceData(clientToConnect, message, "CONTROL-REQUEST"); } - public static boolean sendControlCommand(DroneController controller, String deviceId, String action, double speed, double duration) + public static boolean sendControlCommand(DroneController controller, String deviceId, String action, + double speed, double duration) throws DeviceManagementException { - boolean control_state = false; + boolean controlState = false; try{ switch (action){ case DroneConstants.TAKE_OFF: - control_state = controller.takeoff(); + controlState = controller.takeoff(); break; case DroneConstants.LAND: - control_state = controller.land(); + controlState = controller.land(); break; case DroneConstants.BACK: - control_state = controller.back(speed, duration); + controlState = controller.back(speed, duration); break; case DroneConstants.CLOCK_WISE: - control_state = controller.clockwise(speed, duration); + controlState = controller.clockwise(speed, duration); break; case DroneConstants.COUNTER_CLOCKWISE: - control_state = controller.conterClockwise(speed, duration); + controlState = controller.conterClockwise(speed, duration); break; case DroneConstants.DOWN: - control_state = controller.down(speed, duration); + controlState = controller.down(speed, duration); break; case DroneConstants.FRONT: - control_state = controller.back(speed, duration); + controlState = controller.back(speed, duration); break; case DroneConstants.FORWARD: - control_state = controller.clockwise(speed, duration); + controlState = controller.clockwise(speed, duration); break; case DroneConstants.UP: - control_state = controller.up(speed, duration); + controlState = controller.up(speed, duration); + break; + default: + log.error("Invalid command"); break; } }catch(Exception e){ log.error(e.getMessage()+ "\n"+ e); } - return control_state; + return controlState; } public static boolean publishToDAS(String owner, String deviceId, float temperature) { @@ -117,21 +118,4 @@ public static boolean publishToDAS(String owner, String deviceId, float temperat } return true; } - - public static CertificateManagementService getCertificateManagementService() throws - DroneAnalyzerException { - - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - CertificateManagementService certificateManagementService = (CertificateManagementService) - ctx.getOSGiService(CertificateManagementService.class, null); - - if (certificateManagementService == null) { - String msg = "EnrollmentService is not initialized"; - log.error(msg); - throw new DroneAnalyzerException(msg); - } - - return certificateManagementService; - } - } diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/plugin/internal/DroneAnalyzerManagementServiceComponent.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/plugin/internal/DroneAnalyzerManagementServiceComponent.java index 473502f4c..43ca53433 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/plugin/internal/DroneAnalyzerManagementServiceComponent.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/plugin/internal/DroneAnalyzerManagementServiceComponent.java @@ -27,8 +27,6 @@ import org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.impl.DroneAnalyzerManagerService; import org.wso2.carbon.device.mgt.iot.service.DeviceTypeService; - - /** * @scr.component name="org.wso2.carbon.device.mgt.iot.droneanalyzer.plugin.internal * .DroneAnalyzerManagementServiceComponent" diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/util.py b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/util.py index c0398d022..33a84fea7 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/util.py +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/util.py @@ -33,6 +33,7 @@ DEVICE_ID = configParser.get('Device-Configurations', 'deviceId') XMPP_EP = configParser.get('Device-Configurations', 'xmpp-ep') AUTH_TOKEN = configParser.get('Device-Configurations', 'auth-token') +DEVICE_PASSWORD = configParser.get('Device-Configurations', 'auth-token') CONTROLLER_CONTEXT = configParser.get('Device-Configurations', 'controller-context') HTTPS_EP = configParser.get('Device-Configurations', 'https-ep') HTTP_EP = configParser.get('Device-Configurations', 'http-ep') diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/xmppClient.py b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/xmppClient.py index 5bcfd5893..30434d601 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/xmppClient.py +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/src/xmppClient.py @@ -23,9 +23,9 @@ XMPP_ENDPOINT = util.XMPP_EP.split(":") XMPP_IP = XMPP_ENDPOINT[1].replace('//', '') XMPP_PORT = int(XMPP_ENDPOINT[2]) -MESSAGE_TO = "admin" -XMPP_OWN = util.DEVICE_OWNER -XMPP_PWD = util.DEVICE_ID +MESSAGE_TO = util.DEVICE_OWNER +XMPP_PWD = util.DEVICE_PASSWORD +XMPP_OWN = util.DEVICE_ID XMPP_RESOURCE = "drone_current_status" XMPP_JID = MESSAGE_TO + "@" + XMPP_IP + "/" + XMPP_RESOURCE diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/start_service.sh b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/start_service.sh index fccb16dcf..80b059103 100755 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/start_service.sh +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/agent/start_service.sh @@ -66,7 +66,7 @@ while true; do done cp deviceConfig.properties ./src -./src/IRIS+DroneStatistics.py -i $push_interval -b $baud -c $connection_target +python ./src/IRIS+DroneStatistics.py -i $push_interval -b $baud -c $connection_target if [ $? -ne 0 ]; then echo "Could not start the service..." diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/css/main-app.css b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/css/main-app.css index 98b5f3049..17a518d20 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/css/main-app.css +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/css/main-app.css @@ -169,3 +169,52 @@ .navbar { border-radius: 0; } +.circle { + background: none repeat scroll 0 0 #191919; + border-radius: 50px; + height: 50px; + padding: 10px; + width: 50px; + color: #fff; +} + +.padding-top-double { + padding-top: 20px; +} +.padding-double { + padding: 20px; +} +.grey { + color: #333; +} +hr { + display: block; + height: 1px; + border: 0; + border-top: 1px solid #7f7f7f; + margin: 1em 0; + padding: 0; + opacity: 0.2; +} +.light-grey { + color: #7c7c7c; +} +.uppercase { + text-transform: uppercase; +} +.grey-bg { + background-color: #f6f4f4; +} + +path { + stroke: black; + stroke-width: 2; + fill: none; +} + +.axis path, .axis line { + fill: none; + stroke: #ccc; + stroke-width: 2; + shape-rendering: crispEdges; +} diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js index 1b472786c..b4e93125c 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js @@ -20,7 +20,7 @@ var config_api = function () { var config_api = this; var domain = "localhost"; var port = "9793"; - var context_controller = "/drone_analyzer/DroneAnalyzerServiceUnitManager/controller/send_command"; + var context_controller = "/drone_analyzer/controller/send_command"; config_api.config_3dobject_holder = "#virtualDrone"; config_api.realtime_plotting_update_interval = 30; config_api.realtime_plotting_totalPoints = 30; @@ -29,7 +29,7 @@ var config_api = function () { config_api.drone_control = "http://" + domain + ":" + port + "/" + context_controller; config_api.drone_controlType = "POST"; config_api.drone_controlDataType = "json"; - config_api.web_socket_endpoint = "ws://localhost:9763/drone_analyzer/datastream/drone_status"; + config_api.web_socket_endpoint = "wss://localhost:9443/drone_analyzer/datastream/drone_status"; config_api.modules_status = { "realtimePlotting": false, "sensorReadings": false, diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler index ffe2636ee..e96eb3427 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler @@ -16,7 +16,7 @@ * under the License. */ -object_maker.init(config_api.config_3dobject_holder, $("#objectHolder").width(), $("#objectHolder").width()/2); +object_maker.init(config_api.config_3dobject_holder, $("#objectHolder").width(), $("#objectHolder").width()/1.5); object_maker.animate(); var flight_dynamics = new flight_dynamics(); $("#window_size").slider({ diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/flight_dynamics.js b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/flight_dynamics.js index 926fec902..4616cacf8 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/flight_dynamics.js +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/flight_dynamics.js @@ -15,32 +15,30 @@ * specific language governing permissions and limitations * under the License. */ + var flight_dynamics = function () { var api = this; api.processingMessage = function (sender_message) { - - JSON.stringify(sender_message); - + if(sender_message.battery_level!= undefined){ + $("#battery_level_holder").width( parseInt(sender_message.battery_level)+"%" ); + $("#battery_level").html(sender_message.battery_level+"%"); + } if (sender_message.quatanium_val != undefined) { current_status = object_maker.get_heading_attitude_bank(sender_message.quatanium_val); object_maker.set_heading_attitude_bank(current_status); $("#imageTop").animate({rotate: '' + (180 / Math.PI) * 2.890456 + 'deg'}, 2); } - - $("#imageTop").delay(2).animate({rotate: '45deg'}, 2); if (config_api.modules_status.angleOfRotation_2 || config_api.modules_status.angleOfRotation_1) { console.log(JSON.stringify(current_status)); object_maker.set_bank("#imageTop", current_status.bank); object_maker.set_heading("#imageBackSecond", current_status.heading); } - if (config_api.modules_status.realtimePlotting) { if (current_status[$('#plotting_attribute').val()] != undefined) { plotting.pushData(current_status[$('#plotting_attribute').val()]); } } - if (sender_message.basicParam != undefined) { if (sender_message.basicParam.velocity != undefined) { var velocity = sender_message.basicParam.velocity; diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs index 27176171c..a4404ee87 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs @@ -1,57 +1,5 @@ {{#zone "topCss"}} {{css "css/main-app.css" }} - {{/zone}}
@@ -69,8 +17,8 @@
- 0% + aria-valuemax="100" style="width: 0%;" id="battery_level_holder"> +

0%

@@ -84,12 +32,8 @@

Controller

- -
@@ -150,12 +94,8 @@

Angle of Rotation

- -
@@ -170,12 +110,8 @@
- -
@@ -196,12 +132,8 @@
- -
@@ -224,12 +156,8 @@

Live Video Stream

- -
@@ -248,20 +176,16 @@

Sensor Readings

- -
-

Location latitude:
+

Location
latitude:
longitude:
altitudes:

-

Velocity: x :
+

Velocity:
x :
y :
z :

Battery Voltage:

@@ -275,12 +199,8 @@

Realtime Plotting

- -
From 7037dd99a8e0f582126102fa1c1ffb4af6093acb Mon Sep 17 00:00:00 2001 From: GPrathap Date: Sun, 24 Jan 2016 17:49:31 +0530 Subject: [PATCH 2/3] bug fixed --- .../api/impl/DroneControllerService.java | 1 - .../impl/util/DroneAnalyzerServiceUtils.java | 25 ------------------- 2 files changed, 26 deletions(-) diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java index 278df4079..fbfa4da3c 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/DroneControllerService.java @@ -20,7 +20,6 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.device.DeviceType; -import org.wso2.carbon.apimgt.annotations.device.feature.Feature; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.DeviceValidator; diff --git a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java index 02af8a808..0b6a3abff 100644 --- a/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java +++ b/components/device-mgt-iot-droneanalyzer/org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api/src/main/java/org/wso2/carbon/device/mgt/iot/droneanalyzer/controller/api/impl/util/DroneAnalyzerServiceUtils.java @@ -19,9 +19,6 @@ package org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.util; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.analytics.exception.DataPublisherConfigurationException; -import org.wso2.carbon.device.mgt.analytics.service.DeviceAnalyticsService; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig; import org.wso2.carbon.device.mgt.iot.droneanalyzer.controller.api.impl.transport.DroneAnalyzerXMPPConnector; @@ -34,7 +31,6 @@ public class DroneAnalyzerServiceUtils { private static final String SUPER_TENANT = "carbon.super"; - private static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; private static org.apache.commons.logging.Log log = LogFactory.getLog(DroneAnalyzerServiceUtils.class); public static void sendCommandViaXMPP(String deviceOwner, String deviceId, String resource, @@ -97,25 +93,4 @@ public static boolean sendControlCommand(DroneController controller, String devi } return controlState; } - - public static boolean publishToDAS(String owner, String deviceId, float temperature) { - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - ctx.setTenantDomain(SUPER_TENANT, true); - DeviceAnalyticsService deviceAnalyticsService = (DeviceAnalyticsService) ctx.getOSGiService( - DeviceAnalyticsService.class, null); - Object metdaData[] = {owner, DroneConstants.DEVICE_TYPE, deviceId, - System.currentTimeMillis()}; - Object payloadData[] = {temperature}; - - try { - deviceAnalyticsService.publishEvent(TEMPERATURE_STREAM_DEFINITION, "1.0.0", metdaData, - new Object[0], payloadData); - } catch (DataPublisherConfigurationException e) { - return false; - } finally { - PrivilegedCarbonContext.endTenantFlow(); - } - return true; - } } From 86530bc374921cec48cb3fb32679538af98a6250 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Sun, 24 Jan 2016 23:26:51 +0530 Subject: [PATCH 3/3] changed the way server address is taken --- .../public/js/config/config.js | 8 +-- .../public/js/mainHandler | 55 +++++++++++-------- .../public/js/modules/controller.js | 2 +- .../statistics.hbs | 8 +-- .../statistics.js | 29 ++-------- 5 files changed, 45 insertions(+), 57 deletions(-) diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js index b4e93125c..028695ee6 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/config/config.js @@ -15,21 +15,19 @@ * specific language governing permissions and limitations * under the License. */ -//TODO this needs to a private resource + var config_api = function () { var config_api = this; - var domain = "localhost"; - var port = "9793"; var context_controller = "/drone_analyzer/controller/send_command"; config_api.config_3dobject_holder = "#virtualDrone"; config_api.realtime_plotting_update_interval = 30; config_api.realtime_plotting_totalPoints = 30; config_api.realtime_plotting_data_window = {}; config_api.effectController = {uy: 70.0, uz: 15.0, ux: 10.0, fx: 2.0, fz: 15.0, Tmax: 1}; - config_api.drone_control = "http://" + domain + ":" + port + "/" + context_controller; + config_api.drone_control = context_controller; config_api.drone_controlType = "POST"; config_api.drone_controlDataType = "json"; - config_api.web_socket_endpoint = "wss://localhost:9443/drone_analyzer/datastream/drone_status"; + config_api.web_socket_endpoint = "/drone_analyzer/datastream/drone_status"; config_api.modules_status = { "realtimePlotting": false, "sensorReadings": false, diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler index e96eb3427..28199109a 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/mainHandler @@ -58,7 +58,6 @@ $('.btn-minimize').click(function (e) { if ($target.is(':visible')) { if ($(this).parent().attr('id') === "RealtimePlotting") { plotting.forceToRedraw(function (status) { - d3.select("#realtimechart").select("svg").remove(); plotting.realtime_plotting("#realtimechart", "#range_min", "#range_max", "#window_update_value", 600, $("#realtimechart").height(), "#window_size_current_value", @@ -71,33 +70,40 @@ $('.btn-minimize').click(function (e) { $('#connectionOpen').on('click', function () { $('#connectionOpen').toggleClass('active'); }); - - $("#xmppConnectionOpen").on('click', function () { $('#xmppConnectionOpen').toggleClass('active'); if ($('#xmppConnectionOpen').html() === "Start") { - sendMessage(); - $('#xmppConnectionOpen').html("Stop"); + sendMessage("Start the process", function(state){ + console.log("sending message to server..."+ state); + if(state<2){ + $('#xmppConnectionOpen').html("Stop"); + }else{ + $('#xmppConnectionOpen').html("Start"); + } + }); + } else if ($('#xmppConnectionOpen').html() === "Stop") { - closeSocket(); - $('#xmppConnectionOpen').html("Start"); - $("#connectionOpen").html("Connect to server").removeClass("btn btn-info").addClass("btn btn-primary"); + closeSocket(function(state){ + console.log("closing WebSocket..."+ state); + if(state<2){ + $('#xmppConnectionOpen').html("Stop"); + }else{ + $('#xmppConnectionOpen').html("Start"); + } + }); + $("#connectionOpen").html("Connect to XMPP Server").removeClass("btn btn-info").addClass("btn btn-primary"); } }); $('.btn-minimize').parent().parent().next('.box-content').hide(); - - var webSocket; config_api.realtime_plotting_data_window["attitude"] = new Queue(); - var current_status = {}; - -function openSocket() { - if (webSocket !== undefined && webSocket.readyState !== WebSocket.CLOSED) { +function openSocket(wssAddress) { + if (webSocket !== undefined && webSocket.readyState == 1) { writeResponse("WebSocket is already opened."); } else { - webSocket = new WebSocket(config_api.web_socket_endpoint); + webSocket = new WebSocket(wssAddress+config_api.web_socket_endpoint); } webSocket.onopen = function (event) { if (event === undefined) { @@ -121,15 +127,20 @@ function openSocket() { writeResponse("Message has been corrupted."); } }; - } -function sendMessage(message) { - webSocket.send(message); +function sendMessage(message, callback) { + if(webSocket.readyState<2){ + webSocket.send(message); + } + callback(webSocket.readyState); } -function closeSocket() { - webSocket.close(); +function closeSocket(callback) { + if(webSocket.readyState<2){ + webSocket.close(); + } + callback(webSocket.readyState); } function writeResponse(text) { @@ -137,8 +148,6 @@ function writeResponse(text) { } window.onbeforeunload = function () { - webSocket.onclose = function () { - }; - webSocket.close() + webSocket.close(); }; diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/controller.js b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/controller.js index a45b65b73..f9d7f0086 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/controller.js +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/public/js/modules/controller.js @@ -17,7 +17,7 @@ */ $("#module_control button").click(function (index) { console.log("Asking Server to send the " + $(this).attr('id') + " command to Ar Drone"); - var url = config_api.drone_control + "?action=" + $(this).attr('id') + "&speed=6&duration=7"; + var url = config_api.drone_control; ajax_handler.ajaxRequest(url, config_api.drone_controlType, {action: $(this).attr('id'), speed: 7, duration: 7}, config_api.drone_controlDataType, function (data, status) { console.log(JSON.stringify(data)); diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs index a4404ee87..2f004fd74 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.hbs @@ -6,7 +6,7 @@
+ onclick="openSocket('{{wssAddress}}');">Connect to XMPP Server
@@ -25,7 +25,7 @@
-
+
@@ -230,8 +230,6 @@
- - {{#zone "bottomJs"}} {{js "/js/d3.min.js" }} {{js "/js/3dobject_controller/three.min.js" }} diff --git a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.js b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.js index dc92c0e90..0740b424b 100644 --- a/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.js +++ b/features/device-mgt-iot-droneanalyzer-feature/org.wso2.carbon.device.mgt.iot.droneanalyzer.feature/src/main/resources/jaggeryapps/devicemgt/app/units/iot.unit.device.droneanalyzer.statistics/statistics.js @@ -16,27 +16,10 @@ * under the License. */ function onRequest (context) { - /*var log = new Log("detail.js"); - var deviceType = request.getParameter("type"); - var deviceId = request.getParameter("id"); - - if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) { - var deviceModule = require("/modules/device.js").deviceModule; - var device = deviceModule.viewDevice(deviceType, deviceId); - - if (device) { - var viewModel = {}; - var deviceInfo = device.properties.DEVICE_INFO; - if (deviceInfo != undefined && String(deviceInfo.toString()).length > 0) { - deviceInfo = parse(stringify(deviceInfo)); - viewModel.system = device.properties.IMEI; - viewModel.machine = "Virtual Firealarm"; - viewModel.vendor = device.properties.VENDOR; - } - device.viewModel = viewModel; - } - context.device = device; - - return context; - }*/ + var log = new Log("statistics.js"); + var serverAddress = require("/app/modules/serverAddress.js").serverAddress; + var wssAddress = serverAddress.getWSSAddress(); + var httpsAddress = serverAddress.getHPPSTSAddress(); + var device = context.unit.params.device; + return { "device": device, "wssAddress": wssAddress, "httpsAddress": httpsAddress}; } \ No newline at end of file