|
|
@ -34,14 +34,14 @@ public class ServiceUtils {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param owner name of device owner
|
|
|
|
* @param owner name of device owner
|
|
|
|
* @param deviceId unique identifier of the device
|
|
|
|
* @param deviceId unique identifier of the device
|
|
|
|
* @param sensorValue current value of sensor which is set at agent side
|
|
|
|
* @param sensorValue value of sensor which is set at agent side
|
|
|
|
* @return status
|
|
|
|
* @return status
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static boolean publishTemperatureToDAS(String owner, String deviceId,
|
|
|
|
public static boolean publishTemperatureToDAS(String owner, String deviceId,
|
|
|
|
String sensorValue) {
|
|
|
|
String sensorValue) {
|
|
|
|
float temperature = Float.parseFloat(sensorValue);
|
|
|
|
float temperature = Float.parseFloat(sensorValue);
|
|
|
|
Object payloadCurrent[] = {temperature};
|
|
|
|
Object payload[] = {temperature};
|
|
|
|
return publishToDAS(owner, deviceId, payloadCurrent, ORG_WSO2_IOT_DEVICES_TEMPERATURE);
|
|
|
|
return publishToDAS(owner, deviceId, payload, ORG_WSO2_IOT_DEVICES_TEMPERATURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
@ -49,17 +49,17 @@ public class ServiceUtils {
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @param owner name of device owner
|
|
|
|
* @param owner name of device owner
|
|
|
|
* @param deviceId unique identifier of the device
|
|
|
|
* @param deviceId unique identifier of the device
|
|
|
|
* @param sensorValue current value of sensor which is set at agent side
|
|
|
|
* @param sensorValue value of sensor which is set at agent side
|
|
|
|
* @return status
|
|
|
|
* @return status
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static boolean publishHumidityToDAS(String owner, String deviceId,
|
|
|
|
public static boolean publishHumidityToDAS(String owner, String deviceId,
|
|
|
|
String sensorValue) {
|
|
|
|
String sensorValue) {
|
|
|
|
float humidity = Float.parseFloat(sensorValue);
|
|
|
|
float humidity = Float.parseFloat(sensorValue);
|
|
|
|
Object payloadCurrent[] = {humidity};
|
|
|
|
Object payload[] = {humidity};
|
|
|
|
return publishToDAS(owner, deviceId, payloadCurrent, ORG_WSO2_IOT_DEVICES_HUMIDITY);
|
|
|
|
return publishToDAS(owner, deviceId, payload, ORG_WSO2_IOT_DEVICES_HUMIDITY);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static boolean publishToDAS(String owner, String deviceId, Object[] payloadCurrent,
|
|
|
|
private static boolean publishToDAS(String owner, String deviceId, Object[] payload,
|
|
|
|
String definition) {
|
|
|
|
String definition) {
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext.startTenantFlow();
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
|
@ -72,7 +72,7 @@ public class ServiceUtils {
|
|
|
|
Object metaData[] = {owner, DeviceTypeConstants.DEVICE_TYPE, deviceId, System.currentTimeMillis()};
|
|
|
|
Object metaData[] = {owner, DeviceTypeConstants.DEVICE_TYPE, deviceId, System.currentTimeMillis()};
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
deviceAnalyticsService.publishEvent(definition, SENSOR_STREAM_VERSION, metaData,
|
|
|
|
deviceAnalyticsService.publishEvent(definition, SENSOR_STREAM_VERSION, metaData,
|
|
|
|
new Object[0], payloadCurrent);
|
|
|
|
new Object[0], payload);
|
|
|
|
} catch (DataPublisherConfigurationException e) {
|
|
|
|
} catch (DataPublisherConfigurationException e) {
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|