diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java index 275a8f221..82fa7eb32 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java @@ -85,7 +85,7 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { } catch (TransportHandlerException e) { log.warn(AgentConstants.LOG_APPENDER + "Subscription to MQTT Broker at: " + - mqttBrokerEndPoint + " failed"); + mqttBrokerEndPoint + " failed"); agentManager.updateAgentStatus("Subscription to broker failed."); } @@ -118,16 +118,6 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { receivedMessage = message.toString(); if(!receivedMessage.contains("policyDefinition")){ receivedMessage = AgentUtilOperations.extractMessageFromPayload(receivedMessage); - }else{ - JSONObject jsonMessage = new JSONObject(receivedMessage); - updateCEPPolicy(jsonMessage.getString("policyDefinition")); - } - log.info(AgentConstants.LOG_APPENDER + "Message [" + receivedMessage + "] was received"); - } catch (AgentCoreOperationException e) { - log.warn(AgentConstants.LOG_APPENDER + "Could not extract message from payload.", e); - return; - } - String[] controlSignal = receivedMessage.split(":"); // message- ":" format.(ex: "BULB:ON", "TEMPERATURE", "HUMIDITY") @@ -168,9 +158,8 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { publishToQueue(humidPublishTopic, securePayLoad); break; - case AgentConstants.POLICY_SIGNAL: - String policy = controlSignal[1]; - updateCEPPolicy(policy); + case AgentConstants.POLICY_REVOKE: + break; default: log.warn(AgentConstants.LOG_APPENDER + "'" + controlSignal[0] + @@ -185,6 +174,17 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { agentManager.getAgentConfigs().getMqttBrokerEndpoint() + " failed"); } + } else { + JSONObject jsonMessage = new JSONObject(receivedMessage); + updateCEPPolicy(jsonMessage.getString("policyDefinition")); + } + log.info(AgentConstants.LOG_APPENDER + "Message [" + receivedMessage + "] was received"); + } catch (AgentCoreOperationException e) { + log.warn(AgentConstants.LOG_APPENDER + "Could not extract message from payload.", e); + return; + } + + } @Override @@ -247,8 +247,8 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { } catch (MqttException e) { if (log.isDebugEnabled()) { log.warn(AgentConstants.LOG_APPENDER + - "Unable to 'STOP' MQTT connection at broker at: " + - mqttBrokerEndPoint); + "Unable to 'STOP' MQTT connection at broker at: " + + mqttBrokerEndPoint); } try { diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java index 1e732c752..81cb5ae00 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java @@ -57,7 +57,8 @@ public class AgentConstants { --------------------------------------------------------------------------------------- */ public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; - public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s/#"; + //public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s/#"; + public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s/operation/#"; public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/temperature"; /* --------------------------------------------------------------------------------------- XMPP Connection specific information @@ -104,7 +105,7 @@ public class AgentConstants { --------------------------------------------------------------------------------------- */ public static final String BULB_CONTROL = "BULB"; public static final String TEMPERATURE_CONTROL = "TEMPERATURE"; - public static final String POLICY_SIGNAL = "POLICY"; + public static final String POLICY_REVOKE = "POLICY_REVOKE"; public static final String HUMIDITY_CONTROL = "HUMIDITY"; public static final String CONTROL_ON = "ON"; public static final String CONTROL_OFF = "OFF"; diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java index a2d9cfacf..ae76433d2 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java @@ -288,6 +288,7 @@ public class AgentUtilOperations { } return actualMessage; } else { + //System.out.println("\n . Not enrolled .\n"); return message; } } diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java index bfa29ca58..57fbc4ec4 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java @@ -63,7 +63,7 @@ public class AgentConstants { --------------------------------------------------------------------------------------- */ public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; - public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s"; + public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s/operation/#"; public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/temperature"; /* --------------------------------------------------------------------------------------- diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java index f04922d58..69cee6588 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java @@ -34,6 +34,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; +import org.wso2.carbon.device.mgt.core.operation.mgt.ConfigOperation; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.constants.VirtualFireAlarmConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil; @@ -96,9 +97,8 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { String publishTopic = APIUtil.getTenantDomainOftheUser() + "/" + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; - Operation commandOp = new CommandOperation(); + ConfigOperation commandOp = new ConfigOperation(); commandOp.setCode("buzz"); - commandOp.setType(Operation.Type.COMMAND); commandOp.setEnabled(true); commandOp.setPayLoad(actualMessage);