|
|
@ -44,7 +44,8 @@ import org.wso2.carbon.device.mgt.iot.common.exception.DeviceControllerException
|
|
|
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipArchive;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipArchive;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.common.util.ZipUtil;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.dao.TemperatureRecord;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.dao.DeviceRecord;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.dao.SensorRecord;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.util.DataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.util.DataHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.dao.DeviceJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.dao.DeviceJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.util.VirtualFireAlarmMQTTSubscriber;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.virtual.firealarm.service.impl.util.VirtualFireAlarmMQTTSubscriber;
|
|
|
@ -246,8 +247,7 @@ public class VirtualFireAlarmService {
|
|
|
|
device.setName(name);
|
|
|
|
device.setName(name);
|
|
|
|
device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
|
|
|
device.setType(VirtualFireAlarmConstants.DEVICE_TYPE);
|
|
|
|
|
|
|
|
|
|
|
|
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(
|
|
|
|
boolean updated = deviceManagement.getDeviceManagementService().modifyEnrollment(device);
|
|
|
|
device);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (updated) {
|
|
|
|
if (updated) {
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
@ -607,11 +607,11 @@ public class VirtualFireAlarmService {
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public TemperatureRecord requestTemperature(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord requestTemperature(@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) {
|
|
|
|
TemperatureRecord temperatureRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
|
DeviceValidator deviceValidator = new DeviceValidator();
|
|
|
|
DeviceValidator deviceValidator = new DeviceValidator();
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -636,8 +636,9 @@ public class VirtualFireAlarmService {
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String tString = sendCommandViaHTTP(deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
|
|
|
String tString = sendCommandViaHTTP(deviceHTTPEndpoint, VirtualFireAlarmConstants.TEMPERATURE_CONTEXT, false);
|
|
|
|
float temperature = Float.parseFloat(tString);
|
|
|
|
String temperatureValue = tString;
|
|
|
|
DataHolder.getThisInstance().setTemperature(deviceId, temperature, Calendar.getInstance().getTimeInMillis());
|
|
|
|
DataHolder.getInstance().setSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMPERATURE, temperatureValue,
|
|
|
|
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
|
case MQTT_PROTOCOL:
|
|
|
@ -651,13 +652,13 @@ public class VirtualFireAlarmService {
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.NOT_ACCEPTABLE.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
temperatureRecord = DataHolder.getThisInstance().getTemperature(deviceId);
|
|
|
|
sensorRecord = DataHolder.getInstance().getSensorRecord(deviceId, VirtualFireAlarmConstants.SENSOR_TEMPERATURE);
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
} catch (DeviceManagementException e) {
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.OK.getStatusCode());
|
|
|
|
return temperatureRecord;
|
|
|
|
return sensorRecord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Path("controller/push_temperature")
|
|
|
|
@Path("controller/push_temperature")
|
|
|
@ -684,13 +685,38 @@ public class VirtualFireAlarmService {
|
|
|
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
DataHolder.getThisInstance().setTemperature(deviceId, temperature, Calendar.getInstance().getTimeInMillis());
|
|
|
|
DataHolder.getInstance().setSensorRecord(deviceId,
|
|
|
|
|
|
|
|
VirtualFireAlarmConstants.SENSOR_TEMPERATURE,
|
|
|
|
|
|
|
|
String.valueOf(temperature),
|
|
|
|
|
|
|
|
Calendar.getInstance().getTimeInMillis());
|
|
|
|
if (!publishToDAS(dataMsg.owner, dataMsg.deviceId, dataMsg.value)) {
|
|
|
|
if (!publishToDAS(dataMsg.owner, dataMsg.deviceId, dataMsg.value)) {
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("controller/set_sensor")
|
|
|
|
|
|
|
|
@POST
|
|
|
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
|
|
|
public boolean setSensorReading(@HeaderParam("deviceId") String deviceId,
|
|
|
|
|
|
|
|
@HeaderParam("sensorName") String sensorName,
|
|
|
|
|
|
|
|
@HeaderParam("sensorValue") String sensorValue,
|
|
|
|
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return DataHolder.getInstance().setSensorRecord(deviceId, sensorName, sensorValue, Calendar.getInstance().getTimeInMillis());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("controller/read_sensor")
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
|
|
|
public SensorRecord readSensorReading(@HeaderParam("deviceId") String deviceId,
|
|
|
|
|
|
|
|
@HeaderParam("sensorName") String sensorName,
|
|
|
|
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
|
|
|
return DataHolder.getInstance().getSensorRecord(deviceId, sensorName);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext, boolean fireAndForgot) throws DeviceManagementException {
|
|
|
|
private String sendCommandViaHTTP(final String deviceHTTPEndpoint, String urlContext, boolean fireAndForgot) throws DeviceManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
String responseMsg = "";
|
|
|
|
String responseMsg = "";
|
|
|
@ -764,6 +790,8 @@ public class VirtualFireAlarmService {
|
|
|
|
return responseMsg;
|
|
|
|
return responseMsg;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource, String state) throws DeviceManagementException {
|
|
|
|
private boolean sendCommandViaMQTT(String deviceOwner, String deviceId, String resource, String state) throws DeviceManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
boolean result = false;
|
|
|
|