Merge pull request #173 from NuwanSameera/IoTS-1.0.0-M2

Digital display new operations added and modified display agent added.
Ruwan 9 years ago
commit af4a30dc02

@ -66,6 +66,7 @@ public class DigitalDisplayControllerService {
public void setDigitalDisplayMQTTConnector(final
DigitalDisplayMQTTConnector digitalDisplayMQTTConnector) {
Runnable connector = new Runnable() {
public void run() {
if (waitForServerStartup()) {
@ -88,22 +89,23 @@ public class DigitalDisplayControllerService {
/**
* Restart the running browser in the given digital display.
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/restart-browser")
@POST
@Feature(code = "restart-browser", name = "Restart Browser", type="operation",
@Feature(code = "restart-browser", name = "Restart Browser", type = "operation",
description = "Restart Browser in Digital Display")
public void restartBrowser(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + ":", "");
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.RESTART_BROWSER_CONSTANT + "::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -116,55 +118,26 @@ public class DigitalDisplayControllerService {
}
/**
* Close the running browser in the given digital display.
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/close-browser")
@POST
@Feature(code = "close-browser", name = "Close Browser", type="operation",
description = "Close Browser in Digital Display")
public void closeBrowser(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.CLOSE_BROWSER_CONSTANT + ":", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
/**
* Terminate all running processes. If this execute we have to reboot digital display manually.
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/terminate-display")
@POST
@Feature(code = "terminate-display", name = "Terminate Display", type="operation",
@Feature(code = "terminate-display", name = "Terminate Display", type = "operation",
description = "Terminate all running process in Digital Display")
public void terminateDisplay(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + ":", "");
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.TERMINATE_DISPLAY_CONSTANT + "::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -177,24 +150,25 @@ public class DigitalDisplayControllerService {
}
/**
* Restart python server in given digital display
* Reboot running digital display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/restart-display")
@POST
@Feature(code = "restart-display", name = "Restart Display", type="operation",
@Feature(code = "restart-display", name = "Restart Display", type = "operation",
description = "Restart Digital Display")
public void restartDisplay(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + ":", "");
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.RESTART_DISPLAY_CONSTANT + "::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -211,27 +185,55 @@ public class DigitalDisplayControllerService {
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param token web socket id of the method invoke client
* @param response response type of the method
* @param path page no need to change
* @param name name of page need to change
* @param attribute this can be path,time or type
* @param newValue page is used to replace path
*/
@Path("/edit-content")
@Path("/edit-sequence")
@POST
@Feature(code = "edit-sequence", name = "Edit Sequence", type = "operation",
description = "Search through the sequence and edit requested resource in Digital Display")
public void editSequence(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("name") String name,
@FormParam("attribute") String attribute,
@FormParam("new-value") String newValue,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
token = token.split(" ")[1];
String params = name + "|" + attribute + "|" + newValue;
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + "::", params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
} catch (DigitalDisplayException e) {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
@Path("/upload-content")
@POST
@Feature(code = "edit-content", name = "Edit Content", type="operation",
@Feature(code = "upload-content", name = "Upload Content", type = "operation",
description = "Search through the sequence and edit requested resource in Digital Display")
public void editContent(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("path") String path,
@FormParam("attribute") String attribute,
@FormParam("new-value") String newValue,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
public void uploadContent(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("remote-path") String remotePath,
@FormParam("screen-name") String screenName,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
String params = path + "|" + attribute + "|" + newValue;
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.EDIT_SEQUENCE_CONSTANT + ":", params);
token = token.split(" ")[1];
String params = remotePath + "|" + screenName;
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.UPLOAD_CONTENT_CONSTANT + "::",
params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -246,38 +248,40 @@ public class DigitalDisplayControllerService {
/**
* Add new resource end to the existing sequence
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param type type of new resource
* @param time new resource visible time
* @param path URL of the new resource
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
* @param type type of new resource
* @param time new resource visible time
* @param path URL of the new resource
*/
@Path("/add-resource")
@POST
@Feature(code = "add-resource", name = "Add Resource", type="operation",
@Feature(code = "add-resource", name = "Add Resource", type = "operation",
description = "Add new resource end to the existing sequence in Digital Display")
public void addNewResource(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("type") String type,
@FormParam("time") String time,
@FormParam("path") String path,
@FormParam("name") String name,
@FormParam("position") String position,
@HeaderParam("sessionId") String sessionId,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
String params;
try {
if (position.isEmpty()){
params = type + "|" + time + "|" + path;
if (position.isEmpty()) {
params = type + "|" + time + "|" + path + "|" + name;
} else {
params = type + "|" + time + "|" + path +
"|" + "after=" + position;
params = type + "|" + time + "|" + path + "|" + name +
"|" + "after=" + position;
}
sendCommandViaMQTT(owner, deviceId, sessionId + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT + ":", params);
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" +
DigitalDisplayConstants.ADD_NEW_RESOURCE_CONSTANT + "::", params);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -291,25 +295,26 @@ public class DigitalDisplayControllerService {
/**
* Delete a resource in sequence
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param path path of the page no need to delete
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
* @param name name of the page no need to delete
*/
@Path("/remove-resource")
@POST
@Feature(code = "remove-resource", name = "Remove Resource", type="operation",
@Feature(code = "remove-resource", name = "Remove Resource", type = "operation",
description = "Delete a resource from sequence in Digital Display")
public void removeResource(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@FormParam("path") String path,
@HeaderParam("sessionId") String sessionId,
@FormParam("name") String name,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" +
DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + ":", path);
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" +
DigitalDisplayConstants.REMOVE_RESOURCE_CONSTANT + "::", name);
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -318,31 +323,28 @@ public class DigitalDisplayControllerService {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
/**
* Remove directory and whole content
* Restart HTTP in running display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param directoryName path of the folder need to delete
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/remove-directory")
@Path("/restart-server")
@POST
@Feature(code = "remove-directory", name = "Remove Directory", type="operation",
description = "Remove directory and whole content in Digital Display")
public void removeDirectory(@FormParam("directory-name") String directoryName,
@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
@Feature(code = "restart-server", name = "Restart Server", type = "operation",
description = "Stop HTTP Server running in Digital Display")
public void restartServer(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" +
DigitalDisplayConstants.REMOVE_DIRECTORY_CONSTANT + ":", directoryName);
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.RESTART_SERVER_CONSTANT + "::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -355,29 +357,25 @@ public class DigitalDisplayControllerService {
}
/**
* Remove content from www folder
* Get screenshot of running display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param directoryName path of directory of request file contain
* @param content file name of need to delete
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/remove-content")
@Path("/screenshot")
@POST
@Feature(code = "remove-content", name = "Remove Content", type="operation",
description = "Remove content from www folder in Digital Display")
public void removeContent(@FormParam("directory-name") String directoryName,
@FormParam("content") String content,
@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
@Feature(code = "screenshot", name = "Take Screenshot", type = "operation",
description = "Show current view in Digital Display")
public void showScreenshot(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
String param = directoryName + "|" + content;
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.REMOVE_CONTENT_CONSTANT + ":", param);
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.SCREENSHOT_CONSTANT + "::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -386,28 +384,29 @@ public class DigitalDisplayControllerService {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
/**
* Stop specific display
* Get statistics of running display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/shutdown-display")
@Path("/get-device-status")
@POST
@Feature(code = "shutdown-display", name = "Shut Down", type="operation",
description = "Stop specific display in Digital Display")
public void shutDownDisplay(@HeaderParam("deviceId") String deviceId,
@Feature(code = "get-device-status", name = "Get Device Status", type = "operation",
description = "Current status in Digital Display")
public void getDevicestatus(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + "::" + DigitalDisplayConstants.SHUTDOWN_DISPLAY_CONSTANT + ":", "");
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.GET_DEVICE_STATUS_CONSTANT +
"::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -416,28 +415,28 @@ public class DigitalDisplayControllerService {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
/**
* Check specific digital display power ON of OFF
* Stop specific display
*
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param sessionId web socket id of the method invoke client
* @param response response type of the method
* @param deviceId id of the controlling digital display
* @param owner owner of the digital display
* @param token web socket id of the method invoke client
* @param response response type of the method
*/
@Path("/get-status")
@Path("/get-content-list")
@POST
@Feature(code = "get-status", name = "Get Status", type="operation",
description = "Check specific digital display power ON or OFF")
public void getStatus(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("sessionId") String sessionId,
@Context HttpServletResponse response) {
@Feature(code = "get-content-list", name = "Get Content List", type = "operation",
description = "Content List in Digital Display")
public void getResources(@HeaderParam("deviceId") String deviceId,
@HeaderParam("owner") String owner,
@HeaderParam("Authorization") String token,
@Context HttpServletResponse response) {
try {
sendCommandViaMQTT(owner, deviceId, sessionId + ":" + DigitalDisplayConstants.GET_STATUS_CONSTANT, "");
token = token.split(" ")[1];
sendCommandViaMQTT(owner, deviceId, token + "::" + DigitalDisplayConstants.GET_CONTENTLIST_CONSTANT + "::", "");
response.setStatus(Response.Status.OK.getStatusCode());
} catch (DeviceManagementException e) {
log.error(e);
@ -446,7 +445,6 @@ public class DigitalDisplayControllerService {
log.error(e);
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
}
}
/**
@ -463,9 +461,8 @@ public class DigitalDisplayControllerService {
String param)
throws DeviceManagementException, DigitalDisplayException {
log.info(deviceOwner);
String topic = String.format(DigitalDisplayConstants.PUBLISH_TOPIC, deviceOwner, deviceId);
String payload = operation + ":" + param;
String payload = operation + param;
try {
digitalDisplayMQTTConnector.publishToDigitalDisplay(topic, payload, 2, false);

@ -0,0 +1,33 @@
package org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.model;
public class ScreenShotModel {
private String[] scrrenShotData;
private int length;
public ScreenShotModel(){
}
public ScreenShotModel(String[] scrrenShotData , int length){
this.scrrenShotData = scrrenShotData;
this.length = length;
}
public void setScrrenShotData(String[] scrrenShotData){
this.scrrenShotData = scrrenShotData;
}
public void setLength(int length){
this.length = length;
}
public String[] getScrrenShotData(){
return this.scrrenShotData;
}
public int getLength(){
return this.length;
}
}

@ -4,14 +4,19 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.json.JSONObject;
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.model.ScreenShotModel;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.controller.api.websocket.DigitalDisplayWebSocketServerEndPoint;
import org.wso2.carbon.device.mgt.iot.digitaldisplay.plugin.constants.DigitalDisplayConstants;
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
import org.wso2.carbon.device.mgt.iot.transport.mqtt.MQTTTransportHandler;
import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ScheduledFuture;
@SuppressWarnings("no JAX-WS annotation")
public class DigitalDisplayMQTTConnector extends MQTTTransportHandler {
@ -25,9 +30,13 @@ public class DigitalDisplayMQTTConnector extends MQTTTransportHandler {
private static String iotServerSubscriber = UUID.randomUUID().toString().substring(0, 5);
private ScheduledFuture<?> dataPushServiceHandler;
private Map<String, ScreenShotModel> screenshots = new HashMap<>();
private DigitalDisplayMQTTConnector() {
super(iotServerSubscriber, DigitalDisplayConstants.DEVICE_TYPE,
MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic);
MqttConfig.getInstance().getMqttQueueEndpoint(), subscribeTopic);
}
@Override
@ -65,36 +74,62 @@ public class DigitalDisplayMQTTConnector extends MQTTTransportHandler {
@Override
public void processIncomingMessage(MqttMessage message, String... messageParams) {
if(messageParams.length != 0) {
String topic = messageParams[0];
String ownerAndId = topic.replace("wso2" + File.separator + "iot" + File.separator, "");
ownerAndId = ownerAndId.replace(File.separator + DigitalDisplayConstants.DEVICE_TYPE + File.separator, ":");
ownerAndId = ownerAndId.replace(File.separator + "digital_display_publisher", "");
String owner = ownerAndId.split(":")[0];
String deviceId = ownerAndId.split(":")[1];
String[] messageData = message.toString().split(":");
if (log.isDebugEnabled()) {
log.debug("Received MQTT message for: [OWNER-" + owner + "] & [DEVICE.ID-" + deviceId + "]");
}
String topic = messageParams[0];
String ownerAndId = topic.replace("wso2" + File.separator + "iot" + File.separator, "");
ownerAndId = ownerAndId.replace(File.separator + DigitalDisplayConstants.DEVICE_TYPE + File.separator, ":");
ownerAndId = ownerAndId.replace(File.separator + "digital_display_publisher", "");
if (messageData.length == 3) {
String randomId = messageData[0];
String requestMessage = messageData[1];
String result = messageData[2];
String owner = ownerAndId.split(":")[0];
String deviceId = ownerAndId.split(":")[1];
if (log.isDebugEnabled()) {
log.debug("Return result " + result + " for Request " + requestMessage);
String[] messageData = message.toString().split("::");
if (log.isDebugEnabled()) {
log.debug("Received MQTT message for: [OWNER-" + owner + "] & [DEVICE.ID-" + deviceId + "]");
}
String token = messageData[0];
if (messageData.length == 2) {
String responseMessage = messageData[1];
DigitalDisplayWebSocketServerEndPoint.sendMessage(token, new StringBuilder(responseMessage));
} else if (messageData.length == 3) {
String response = messageData[2];
JSONObject schreenshot = new JSONObject(response);
String pic_id = schreenshot.getString("pic_id");
String data = schreenshot.getString("data");
int pos = schreenshot.getInt("pos");
int length = schreenshot.getInt("size");
createScreenShot(token, pic_id, pos, length, data);
}
}
private void createScreenShot(String token, String pic_id, int pos, int length, String data) {
ScreenShotModel screenShotModel = screenshots.get(pic_id);
if (screenShotModel == null) {
screenShotModel = new ScreenShotModel();
screenShotModel.setScrrenShotData(new String[length + 1]);
screenShotModel.setLength(0);
screenshots.put(pic_id, screenShotModel);
}
if (screenShotModel.getLength() <= length) {
screenShotModel.getScrrenShotData()[pos] = data;
System.out.println(screenShotModel.getLength());
screenShotModel.setLength(screenShotModel.getLength() + 1);
if (screenShotModel.getLength() == (length + 1)) {
StringBuilder displayScreenShot = new StringBuilder("Screenshot||");
for (String screenshot : screenShotModel.getScrrenShotData()) {
displayScreenShot.append(screenshot);
}
DigitalDisplayWebSocketServerEndPoint.sendMessage(randomId, result);
screenshots.remove(pic_id);
DigitalDisplayWebSocketServerEndPoint.sendMessage(token, displayScreenShot);
}
}
}
public void publishToDigitalDisplay(String topic, String payLoad, int qos, boolean retained)
throws TransportHandlerException {
if(log.isDebugEnabled()){
if (log.isDebugEnabled()) {
log.debug("Publishing message [" + payLoad + "to topic [" + topic + "].");
}
publishToQueue(topic, payLoad, qos, retained);

@ -4,23 +4,18 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.inject.Singleton;
import javax.websocket.OnClose;
import javax.websocket.OnError;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.*;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
@ServerEndpoint(value = "/digital-display-server-end-point")
@ServerEndpoint(value = "/{token}")
@Singleton
public class DigitalDisplayWebSocketServerEndPoint {
private static Log log = LogFactory.getLog(DigitalDisplayWebSocketServerEndPoint.class);
private static Map<String,Session> clientSessions = new HashMap<>();
private static Map<String, Session> clientSessions = new HashMap<>();
/**
* This method will be invoked when a client requests for a
@ -29,12 +24,8 @@ public class DigitalDisplayWebSocketServerEndPoint {
* @param userSession the userSession which is opened.
*/
@OnOpen
public void onOpen(Session userSession){
UUID uuid = UUID.randomUUID();
log.info("Generated Random Id " + uuid.toString());
log.info(" Connected with Session Id : " + userSession.getId());
clientSessions.put(uuid.toString() , userSession);
userSession.getAsyncRemote().sendText("RandomID:" + uuid.toString());
public void onOpen(Session userSession, @PathParam("token") String token) {
clientSessions.put(token, userSession);
}
/**
@ -44,29 +35,28 @@ public class DigitalDisplayWebSocketServerEndPoint {
* @param userSession the userSession which is opened.
*/
@OnClose
public void onClose(Session userSession){
log.info("Client disconnected - Session Id : " + userSession.getId());
public void onClose(Session userSession) {
clientSessions.values().remove(userSession);
}
@OnError
public void onError(Throwable t){
log.error("Error occurred " + t );
public void onError(Throwable t) {
log.error("Error occurred " + t);
}
/**
* This method will be invoked when a message received from device
* to send client.
*
* @param randomId the client of message to be sent.
* @param token the client of message to be sent.
* @param message the message sent by device to client
*/
public static void sendMessage(String randomId , String message){
if(clientSessions.keySet().contains(randomId)){
clientSessions.get(randomId).getAsyncRemote().sendText(message);
log.info("Message : " + message + " send to Session Id : " + randomId);
}else {
public static void sendMessage(String token, StringBuilder message) {
Session session = clientSessions.get(token);
if (session != null) {
session.getAsyncRemote().sendText(message.toString());
} else {
log.error("Client already disconnected.");
}
}

@ -21,17 +21,17 @@ public class DigitalDisplayConstants {
public final static String DEVICE_TYPE = "digital_display";
public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME";
public final static String DEVICE_PLUGIN_DEVICE_ID = "DIGITAL_DISPLAY_DEVICE_ID";
public final static String SHUTDOWN_DISPLAY_CONSTANT = "shutdown_display";
public final static String RESTART_SERVER_CONSTANT = "restart_server";
public final static String RESTART_DISPLAY_CONSTANT = "restart_display";
public final static String REMOVE_DIRECTORY_CONSTANT = "remove_dir_and_content";
public final static String REMOVE_CONTENT_CONSTANT = "remove_content";
public final static String CLOSE_BROWSER_CONSTANT = "close_browser";
public final static String RESTART_BROWSER_CONSTANT = "restart_browser";
public final static String TERMINATE_DISPLAY_CONSTANT = "terminate_display";
public final static String EDIT_SEQUENCE_CONSTANT = "edit_content_config";
public final static String EDIT_SEQUENCE_CONSTANT = "edit_sequence";
public final static String UPLOAD_CONTENT_CONSTANT = "upload_content";
public final static String ADD_NEW_RESOURCE_CONSTANT = "add_new_resource";
public final static String REMOVE_RESOURCE_CONSTANT = "remove_resources";
public final static String GET_STATUS_CONSTANT = "get_status";
public final static String SCREENSHOT_CONSTANT = "get_screenshot";
public final static String GET_CONTENTLIST_CONSTANT = "get_content_list";
public final static String GET_DEVICE_STATUS_CONSTANT = "get_device_status";
public final static String PUBLISH_TOPIC = "wso2/iot/%s/digital_display/%s/digital_display_subscriber";
}

@ -9,6 +9,8 @@ for P in paho-mqtt lxml; do
}
done
unzip DigitalDisplay
cp ./deviceConfig.properties ./DigitalDisplay

@ -4,8 +4,6 @@ ps aux|grep httpserver.py|awk '{print $2}'|xargs kill -9
#xdotool mousemove 0 0
#xdotool search -name LXTerminal windowunmap
#cd ~/
unzip DigitalDisplay
cp ./deviceConfig.properties ./DigitalDisplay
cd ./DigitalDisplay/
mkdir -p tmp/dd-kernel-test
python displayagent.py

@ -10,6 +10,11 @@
<img src="{{@unit.publicUri}}/images/display-icon.png"/>
{{/zone}}
{{#zone "operation-status"}}
<div id="div-operation-status" class="hidden" align="center" style="padding: 10px; margin-bottom: 5px">
</div>
{{/zone}}
{{#zone "device-opetations"}}
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Operations
@ -20,6 +25,7 @@
{{/zone}}
{{#zone "device-detail-properties"}}
<div class="media">
<div class="media-left col-xs-12 col-sm-2 col-md-2 col-lg-2">
<ul class="list-group" role="tablist">
@ -31,26 +37,56 @@
</ul>
</div>
<div class="media-body add-padding-left-5x remove-padding-xs tab-content">
<div class="panel-group tab-content">
<div class="panel panel-default tab-pane" id="policies" role="tabpanel"
aria-labelledby="policies">
<div class="panel-heading">Policies</div>
<div class="panel-body">
<div id="policy-spinner" class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policies . . .
<br>
<br>
</div>
<div id="policy-list-container">
<div class="panel-body">
No policies found
<div class="panel panel-default tab-pane active"
id="device_statistics" role="tabpanel" aria-labelledby="device_statistics">
<div style="background: #11375B; color: #fff; padding: 10px; margin-bottom: 5px">
Display Status
</div>
<div class="col-md-12">
<div id="screeshot" class="col-md-4">
<div>Display View</div>
<a id="zoom-image" href="{{@unit.publicUri}}/images/default-screen.png" target="_blank">
<img id="img" src="{{@unit.publicUri}}/images/default-screen.png"
style="width: 40% ; height: 40% ; float: left" class="img-responsive"/>
</a>
</div>
<div id="content-list-pane" class="col-md-4">
<div>Content List</div>
<ul id="content-list"></ul>
</div>
<div id="device-statics-pane" class="col-md-4">
<div>Device Statics</div>
<ul id="device-statics"></ul>
</div>
</div>
</div>
<div class="panel-group tab-content">
<div class="panel panel-default tab-pane" id="policy_compliance" role="tabpanel"
aria-labelledby="policy_compliance">
<div class="panel-heading">Policy Compliance <span><a href="#"
id="refresh-policy"><i
class="fw fw-refresh"></i></a></span></div>
<div class="panel panel-default tab-pane" id="policies" role="tabpanel"
aria-labelledby="policies">
<div class="panel-heading">Policies</div>
<div class="panel-body">
<div id="policy-spinner" class="wr-advance-operations-init hidden">
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<i class="fw fw-settings fw-spin fw-2x"></i>
&nbsp;&nbsp;&nbsp;
Loading Policies . . .
<br>
<br>
</div>
<div id="policy-list-container">
<div class="panel-body">
No policies found
</div>
<br class="c-both"/>
</div>
<br class="c-both"/>
</div>
</div>
<a class="padding-left"
@ -86,4 +122,13 @@
</div>
</div>
</div>
{{/zone}}
{{/zone}}
{{#zone "bottomJs"}}
<script type="text/javascript">
var token = "{{token}}";
var port = "{{port}}";
var host = "{{host}}";
</script>
{{js "js/websocket.js"}}
{{/zone}}

@ -17,9 +17,20 @@
*/
function onRequest(context) {
var log = new Log("detail.js");
var log = new Log("device-view.js");
var deviceType = context.uriParams.deviceType;
var deviceId = request.getParameter("id");
var owner = context.user.username;
var TokenClient = Packages.org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
var accessTokenClient = new TokenClient(deviceType);
var accessTokenInfo = accessTokenClient.getAccessToken(owner, deviceId);
var accessToken = accessTokenInfo.getAccess_token();
var getProperty = require("process").getProperty;
var port = getProperty("carbon.https.port");
var host = getProperty("carbon.local.ip");
if (deviceType != null && deviceType != undefined && deviceId != null && deviceId != undefined) {
var deviceModule = require("/app/modules/device.js").deviceModule;
@ -27,7 +38,7 @@ function onRequest(context) {
if (device && device.status != "error") {
log.info(device);
return {"device": device};
return {"device": device, "token" : accessToken , "port" : port, "host" : host};
}
}
}

@ -0,0 +1,64 @@
var displayClient = null;
window.onload = function () {
connect();
};
window.onbeforeunload = function () {
disconnect();
}
function connect() {
displayClient = new WebSocket("wss://" + host + ":" + port + "/digital_display/" + token);
displayClient.onmessage = function (event) {
var message = event.data;
var operationDiv = document.getElementById("div-operation-status");
var type = message.split('||')[0];
var reply = message.split('||')[1];
if (type.valueOf() == new String("Screenshot").valueOf()) {
document.getElementById('img').setAttribute('src', 'data:image/png;base64,' + reply);
document.getElementById('zoom-image').setAttribute('href', 'data:image/png;base64,' + reply);
} else if (type.valueOf() == new String("Success").valueOf()) {
$('#div-operation-status').removeClass('hidden');
$('#div-operation-status').text(reply);
operationDiv.style.backgroundColor = '#DFF2BF';
operationDiv.style.color = '#4F8A10';
} else if (type.valueOf() == new String("Failed").valueOf()) {
$('#div-operation-status').removeClass('hidden');
$('#div-operation-status').text(reply);
operationDiv.style.backgroundColor = '#FFBABA';
operationDiv.style.color = '#D8000C';
} else if (type.valueOf() == new String("ContentList").valueOf()) {
var resources = reply.split("-");
var ul = document.getElementById("content-list");
ul.innerHTML = "";
for (i = 0; i < resources.length; i++) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(resources[i]));
ul.appendChild(li);
}
} else if (type.valueOf() == new String("DeviceStatus").valueOf()) {
var resources = reply.split("-");
var ul = document.getElementById("device-statics");
ul.innerHTML = "";
for (i = 0; i < resources.length; i++) {
var li = document.createElement("li");
li.appendChild(document.createTextNode(resources[i]));
ul.appendChild(li);
}
}
setTimeout(function () {
$('#div-operation-status').addClass('hidden');
}, 10000);
};
}
function disconnect() {
displayClient.close();
}

@ -187,7 +187,8 @@
</li>
<li class="padding-top-double"><span class="circle">04</span>&nbsp;&nbsp;&nbsp;Unzip downloaded agent.
</li>
<li class="padding-top-double"><span class="circle">05</span>&nbsp;&nbsp;&nbsp;Start Agent by running wso2Agent.sh
<li class="padding-top-double"><span class="circle">05</span>&nbsp;&nbsp;&nbsp;Start Agent by running
installpackages.sh followed by wso2Agent.sh
</li>
</ul>
<br>

Loading…
Cancel
Save