fixed issues in android sense

revert-dabc3590
ayyoob 9 years ago
parent e775c8ebe0
commit 3b75a2e9a4

@ -159,7 +159,7 @@ public class AndroidSenseMQTTHandler extends MQTTTransportHandler {
*/ */
@Override @Override
public void publishDeviceData(String... publishData) throws TransportHandlerException { public void publishDeviceData(String... publishData) throws TransportHandlerException {
if (publishData.length != 3) { if (publishData.length != 4) {
String errorMsg = "Incorrect number of arguments received to SEND-MQTT Message. " + String errorMsg = "Incorrect number of arguments received to SEND-MQTT Message. " +
"Need to be [owner, deviceId, content]"; "Need to be [owner, deviceId, content]";
Log.e(TAG, errorMsg); Log.e(TAG, errorMsg);

@ -251,7 +251,7 @@ public class LocalRegistry {
SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(SENSE_SHARED_PREFERENCES, Context.MODE_PRIVATE);
LocalRegistry.tenantDomain = sharedpreferences.getString(TENANT_DOMAIN_KEY, ""); LocalRegistry.tenantDomain = sharedpreferences.getString(TENANT_DOMAIN_KEY, "");
} }
return LocalRegistry.mqttEndpoint; return LocalRegistry.tenantDomain;
} }
public static String getServerHost(Context context) { public static String getServerHost(Context context) {

@ -19,9 +19,9 @@
<eventReceiver name="EventReceiver_AndroidSense" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver"> <eventReceiver name="EventReceiver_AndroidSense" statistics="disable" trace="disable" xmlns="http://wso2.org/carbon/eventreceiver">
<from eventAdapterType="oauth-mqtt"> <from eventAdapterType="oauth-mqtt">
<property name="topic">wso2/android_sense/+/data</property> <property name="topic">wso2/carbon.super/android_sense/+/data</property>
<property name="username">admin</property> <property name="username">admin</property>
<property name="contentValidationParams">device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:2</property> <property name="contentValidationParams">device_id_json_path:event.metaData.deviceId,device_id_topic_hierarchy_index:3</property>
<property name="contentValidation">default</property> <property name="contentValidation">default</property>
<property name="dcrUrl">https://localhost:9443/dynamic-client-web/register</property> <property name="dcrUrl">https://localhost:9443/dynamic-client-web/register</property>
<property name="url">tcp://localhost:1883</property> <property name="url">tcp://localhost:1883</property>

@ -47,7 +47,7 @@ public class AndroidSenseConstants {
public static final String SENSOR_ROTATION = "rotation"; public static final String SENSOR_ROTATION = "rotation";
public static final String SENSOR_WORDCOUNT = "wordcounter"; public static final String SENSOR_WORDCOUNT = "wordcounter";
//MQTT Subscribe topic //MQTT Subscribe topic
public static final String MQTT_SUBSCRIBE_WORDS_TOPIC = "wso2/android_sense/+/data"; public static final String MQTT_SUBSCRIBE_WORDS_TOPIC = "wso2/+/android_sense/+/data";
public static final String DATA_SOURCE_NAME = "jdbc/AndroidSenseDM_DB"; public static final String DATA_SOURCE_NAME = "jdbc/AndroidSenseDM_DB";
public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super"; public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super";
} }

@ -47,8 +47,7 @@ public interface ArduinoControllerService {
@Path("device/{deviceId}/bulb") @Path("device/{deviceId}/bulb")
@POST @POST
@Feature(code = "bulb", name = "Control Bulb", type = "operation", description = "Control Bulb on Arduino Uno") @Feature(code = "bulb", name = "Control Bulb", type = "operation", description = "Control Bulb on Arduino Uno")
Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state);
@FormParam("state") String state);
@Path("device/sensor") @Path("device/sensor")
@POST @POST
@ -57,12 +56,12 @@ public interface ArduinoControllerService {
@Path("device/{deviceId}/controls") @Path("device/{deviceId}/controls")
@GET @GET
Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol); Response readControls(@PathParam("deviceId") String deviceId);
@Path("device/temperature") @Path("device/temperature")
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request); Response pushTemperatureData(final DeviceData dataMsg);
/** /**
* Retreive Sensor data for the device type * Retreive Sensor data for the device type

@ -76,12 +76,9 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
@Override @Override
@Path("device/{deviceId}/bulb") @Path("device/{deviceId}/bulb")
@POST @POST
public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, public Response switchBulb(@PathParam("deviceId") String deviceId, @QueryParam("state") String state) {
@FormParam("state") String state) {
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId); LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
String operation = "BULB:" + state.toUpperCase(); String operation = "BULB:" + state.toUpperCase();
log.info(operation);
if (deviceControlList == null) { if (deviceControlList == null) {
deviceControlList = new LinkedList<>(); deviceControlList = new LinkedList<>();
deviceControlList.add(operation); deviceControlList.add(operation);
@ -99,7 +96,6 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
public Response pushData(DeviceData dataMsg) { public Response pushData(DeviceData dataMsg) {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
float pinData = dataMsg.value;
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" + log.warn("An error occured whilst trying to publish pin data of Arduino with ID [" +
deviceId + "] of owner [" + owner + "]"); deviceId + "] of owner [" + owner + "]");
@ -111,7 +107,7 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
@Override @Override
@Path("device/{deviceId}/controls") @Path("device/{deviceId}/controls")
@GET @GET
public Response readControls(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol) { public Response readControls(@PathParam("deviceId") String deviceId) {
String result; String result;
LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId); LinkedList<String> deviceControlList = internalControlsQueue.get(deviceId);
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -142,10 +138,9 @@ public class ArduinoControllerServiceImpl implements ArduinoControllerService {
@Path("device/temperature") @Path("device/temperature")
@POST @POST
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
public Response pushTemperatureData(final DeviceData dataMsg, @Context HttpServletRequest request) { public Response pushTemperatureData(final DeviceData dataMsg) {
String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String owner = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
String deviceId = dataMsg.deviceId; String deviceId = dataMsg.deviceId;
float temperature = dataMsg.value;
if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) { if (!ArduinoServiceUtils.publishToDAS(dataMsg.deviceId, dataMsg.value)) {
log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId + log.warn("An error occured whilst trying to publish temperature data of Arduino with ID [" + deviceId +
"] of owner [" + owner + "]"); "] of owner [" + owner + "]");

@ -34,7 +34,6 @@ import javax.ws.rs.core.Response;
@Path("enrollment") @Path("enrollment")
@API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"}) @API(name = "arduino_mgt", version = "1.0.0", context = "/arduino_mgt", tags = {"arduino"})
@DeviceType(value = "arduino")
public interface ArduinoManagerService { public interface ArduinoManagerService {
@Path("devices/{device_id}") @Path("devices/{device_id}")
@ -61,9 +60,4 @@ public interface ArduinoManagerService {
@GET @GET
@Produces("application/octet-stream") @Produces("application/octet-stream")
Response downloadSketch(@QueryParam("deviceName") String customDeviceName); Response downloadSketch(@QueryParam("deviceName") String customDeviceName);
@Path("devices/generate_link")
@GET
Response generateSketchLink(@QueryParam("deviceName") String deviceName);
} }

@ -167,29 +167,6 @@ public class ArduinoManagerServiceImpl implements ArduinoManagerService {
} }
} }
@Override
@Path("devices/generate_link")
@GET
public Response generateSketchLink(@QueryParam("deviceName") String deviceName) {
try {
ZipArchive zipFile = createDownloadFile(APIUtil.getAuthenticatedUser(), deviceName);
Response.ResponseBuilder rb = Response.ok(zipFile.getDeviceId());
return rb.build();
} catch (IllegalArgumentException ex) {
return Response.status(400).entity(ex.getMessage()).build();//bad request
} catch (DeviceManagementException ex) {
return Response.status(500).entity(ex.getMessage()).build();
} catch (JWTClientException ex) {
return Response.status(500).entity(ex.getMessage()).build();
} catch (DeviceControllerException ex) {
return Response.status(500).entity(ex.getMessage()).build();
} catch (APIManagerException ex) {
return Response.status(500).entity(ex.getMessage()).build();
} catch (UserStoreException ex) {
return Response.status(500).entity(ex.getMessage()).build();
}
}
private ZipArchive createDownloadFile(String owner, String deviceName) private ZipArchive createDownloadFile(String owner, String deviceName)
throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException, throws DeviceManagementException, JWTClientException, DeviceControllerException, APIManagerException,
UserStoreException { UserStoreException {

Loading…
Cancel
Save