|
|
@ -25,13 +25,13 @@ import org.wso2.carbon.device.mgt.common.Device;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.DeviceManagement;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.plugin.constants.AndroidSenseConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.DeviceJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.androidsense.service.impl.util.SensorJSON;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.DeviceManagement;
|
|
|
|
|
|
|
|
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.androidsense.plugin.constants.AndroidSenseConstants;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.ws.rs.*;
|
|
|
|
import javax.ws.rs.*;
|
|
|
@ -83,7 +83,9 @@ public class AndroidSenseService {
|
|
|
|
@Context //injected response proxy supporting multiple thread
|
|
|
|
@Context //injected response proxy supporting multiple thread
|
|
|
|
private HttpServletResponse response;
|
|
|
|
private HttpServletResponse response;
|
|
|
|
|
|
|
|
|
|
|
|
@Path("manager/device") @PUT public boolean register(@FormParam("deviceId") String deviceId,
|
|
|
|
@Path("manager/device")
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
|
|
|
|
public boolean register(@FormParam("deviceId") String deviceId,
|
|
|
|
@FormParam("owner") String owner) {
|
|
|
|
@FormParam("owner") String owner) {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
@ -126,7 +128,9 @@ public class AndroidSenseService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Path("manager/device/remove/{device_id}") @DELETE public void removeDevice(@PathParam("device_id") String deviceId,
|
|
|
|
@Path("manager/device/remove/{device_id}")
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
|
|
|
|
public void removeDevice(@PathParam("device_id") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
@ -150,9 +154,10 @@ public class AndroidSenseService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Path("manager/device/update/{device_id}") @POST
|
|
|
|
@Path("manager/device/update/{device_id}")
|
|
|
|
public boolean updateDevice(@PathParam("device_id") String deviceId,
|
|
|
|
@POST
|
|
|
|
@QueryParam("name") String name,
|
|
|
|
public boolean updateDevice(
|
|
|
|
|
|
|
|
@PathParam("device_id") String deviceId, @QueryParam("name") String name,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
@ -189,7 +194,11 @@ public class AndroidSenseService {
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Path("manager/device/{device_id}") @GET @Consumes("application/json") @Produces("application/json") public Device getDevice(
|
|
|
|
@Path("manager/device/{device_id}")
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
|
|
|
@Consumes("application/json")
|
|
|
|
|
|
|
|
@Produces("application/json")
|
|
|
|
|
|
|
|
public Device getDevice(
|
|
|
|
@PathParam("device_id") String deviceId) {
|
|
|
|
@PathParam("device_id") String deviceId) {
|
|
|
|
|
|
|
|
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
|
DeviceManagement deviceManagement = new DeviceManagement(SUPER_TENANT);
|
|
|
@ -211,8 +220,11 @@ public class AndroidSenseService {
|
|
|
|
|
|
|
|
|
|
|
|
/* Service to push all the sensor data collected by the Android
|
|
|
|
/* Service to push all the sensor data collected by the Android
|
|
|
|
Called by the Android device */
|
|
|
|
Called by the Android device */
|
|
|
|
@Path("controller/sensordata") @POST @Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
@Path("controller/sensordata")
|
|
|
|
public void pushSensorData(final DeviceJSON dataMsg, @Context HttpServletResponse response) {
|
|
|
|
@POST
|
|
|
|
|
|
|
|
@Consumes(MediaType.APPLICATION_JSON)
|
|
|
|
|
|
|
|
public void pushSensorData(
|
|
|
|
|
|
|
|
final DeviceJSON dataMsg, @Context HttpServletResponse response) {
|
|
|
|
|
|
|
|
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
@ -229,7 +241,7 @@ public class AndroidSenseService {
|
|
|
|
switch (sensor.key) {
|
|
|
|
switch (sensor.key) {
|
|
|
|
case "battery":
|
|
|
|
case "battery":
|
|
|
|
streamDef = BATTERY_STREAM_DEFINITION;
|
|
|
|
streamDef = BATTERY_STREAM_DEFINITION;
|
|
|
|
payloadData = new Object[] { Float.parseFloat(sensor.value) };
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
sensorName = SENSOR_BATTERY;
|
|
|
|
sensorName = SENSOR_BATTERY;
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
case "GPS":
|
|
|
|
case "GPS":
|
|
|
@ -258,8 +270,8 @@ public class AndroidSenseService {
|
|
|
|
} else if (androidSensorId == 5) {
|
|
|
|
} else if (androidSensorId == 5) {
|
|
|
|
streamDef = LIGHT_STREAM_DEFINITION;
|
|
|
|
streamDef = LIGHT_STREAM_DEFINITION;
|
|
|
|
sensorName = SENSOR_LIGHT;
|
|
|
|
sensorName = SENSOR_LIGHT;
|
|
|
|
payloadData = new Object[] { Float.parseFloat(sensor.value) };
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
} else if (androidSensorId == 1){
|
|
|
|
} else if (androidSensorId == 1) {
|
|
|
|
streamDef = ACCELEROMETER_STREAM_DEFINITION;
|
|
|
|
streamDef = ACCELEROMETER_STREAM_DEFINITION;
|
|
|
|
String value = sensor.value;
|
|
|
|
String value = sensor.value;
|
|
|
|
String valuesM[] = value.split(",");
|
|
|
|
String valuesM[] = value.split(",");
|
|
|
@ -298,11 +310,11 @@ public class AndroidSenseService {
|
|
|
|
} else if (androidSensorId == 8) {
|
|
|
|
} else if (androidSensorId == 8) {
|
|
|
|
streamDef = PROXIMITY_STREAM_DEFINITION;
|
|
|
|
streamDef = PROXIMITY_STREAM_DEFINITION;
|
|
|
|
sensorName = SENSOR_PROXIMITY;
|
|
|
|
sensorName = SENSOR_PROXIMITY;
|
|
|
|
payloadData = new Object[] { Float.parseFloat(sensor.value) };
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
} else if (androidSensorId == 6) {
|
|
|
|
} else if (androidSensorId == 6) {
|
|
|
|
streamDef = PRESSURE_STREAM_DEFINITION;
|
|
|
|
streamDef = PRESSURE_STREAM_DEFINITION;
|
|
|
|
sensorName = SENSOR_PRESSURE;
|
|
|
|
sensorName = SENSOR_PRESSURE;
|
|
|
|
payloadData = new Object[] { Float.parseFloat(sensor.value) };
|
|
|
|
payloadData = new Object[]{Float.parseFloat(sensor.value)};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//Add the remaining sensor types.
|
|
|
|
//Add the remaining sensor types.
|
|
|
|
|
|
|
|
|
|
|
@ -311,7 +323,7 @@ public class AndroidSenseService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Object metdaData[] = { dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time };
|
|
|
|
Object metdaData[] = {dataMsg.owner, AndroidSenseConstants.DEVICE_TYPE, dataMsg.deviceId, sensor.time};
|
|
|
|
|
|
|
|
|
|
|
|
if (streamDef != null && payloadData != null && payloadData.length > 0) {
|
|
|
|
if (streamDef != null && payloadData != null && payloadData.length > 0) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -385,13 +397,12 @@ public class AndroidSenseService {
|
|
|
|
return sensorRecord;
|
|
|
|
return sensorRecord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Path("controller/readmagnetic")
|
|
|
|
@Path("controller/readmagnetic")
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readMagnetic(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readMagnetic(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -408,14 +419,14 @@ public class AndroidSenseService {
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by Menaka
|
|
|
|
* Created by Menaka
|
|
|
|
* Adding Accelerometer
|
|
|
|
* Adding Accelerometer
|
|
|
|
* */
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
@Path("controller/readaccelerometer")
|
|
|
|
@Path("controller/readaccelerometer")
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readAccelerometer(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readAccelerometer(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -433,8 +444,8 @@ public class AndroidSenseService {
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readRotation(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readRotation(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -452,8 +463,8 @@ public class AndroidSenseService {
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readProximity(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readProximity(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -471,8 +482,8 @@ public class AndroidSenseService {
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readGyroscope(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readGyroscope(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -490,8 +501,8 @@ public class AndroidSenseService {
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readPressure(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readPressure(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -509,8 +520,8 @@ public class AndroidSenseService {
|
|
|
|
@GET
|
|
|
|
@GET
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Consumes("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
@Produces("application/json")
|
|
|
|
public SensorRecord readGravity(@HeaderParam("owner") String owner,
|
|
|
|
public SensorRecord readGravity(
|
|
|
|
@HeaderParam("deviceId") String deviceId,
|
|
|
|
@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId,
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
@Context HttpServletResponse response) {
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
SensorRecord sensorRecord = null;
|
|
|
|
|
|
|
|
|
|
|
@ -524,5 +535,4 @@ public class AndroidSenseService {
|
|
|
|
return sensorRecord;
|
|
|
|
return sensorRecord;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|