|
|
@ -43,12 +43,13 @@ import org.wso2.carbon.device.mgt.iot.exception.AccessTokenException;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.exception.DeviceControllerException;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorDataManager;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sensormgt.SensorRecord;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.transport.TransportHandlerException;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.util.ZipArchive;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.util.ZipUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto.DeviceJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.dto.DeviceJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.exception.VirtualFireAlarmException;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTSubscriber;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmMQTTConnector;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.transport.VirtualFireAlarmXMPPConnector;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VerificationManager;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.util.VirtualFireAlarmServiceUtils;
|
|
|
@ -99,7 +100,7 @@ public class VirtualFireAlarmService {
|
|
|
|
public static final String MQTT_PROTOCOL = "MQTT";
|
|
|
|
public static final String MQTT_PROTOCOL = "MQTT";
|
|
|
|
|
|
|
|
|
|
|
|
private VerificationManager verificationManager;
|
|
|
|
private VerificationManager verificationManager;
|
|
|
|
private VirtualFireAlarmMQTTSubscriber virtualFireAlarmMQTTSubscriber;
|
|
|
|
private VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector;
|
|
|
|
private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector;
|
|
|
|
private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector;
|
|
|
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
|
|
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
@ -126,7 +127,7 @@ public class VirtualFireAlarmService {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void run() {
|
|
|
|
public void run() {
|
|
|
|
virtualFireAlarmXMPPConnector.initConnector();
|
|
|
|
virtualFireAlarmXMPPConnector.initConnector();
|
|
|
|
virtualFireAlarmXMPPConnector.connectAndLogin();
|
|
|
|
virtualFireAlarmXMPPConnector.connect();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -137,23 +138,22 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param virtualFireAlarmMQTTSubscriber
|
|
|
|
* @param virtualFireAlarmMQTTConnector
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setVirtualFireAlarmMQTTSubscriber(
|
|
|
|
public void setVirtualFireAlarmMQTTConnector(
|
|
|
|
final VirtualFireAlarmMQTTSubscriber virtualFireAlarmMQTTSubscriber) {
|
|
|
|
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
|
|
|
|
this.virtualFireAlarmMQTTSubscriber = virtualFireAlarmMQTTSubscriber;
|
|
|
|
this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
|
|
|
|
|
|
|
|
|
|
|
Runnable xmppStarter = new Runnable() {
|
|
|
|
// Runnable xmppStarter = new Runnable() {
|
|
|
|
@Override
|
|
|
|
// @Override
|
|
|
|
public void run() {
|
|
|
|
// public void run() {
|
|
|
|
virtualFireAlarmMQTTSubscriber.initConnector();
|
|
|
|
virtualFireAlarmMQTTConnector.connect();
|
|
|
|
virtualFireAlarmMQTTSubscriber.connect();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// };
|
|
|
|
};
|
|
|
|
//
|
|
|
|
|
|
|
|
// Thread xmppStarterThread = new Thread(xmppStarter);
|
|
|
|
Thread xmppStarterThread = new Thread(xmppStarter);
|
|
|
|
// xmppStarterThread.setDaemon(true);
|
|
|
|
xmppStarterThread.setDaemon(true);
|
|
|
|
// xmppStarterThread.start();
|
|
|
|
xmppStarterThread.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -176,8 +176,8 @@ public class VirtualFireAlarmService {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public VirtualFireAlarmMQTTSubscriber getVirtualFireAlarmMQTTSubscriber() {
|
|
|
|
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
|
|
|
|
return virtualFireAlarmMQTTSubscriber;
|
|
|
|
return virtualFireAlarmMQTTConnector;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------------------
|
|
|
|
/* ---------------------------------------------------------------------------------------
|
|
|
@ -622,20 +622,22 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
|
|
|
|
VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint, callUrlPattern, true);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
String resource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
|
|
|
String mqttResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
|
|
|
virtualFireAlarmMQTTSubscriber.publishDeviceData(owner, deviceId, resource, switchToState);
|
|
|
|
virtualFireAlarmMQTTConnector.publishDeviceData(owner, deviceId, mqttResource, switchToState);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
VirtualFireAlarmServiceUtils.sendCommandViaXMPP(owner, deviceId,
|
|
|
|
String xmppResource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", "");
|
|
|
|
VirtualFireAlarmConstants.BULB_CONTEXT,
|
|
|
|
virtualFireAlarmXMPPConnector.publishDeviceData(owner, deviceId, xmppResource, switchToState);
|
|
|
|
switchToState, virtualFireAlarmXMPPConnector);
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException | TransportHandlerException e) {
|
|
|
|
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
|
|
|
|
log.error("Failed to send switch-bulb request to device [" + deviceId + "] via " + protocolString);
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
@ -653,23 +655,22 @@ public class VirtualFireAlarmService {
|
|
|
|
* @param response
|
|
|
|
* @param response
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Path("controller/readsonar")
|
|
|
|
@Path("controller/readhumidity")
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Feature( code="VIRTUALFIREALARM_READSONAR", name="Read Sonar",
|
|
|
|
@Feature( code="VIRTUALFIREALARM_READHUMIDITY", name="Read Humidity",
|
|
|
|
description="Read Sonar Readings from Virtual Fire Alarm")
|
|
|
|
description="Read Humidity Readings from Virtual Fire Alarm")
|
|
|
|
public String requestSonarReading(@HeaderParam("owner") String owner,
|
|
|
|
public String requestHumidity(@HeaderParam("owner") String owner,
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("protocol") String protocol,
|
|
|
|
@HeaderParam("protocol") String protocol,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
String replyMsg = "";
|
|
|
|
String replyMsg = "";
|
|
|
|
|
|
|
|
|
|
|
|
DeviceValidator deviceValidator = new DeviceValidator();
|
|
|
|
DeviceValidator deviceValidator = new DeviceValidator();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
|
|
|
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(
|
|
|
|
VirtualFireAlarmConstants
|
|
|
|
deviceId, VirtualFireAlarmConstants.DEVICE_TYPE))) {
|
|
|
|
.DEVICE_TYPE))) {
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
|
|
|
return "Unauthorized Access";
|
|
|
|
return "Unauthorized Access Attempt";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
replyMsg = e.getErrorMessage();
|
|
|
|
replyMsg = e.getErrorMessage();
|
|
|
@ -680,8 +681,7 @@ public class VirtualFireAlarmService {
|
|
|
|
String protocolString = protocol.toUpperCase();
|
|
|
|
String protocolString = protocol.toUpperCase();
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Sending request to read sonar value of device [" + deviceId + "] via " +
|
|
|
|
log.debug("Sending request to read humidity value of device [" + deviceId + "] via " + protocolString);
|
|
|
|
protocolString);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -689,26 +689,24 @@ public class VirtualFireAlarmService {
|
|
|
|
case HTTP_PROTOCOL:
|
|
|
|
case HTTP_PROTOCOL:
|
|
|
|
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
|
|
String deviceHTTPEndpoint = deviceToIpMap.get(deviceId);
|
|
|
|
if (deviceHTTPEndpoint == null) {
|
|
|
|
if (deviceHTTPEndpoint == null) {
|
|
|
|
replyMsg =
|
|
|
|
replyMsg = "IP not registered for device: " + deviceId + " of owner: " + owner;
|
|
|
|
"IP not registered for device: " + deviceId + " of owner: " + owner;
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
return replyMsg;
|
|
|
|
return replyMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
replyMsg = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
|
|
|
|
replyMsg = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(deviceHTTPEndpoint,
|
|
|
|
VirtualFireAlarmConstants.SONAR_CONTEXT,
|
|
|
|
VirtualFireAlarmConstants.HUMIDITY_CONTEXT,
|
|
|
|
false);
|
|
|
|
false);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
String resource = VirtualFireAlarmConstants.SONAR_CONTEXT.replace("/", "");
|
|
|
|
String mqttResource = VirtualFireAlarmConstants.HUMIDITY_CONTEXT.replace("/", "");
|
|
|
|
virtualFireAlarmMQTTSubscriber.publishDeviceData(owner, deviceId, resource, "");
|
|
|
|
virtualFireAlarmMQTTConnector.publishDeviceData(owner, deviceId, mqttResource, "");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
VirtualFireAlarmServiceUtils.sendCommandViaXMPP(owner, deviceId,
|
|
|
|
String xmppResource = VirtualFireAlarmConstants.HUMIDITY_CONTEXT.replace("/", "");
|
|
|
|
VirtualFireAlarmConstants.SONAR_CONTEXT, "",
|
|
|
|
virtualFireAlarmXMPPConnector.publishDeviceData(owner, deviceId, xmppResource, "");
|
|
|
|
virtualFireAlarmXMPPConnector);
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
@ -716,14 +714,14 @@ public class VirtualFireAlarmService {
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
return replyMsg;
|
|
|
|
return replyMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException | TransportHandlerException e) {
|
|
|
|
replyMsg = e.getErrorMessage();
|
|
|
|
replyMsg = e.getMessage();
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
return replyMsg;
|
|
|
|
return replyMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
replyMsg = "The current sonar reading of the device is " + replyMsg;
|
|
|
|
replyMsg = "The current humidity reading of the device is " + replyMsg;
|
|
|
|
return replyMsg;
|
|
|
|
return replyMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -750,9 +748,8 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceValidator deviceValidator = new DeviceValidator();
|
|
|
|
DeviceValidator deviceValidator = new DeviceValidator();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
if (!deviceValidator.isExist(owner, SUPER_TENANT, new DeviceIdentifier(deviceId,
|
|
|
|
if (!deviceValidator.isExist(owner, SUPER_TENANT,
|
|
|
|
VirtualFireAlarmConstants
|
|
|
|
new DeviceIdentifier(deviceId, VirtualFireAlarmConstants.DEVICE_TYPE))) {
|
|
|
|
.DEVICE_TYPE))) {
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.UNAUTHORIZED.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
@ -762,9 +759,8 @@ public class VirtualFireAlarmService {
|
|
|
|
String protocolString = protocol.toUpperCase();
|
|
|
|
String protocolString = protocol.toUpperCase();
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug(
|
|
|
|
log.debug("Sending request to read virtual-firealarm-temperature of device " +
|
|
|
|
"Sending request to read virtual-firealarm-temperature of device [" + deviceId +
|
|
|
|
"[" + deviceId + "] via " + protocolString);
|
|
|
|
"] via " + protocolString);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -775,35 +771,33 @@ public class VirtualFireAlarmService {
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String temperatureValue = VirtualFireAlarmServiceUtils.
|
|
|
|
String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(
|
|
|
|
sendCommandViaHTTP(deviceHTTPEndpoint,
|
|
|
|
deviceHTTPEndpoint,
|
|
|
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
|
|
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
|
|
|
false);
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId,
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId,
|
|
|
|
VirtualFireAlarmConstants.SENSOR_TEMPERATURE,
|
|
|
|
VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
|
|
temperatureValue,
|
|
|
|
temperatureValue,
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
String resource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
|
|
String mqttResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
|
|
virtualFireAlarmMQTTSubscriber.publishDeviceData(owner, deviceId, resource, "");
|
|
|
|
virtualFireAlarmMQTTConnector.publishDeviceData(owner, deviceId, mqttResource, "");
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
case XMPP_PROTOCOL:
|
|
|
|
VirtualFireAlarmServiceUtils.sendCommandViaXMPP(owner, deviceId,
|
|
|
|
String xmppResource = VirtualFireAlarmConstants.TEMPERATURE_CONTEXT.replace("/", "");
|
|
|
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, "",
|
|
|
|
virtualFireAlarmMQTTConnector.publishDeviceData(owner, deviceId, xmppResource, "");
|
|
|
|
virtualFireAlarmXMPPConnector);
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
|
|
|
|
sensorRecord = SensorDataManager.getInstance().getSensorRecord(deviceId,
|
|
|
|
VirtualFireAlarmConstants
|
|
|
|
VirtualFireAlarmConstants.SENSOR_TEMP);
|
|
|
|
.SENSOR_TEMPERATURE);
|
|
|
|
} catch (DeviceManagementException | DeviceControllerException | TransportHandlerException e) {
|
|
|
|
} catch (DeviceManagementException | DeviceControllerException e) {
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -829,18 +823,16 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
if (registeredIp == null) {
|
|
|
|
if (registeredIp == null) {
|
|
|
|
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
|
|
|
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
|
|
|
deviceIp + " for device ID - " + deviceId);
|
|
|
|
deviceIp + " for device ID - " + deviceId);
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else if (!registeredIp.equals(deviceIp)) {
|
|
|
|
} else if (!registeredIp.equals(deviceIp)) {
|
|
|
|
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " +
|
|
|
|
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId +
|
|
|
|
deviceId +
|
|
|
|
" is already registered under some other IP. Re-registration required");
|
|
|
|
" is already registered under some other IP. Re-registration " +
|
|
|
|
|
|
|
|
"required");
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMPERATURE,
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
|
|
String.valueOf(temperature),
|
|
|
|
String.valueOf(temperature),
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
|
|
|
|
|
|
|