|
|
|
@ -20,9 +20,6 @@ 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.iot.common.exception.DeviceControllerException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.common.sensormgt.SensorDataManager;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.common.sensormgt.SensorRecord;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.android.sense.plugin.constants.AndroidSenseConstants;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.android.sense.service.impl.util.DeviceJSON;
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.sample.android.sense.service.impl.util.SensorJSON;
|
|
|
|
@ -71,11 +68,9 @@ public class AndroidSenseControllerService {
|
|
|
|
|
switch (sensor.key){
|
|
|
|
|
case "light" : streamDef = LIGHT_STREAM_DEFINITION;
|
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(dataMsg.deviceId,"light",sensor.value,sensor.time);
|
|
|
|
|
break;
|
|
|
|
|
case "battery" : streamDef = BATTERY_STREAM_DEFINITION;
|
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(dataMsg.deviceId,"battery",sensor.value,sensor.time);
|
|
|
|
|
break;
|
|
|
|
|
case "GPS" : streamDef = GPS_STREAM_DEFINITION;
|
|
|
|
|
String gpsValue =sensor.value;
|
|
|
|
@ -84,7 +79,6 @@ public class AndroidSenseControllerService {
|
|
|
|
|
gpsValuesF[0] = Float.parseFloat(gpsValues[0]);
|
|
|
|
|
gpsValuesF[1] = Float.parseFloat(gpsValues[0]);
|
|
|
|
|
payloadData = gpsValuesF;
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(dataMsg.deviceId,"gps",sensor.value,sensor.time);
|
|
|
|
|
break;
|
|
|
|
|
default :
|
|
|
|
|
try {
|
|
|
|
@ -96,9 +90,10 @@ public class AndroidSenseControllerService {
|
|
|
|
|
String valuesM[]=value.split(",");
|
|
|
|
|
Float gValuesF[]= new Float[1];
|
|
|
|
|
gValuesF[0] = Float.parseFloat(valuesM[0])*Float.parseFloat(valuesM[0])*Float.parseFloat(valuesM[0]);
|
|
|
|
|
|
|
|
|
|
payloadData = gValuesF;
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(dataMsg.deviceId,"magnetic",sensor.value,sensor.time);
|
|
|
|
|
}else if(androidSensorId==5){
|
|
|
|
|
streamDef = LIGHT_STREAM_DEFINITION;
|
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
|
}
|
|
|
|
|
}catch(NumberFormatException e){
|
|
|
|
|
continue;
|
|
|
|
@ -120,86 +115,4 @@ public class AndroidSenseControllerService {
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("controller/readgps")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public SensorRecord requestTemperature(@HeaderParam("owner") String owner,
|
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
|
@HeaderParam("protocol") String protocol,
|
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return SensorDataManager.getInstance().getSensorRecord(deviceId,"gps");
|
|
|
|
|
} catch (DeviceControllerException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sensorRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("controller/readlight")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public SensorRecord readLight(@HeaderParam("owner") String owner,
|
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
|
@HeaderParam("protocol") String protocol,
|
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return SensorDataManager.getInstance().getSensorRecord(deviceId,"light");
|
|
|
|
|
} catch (DeviceControllerException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sensorRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("controller/readmagnetic")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public SensorRecord readMagnetic(@HeaderParam("owner") String owner,
|
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
|
@HeaderParam("protocol") String protocol,
|
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return SensorDataManager.getInstance().getSensorRecord(deviceId,"magnetic");
|
|
|
|
|
} catch (DeviceControllerException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sensorRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Path("controller/readbattery")
|
|
|
|
|
@GET
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
public SensorRecord readBattery(@HeaderParam("owner") String owner,
|
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
|
@HeaderParam("protocol") String protocol,
|
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
return SensorDataManager.getInstance().getSensorRecord(deviceId,"battery");
|
|
|
|
|
} catch (DeviceControllerException e) {
|
|
|
|
|
response.setStatus(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return sensorRecord;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|