|
|
@ -36,6 +36,7 @@ import org.wso2.carbon.device.mgt.iot.DeviceManagement;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.DeviceValidator;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.DeviceValidator;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.apimgt.AccessTokenInfo;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.apimgt.TokenClient;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.mqtt.MqttConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppAccount;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppConfig;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
|
|
|
|
import org.wso2.carbon.device.mgt.iot.controlqueue.xmpp.XmppServerClient;
|
|
|
@ -83,8 +84,8 @@ import java.util.List;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.UUID;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
import java.util.concurrent.ConcurrentHashMap;
|
|
|
|
|
|
|
|
|
|
|
|
@API( name="virtual_firealarm", version="1.0.0", context="/virtual_firealarm")
|
|
|
|
@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm")
|
|
|
|
@DeviceType( value = "virtual_firealarm")
|
|
|
|
@DeviceType(value = "virtual_firealarm")
|
|
|
|
public class VirtualFireAlarmService {
|
|
|
|
public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
private static Log log = LogFactory.getLog(VirtualFireAlarmService.class);
|
|
|
|
private static Log log = LogFactory.getLog(VirtualFireAlarmService.class);
|
|
|
@ -104,9 +105,7 @@ public class VirtualFireAlarmService {
|
|
|
|
private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector;
|
|
|
|
private VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector;
|
|
|
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
|
|
|
private ConcurrentHashMap<String, String> deviceToIpMap = new ConcurrentHashMap<>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param verificationManager
|
|
|
|
* @param verificationManager
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setVerificationManager(
|
|
|
|
public void setVerificationManager(
|
|
|
@ -116,48 +115,43 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param virtualFireAlarmXMPPConnector
|
|
|
|
* @param virtualFireAlarmXMPPConnector
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setVirtualFireAlarmXMPPConnector(
|
|
|
|
public void setVirtualFireAlarmXMPPConnector(
|
|
|
|
final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
|
|
|
|
final VirtualFireAlarmXMPPConnector virtualFireAlarmXMPPConnector) {
|
|
|
|
this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
|
|
|
|
this.virtualFireAlarmXMPPConnector = virtualFireAlarmXMPPConnector;
|
|
|
|
|
|
|
|
|
|
|
|
Runnable mqttStarter = new Runnable() {
|
|
|
|
if (MqttConfig.getInstance().isEnabled()) {
|
|
|
|
@Override
|
|
|
|
Runnable mqttStarter = new Runnable() {
|
|
|
|
public void run() {
|
|
|
|
@Override
|
|
|
|
virtualFireAlarmXMPPConnector.initConnector();
|
|
|
|
public void run() {
|
|
|
|
virtualFireAlarmXMPPConnector.connect();
|
|
|
|
virtualFireAlarmXMPPConnector.initConnector();
|
|
|
|
}
|
|
|
|
virtualFireAlarmXMPPConnector.connect();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
Thread mqttStarterThread = new Thread(mqttStarter);
|
|
|
|
Thread mqttStarterThread = new Thread(mqttStarter);
|
|
|
|
mqttStarterThread.setDaemon(true);
|
|
|
|
mqttStarterThread.setDaemon(true);
|
|
|
|
mqttStarterThread.start();
|
|
|
|
mqttStarterThread.start();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
log.warn("MQTT disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmMQTTConnector not started.");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param virtualFireAlarmMQTTConnector
|
|
|
|
* @param virtualFireAlarmMQTTConnector
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public void setVirtualFireAlarmMQTTConnector(
|
|
|
|
public void setVirtualFireAlarmMQTTConnector(
|
|
|
|
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
|
|
|
|
final VirtualFireAlarmMQTTConnector virtualFireAlarmMQTTConnector) {
|
|
|
|
this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
|
|
|
this.virtualFireAlarmMQTTConnector = virtualFireAlarmMQTTConnector;
|
|
|
|
|
|
|
|
if (XmppConfig.getInstance().isEnabled()) {
|
|
|
|
// Runnable xmppStarter = new Runnable() {
|
|
|
|
virtualFireAlarmMQTTConnector.connect();
|
|
|
|
// @Override
|
|
|
|
} else {
|
|
|
|
// public void run() {
|
|
|
|
log.warn("XMPP disabled in 'devicemgt-config.xml'. Hence, VirtualFireAlarmXMPPConnector not started.");
|
|
|
|
virtualFireAlarmMQTTConnector.connect();
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// };
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// Thread xmppStarterThread = new Thread(xmppStarter);
|
|
|
|
|
|
|
|
// xmppStarterThread.setDaemon(true);
|
|
|
|
|
|
|
|
// xmppStarterThread.start();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public VerificationManager getVerificationManager() {
|
|
|
|
public VerificationManager getVerificationManager() {
|
|
|
@ -165,7 +159,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
|
|
|
|
public VirtualFireAlarmXMPPConnector getVirtualFireAlarmXMPPConnector() {
|
|
|
@ -173,7 +166,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
|
|
|
|
public VirtualFireAlarmMQTTConnector getVirtualFireAlarmMQTTConnector() {
|
|
|
@ -186,7 +178,6 @@ public class VirtualFireAlarmService {
|
|
|
|
--------------------------------------------------------------------------------------- */
|
|
|
|
--------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @param name
|
|
|
|
* @param name
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
@ -238,7 +229,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @param response
|
|
|
|
* @param response
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -267,7 +257,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @param name
|
|
|
|
* @param name
|
|
|
|
* @param response
|
|
|
|
* @param response
|
|
|
@ -312,7 +301,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -340,7 +328,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param username
|
|
|
|
* @param username
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -377,7 +364,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
|
* @param customDeviceName
|
|
|
|
* @param customDeviceName
|
|
|
|
* @param sketchType
|
|
|
|
* @param sketchType
|
|
|
@ -411,7 +397,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
|
* @param customDeviceName
|
|
|
|
* @param customDeviceName
|
|
|
|
* @param sketchType
|
|
|
|
* @param sketchType
|
|
|
@ -439,7 +424,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
|
* @param customDeviceName
|
|
|
|
* @param customDeviceName
|
|
|
|
* @param sketchType
|
|
|
|
* @param sketchType
|
|
|
@ -507,7 +491,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
private static String shortUUID() {
|
|
|
|
private static String shortUUID() {
|
|
|
@ -522,7 +505,6 @@ public class VirtualFireAlarmService {
|
|
|
|
--------------------------------------------------------------------------------------- */
|
|
|
|
--------------------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceIP
|
|
|
|
* @param deviceIP
|
|
|
@ -563,7 +545,6 @@ public class VirtualFireAlarmService {
|
|
|
|
Called by an external client intended to control the Virtual FireAlarm bulb */
|
|
|
|
Called by an external client intended to control the Virtual FireAlarm bulb */
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @param protocol
|
|
|
|
* @param protocol
|
|
|
@ -722,7 +703,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param owner
|
|
|
|
* @param owner
|
|
|
|
* @param deviceId
|
|
|
|
* @param deviceId
|
|
|
|
* @param protocol
|
|
|
|
* @param protocol
|
|
|
@ -755,7 +735,7 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Sending request to read virtual-firealarm-temperature of device " +
|
|
|
|
log.debug("Sending request to read virtual-firealarm-temperature of device " +
|
|
|
|
"[" + deviceId + "] via " + protocolString);
|
|
|
|
"[" + deviceId + "] via " + protocolString);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -767,9 +747,9 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(
|
|
|
|
String temperatureValue = VirtualFireAlarmServiceUtils.sendCommandViaHTTP(
|
|
|
|
deviceHTTPEndpoint,
|
|
|
|
deviceHTTPEndpoint,
|
|
|
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
|
|
|
VirtualFireAlarmConstants.TEMPERATURE_CONTEXT,
|
|
|
|
false);
|
|
|
|
false);
|
|
|
|
|
|
|
|
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId,
|
|
|
|
SensorDataManager.getInstance().setSensorRecord(deviceId,
|
|
|
|
VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
|
|
VirtualFireAlarmConstants.SENSOR_TEMP,
|
|
|
@ -801,7 +781,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param dataMsg
|
|
|
|
* @param dataMsg
|
|
|
|
* @param response
|
|
|
|
* @param response
|
|
|
|
*/
|
|
|
|
*/
|
|
|
@ -818,12 +797,12 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
if (registeredIp == null) {
|
|
|
|
if (registeredIp == null) {
|
|
|
|
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
|
|
|
log.warn("Unregistered IP: Temperature Data Received from an un-registered IP " +
|
|
|
|
deviceIp + " for device ID - " + deviceId);
|
|
|
|
deviceIp + " for device ID - " + deviceId);
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
} else if (!registeredIp.equals(deviceIp)) {
|
|
|
|
} else if (!registeredIp.equals(deviceIp)) {
|
|
|
|
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId +
|
|
|
|
log.warn("Conflicting IP: Received IP is " + deviceIp + ". Device with ID " + deviceId +
|
|
|
|
" is already registered under some other IP. Re-registration required");
|
|
|
|
" is already registered under some other IP. Re-registration required");
|
|
|
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
|
|
|
response.setStatus(Response.Status.CONFLICT.getStatusCode());
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -839,7 +818,6 @@ public class VirtualFireAlarmService {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param operation
|
|
|
|
* @param operation
|
|
|
|
* @param message
|
|
|
|
* @param message
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
@ -922,7 +900,6 @@ public class VirtualFireAlarmService {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
|
|
|
|
* @param operation
|
|
|
|
* @param operation
|
|
|
|
* @param inputStream
|
|
|
|
* @param inputStream
|
|
|
|
* @return
|
|
|
|
* @return
|
|
|
|