try {
// Initialize sensors
sen.init();
+ System.out.println("DEBUG: Initialized smartthings sensor! ID: " + sensorId + " Room ID: " + rm.getRoomID());
+ senDetectStatus.put(sensorId, false);
+ System.out.println("DEBUG: Initialized sensor detection to false!");
sen.setId(sensorId++);
- System.out.println("DEBUG: Initialized smartthings sensor!");
+ sen.registerCallback(this);
+ System.out.println("DEBUG: Registered sensor callback!");
} catch (Exception e) {
e.printStackTrace();
}
*/
private void initCameras(RoomSmart rm) {
- // Get and init the cameras for this specific room
+ // Get and init the IAS sensors for this specific room
HashSet<CameraSmart> cameras = roomCameraRelation.get(rm);
// Setup the cameras, start them all and assign each one a motion detector
- for (CameraSmart cam : camSet.values()) {
+ for (CameraSmart cam : cameras) {
// Each camera will have a motion detector unique to it since the motion detection has state
MotionDetection mo = new MotionDetection(12, 0.5f, 10, 10);
// Remember which motion detector is for what camera
camMotionDetect.put(cam, mo);
+
+ // Initialize detection to false
+ camDetectStatus.put(cam, false);
}
}
* @param _numberOfSeconds [int] , Number of seconds in the past that we consider recent.
* @param _upperThreshold [int] , Number of seconds as an upper bound before we turn off.
*
- * @return [void] None.
+ * @return [boolean] None.
*/
- private void updateCameraStatus(RoomSmart _room, int _numberOfSeconds) {
+ private boolean roomDidHaveMotionRecently(RoomSmart _room, int _numberOfSeconds) {
long currentTimeSeconds = (new Date()).getTime() / 1000;
// Loop through all the cameras in the room
} else {
// motionTime == null means this is the initialization phase
// so we put false
- camDetectStatus.put(cam, false);
+ return false;
}
// Did detect motion recently
if (Math.abs(currentTimeSeconds - lastDetectedMotionSeconds) < _numberOfSeconds) {
- camDetectStatus.put(cam, true);
+ return true;
}
}
+
+ return false;
}
System.out.println("DEBUG: Sensor reading value: " + _value);
if(_activeValue) {
-
+ System.out.println("DEBUG: Sensor is detecting something: " + _activeValue);
senDetectStatus.put(_sensorId, true);
} else {
-
+ //System.out.println("DEBUG: Sensor is not detecting something: " + _activeValue);
senDetectStatus.put(_sensorId, false);
}
}
for (RoomSmart room : roomSet.values()) {
// Update status of camera
- updateCameraStatus(room, MOTION_TIME_THRESHOLD);
+ updateCameraStatus(room);
// Update status of doorlocks
//updateDoorLockStatus(room);
}
+ /** Update the status of all devices
+ *
+ * @return [void] None.
+ */
+ private void updateCameraStatus(RoomSmart room) {
+
+ HashSet<CameraSmart> cameras = roomCameraRelation.get(room);
+ if (roomDidHaveMotionRecently(room, MOTION_TIME_THRESHOLD)) {
+
+ // Motion was detected
+ System.out.println("DEBUG: Camera detected something!");
+ for(CameraSmart cam : cameras)
+ camDetectStatus.put(cam, true);
+ } else {
+
+ // No motion was detected
+ //System.out.println("DEBUG: Camera didn't detect anything!");
+ for(CameraSmart cam : cameras)
+ camDetectStatus.put(cam, false);
+ }
+ }
+
/** Method to turn on alarms
*
* @return [void] None.
for (SmartthingsSensorSmart sensor : roomSensorRelation.get(room)) {
// Get the right sensor and the right detection status (true or false)
+ //System.out.println("ABOUT TO DETECT: Reading sensor: " + sensor.getId());
if (senDetectStatus.get(sensor.getId())) {
zoneId = room.getRoomID();
turnOnAlarms(zoneId);
System.out.println("DETECTION: Sensor active in room: " + zoneId);
+ System.out.println("DETECTION: Detection by sensor: " + sensor.getId());
}
}
}
initCameras(rm);
// Init all doorlocks
- //initDoorLocks(rm);
+ //initDoorLocks();
// Init all outlets
- //initOutlets(rm);
+ //initOutlets();
}
// Init all alarms
initAlarms();
+ System.out.println("DEBUG: Initialized all devices! Now starting detection loop!");
+
// Run the main loop that will keep checking the sensors and cameras periodically
while (true) {
private static String STR_ZB_GATEWAY_PORT;
private static String STR_ZB_IOTMASTER_PORT;
private static String STR_NUM_CALLBACK_PORTS;
+ private static String STR_JVM_INIT_HEAP_SIZE;
+ private static String STR_JVM_MAX_HEAP_SIZE;
private static boolean BOOL_VERBOSE;
/**
STR_ZB_GATEWAY_PORT = null;
STR_ZB_IOTMASTER_PORT = null;
STR_NUM_CALLBACK_PORTS = null;
+ STR_JVM_INIT_HEAP_SIZE = null;
+ STR_JVM_MAX_HEAP_SIZE = null;
BOOL_VERBOSE = false;
}
STR_ZB_GATEWAY_PORT = prop.getProperty("ZIGBEE_GATEWAY_PORT");
STR_ZB_IOTMASTER_PORT = prop.getProperty("ZIGBEE_IOTMASTER_PORT");
STR_NUM_CALLBACK_PORTS = prop.getProperty("NUMBER_CALLBACK_PORTS");
+ STR_JVM_INIT_HEAP_SIZE = prop.getProperty("JVM_INIT_HEAP_SIZE");
+ STR_JVM_MAX_HEAP_SIZE = prop.getProperty("JVM_MAX_HEAP_SIZE");
if(prop.getProperty("VERBOSE").equals(STR_YES)) {
BOOL_VERBOSE = true;
}
RuntimeOutput.print("STR_ZB_GATEWAY_PORT=" + STR_ZB_GATEWAY_PORT, BOOL_VERBOSE);
RuntimeOutput.print("STR_ZB_IOTMASTER_PORT=" + STR_ZB_IOTMASTER_PORT, BOOL_VERBOSE);
RuntimeOutput.print("STR_NUM_CALLBACK_PORTS=" + STR_NUM_CALLBACK_PORTS, BOOL_VERBOSE);
+ RuntimeOutput.print("STR_JVM_INIT_HEAP_SIZE=" + STR_JVM_INIT_HEAP_SIZE, BOOL_VERBOSE);
+ RuntimeOutput.print("STR_JVM_MAX_HEAP_SIZE=" + STR_JVM_MAX_HEAP_SIZE, BOOL_VERBOSE);
RuntimeOutput.print("BOOL_VERBOSE=" + BOOL_VERBOSE, BOOL_VERBOSE);
RuntimeOutput.print("IoTMaster: Information extracted successfully!", BOOL_VERBOSE);
}
* @params inStream ObjectOutputStream communication
* @return void
*/
- private void instrumentIoTSetDevice(String strFieldIdentifier, String strFieldName, String strIoTSlaveObjectHostAdd,
+ private void instrumentIoTSetDevice(String strFieldIdentifier, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
ObjectInputStream inStream, ObjectOutputStream outStream)
throws IOException, ClassNotFoundException, InterruptedException {
arrFieldValues = listObject.get(iRow);
// Get device address - if 00:00:00:00:00:00 that means it needs the driver object address (self)
String strDeviceAddress = null;
+ String strDeviceAddressKey = null;
if (arrFieldValues[0].equals(STR_SELF_MAC_ADD)) {
strDeviceAddress = strIoTSlaveObjectHostAdd;
+ strDeviceAddressKey = strObjName + "-" + strIoTSlaveObjectHostAdd;
} else {
strDeviceAddress = routerConfig.getIPFromMACAddress((String) arrFieldValues[0]);
+ strDeviceAddressKey = strObjName + "-" + strDeviceAddress;
}
int iDestDeviceDriverPort = (int) arrFieldValues[1];
String strProtocol = (String) arrFieldValues[2];
bDstPortWildCard = (boolean) arrFieldValues[4];
}
// Add the port connection into communication handler - if it's not assigned yet
- if (commHan.getComPort(strDeviceAddress) == null) {
- commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
+ if (commHan.getComPort(strDeviceAddressKey) == null) {
+ commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
}
+
+ // TODO: DEBUG!!!
+ System.out.println("\n\n DEBUG: InstrumentSetDevice: Object Name: " + strObjName);
+ System.out.println("DEBUG: InstrumentSetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
+ System.out.println("DEBUG: InstrumentSetDevice: Device address: " + strDeviceAddressKey + "\n\n");
+
// Send address one by one
Message msgGetIoTSetObj = null;
if (bDstPortWildCard) {
- String strUniqueDev = strDeviceAddress + ":" + iRow;
+ String strUniqueDev = strDeviceAddressKey + ":" + iRow;
msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
strDeviceAddress, commHan.getAdditionalPort(strUniqueDev), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
} else
msgGetIoTSetObj = new MessageGetDeviceObject(IoTCommCode.GET_DEVICE_IOTSET_OBJECT,
- strDeviceAddress, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
+ strDeviceAddress, commHan.getComPort(strDeviceAddressKey), iDestDeviceDriverPort, bSrcPortWildCard, bDstPortWildCard);
commMasterToSlave(msgGetIoTSetObj, "Get IoTSet objects!", inStream, outStream);
}
// Reinitialize IoTSet on device object
* @params inStream ObjectOutputStream communication
* @return void
*/
- private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strFieldName, String strIoTSlaveObjectHostAdd,
+ private void instrumentIoTSetZBDevice(Map.Entry<String,Object> map, String strObjName, String strFieldName, String strIoTSlaveObjectHostAdd,
ObjectInputStream inStream, ObjectOutputStream outStream)
throws IOException, ClassNotFoundException, InterruptedException {
commMasterToSlave(msgCrtIoTSet, "Create new IoTSet for IoTZigbeeAddress!", inStream, outStream);
// Prepare ZigbeeConfig
String strZigbeeGWAddress = routerConfig.getIPFromMACAddress(STR_ZB_GATEWAY_ADDRESS);
+ String strZigbeeGWAddressKey = strObjName + "-" + strZigbeeGWAddress;
int iZigbeeGWPort = Integer.parseInt(STR_ZB_GATEWAY_PORT);
int iZigbeeIoTMasterPort = Integer.parseInt(STR_ZB_IOTMASTER_PORT);
commHan.addDevicePort(iZigbeeIoTMasterPort);
ZigbeeConfig zbConfig = new ZigbeeConfig(strZigbeeGWAddress, iZigbeeGWPort, iZigbeeIoTMasterPort,
BOOL_VERBOSE);
// Add the port connection into communication handler - if it's not assigned yet
- if (commHan.getComPort(strZigbeeGWAddress) == null) {
- commHan.addPortConnection(strIoTSlaveObjectHostAdd, strZigbeeGWAddress);
+ if (commHan.getComPort(strZigbeeGWAddressKey) == null) {
+ commHan.addPortConnection(strIoTSlaveObjectHostAdd, strZigbeeGWAddressKey);
}
int iRows = setInstrumenter.numberOfRows();
RuntimeOutput.print("IoTMaster: Number of rows for IoTZigbeeAddress: " + iRows, BOOL_VERBOSE);
+
+ // TODO: DEBUG!!!
+ System.out.println("\n\n DEBUG: InstrumentZigbeeDevice: Object Name: " + strObjName);
+ System.out.println("DEBUG: InstrumentZigbeeDevice: Port number: " + commHan.getComPort(strZigbeeGWAddressKey));
+ System.out.println("DEBUG: InstrumentZigbeeDevice: Device address: " + strZigbeeGWAddress + "\n\n");
+
// Transfer the address
for(int iRow=0; iRow<iRows; iRow++) {
arrFieldValues = setInstrumenter.fieldValues(iRow);
// Get device address
String strZBDevAddress = (String) arrFieldValues[0];
// Send policy to Zigbee gateway - TODO: Need to clear policy first?
- zbConfig.setPolicy(strIoTSlaveObjectHostAdd, commHan.getComPort(strZigbeeGWAddress), strZBDevAddress);
+ zbConfig.setPolicy(strIoTSlaveObjectHostAdd, commHan.getComPort(strZigbeeGWAddressKey), strZBDevAddress);
// Send address one by one
Message msgGetIoTSetZBObj = new MessageGetSimpleDeviceObject(IoTCommCode.GET_ZB_DEV_IOTSET_OBJECT,
strZBDevAddress);
}
zbConfig.closeConnection();
// Reinitialize IoTSet on device object
- commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD),
- "Reinitialize IoTSet fields!", inStream, outStream);
+ commMasterToSlave(new MessageSimple(IoTCommCode.REINITIALIZE_IOTSET_FIELD), "Reinitialize IoTSet fields!", inStream, outStream);
}
objAddInitHand.addField(strFieldIdentifier, arrFieldValues); // Save this for object instantiation
// Get device address - if 00:00:00:00:00:00 that means it needs the driver object address (self)
String strDeviceAddress = null;
+ String strDeviceAddressKey = null;
if (arrFieldValues[0].equals(STR_SELF_MAC_ADD)) {
strDeviceAddress = strIoTSlaveObjectHostAdd;
- } else {
+ strDeviceAddressKey = strObjName + "-" + strIoTSlaveObjectHostAdd;
+ } else { // Concatenate object name and IP address to give unique key - for a case where there is one device for multiple drivers
strDeviceAddress = routerConfig.getIPFromMACAddress((String) arrFieldValues[0]);
+ strDeviceAddressKey = strObjName + "-" + strDeviceAddress;
}
int iDestDeviceDriverPort = (int) arrFieldValues[1];
String strProtocol = (String) arrFieldValues[2];
// Add the port connection into communication handler - if it's not assigned yet
- if (commHan.getComPort(strDeviceAddress) == null) {
- commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddress);
- }
+ if (commHan.getComPort(strDeviceAddressKey) == null)
+ commHan.addPortConnection(strIoTSlaveObjectHostAdd, strDeviceAddressKey);
boolean bDstPortWildCard = false;
// Recognize this and allocate different ports for it
if (arrFieldValues.length > 3) {
bDstPortWildCard = (boolean) arrFieldValues[4];
if (bDstPortWildCard) { // This needs a unique source port
- String strUniqueDev = strDeviceAddress + ":" + iRow;
+ String strUniqueDev = strDeviceAddressKey + ":" + iRow;
commHan.addAdditionalPort(strUniqueDev);
}
}
+
+ // TODO: DEBUG!!!
+ System.out.println("\n\n DEBUG: InstrumentPolicySetDevice: Object Name: " + strObjName);
+ System.out.println("DEBUG: InstrumentPolicySetDevice: Port number: " + commHan.getComPort(strDeviceAddressKey));
+ System.out.println("DEBUG: InstrumentPolicySetDevice: Device address: " + strDeviceAddressKey + "\n\n");
+
+
// Send routing policy to router for device drivers and devices
// ROUTING POLICY: RMI communication - RMI registry and stub ports
if((iDestDeviceDriverPort == -1) && (!strProtocol.equals(STR_NO_PROTOCOL))) {
// Port number -1 means that we don't set the policy strictly to port number level
// "nopro" = no protocol specified for just TCP or just UDP (can be both used as well)
// ROUTING POLICY: Device driver and device
- routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
- strProtocol);
+ routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol);
// ROUTING POLICY: Send to the compute node where the device driver is
- routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd,
- strDeviceAddress, strProtocol);
+ routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol);
} else if((iDestDeviceDriverPort == -1) && (strProtocol.equals(STR_NO_PROTOCOL))) {
routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress);
routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress);
// This is a TCP protocol that connects, e.g. a phone to our runtime system
// that provides a gateway access (accessed through destination port number)
commHan.addDevicePort(iDestDeviceDriverPort);
- routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
- STR_TCP_PROTOCOL, iDestDeviceDriverPort);
- routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress,
- STR_TCP_PROTOCOL, iDestDeviceDriverPort);
+ routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort);
+ routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, STR_TCP_PROTOCOL, iDestDeviceDriverPort);
routerConfig.configureRouterHTTPPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress);
routerConfig.configureHostHTTPPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress);
} else {
// Other port numbers...
commHan.addDevicePort(iDestDeviceDriverPort);
- routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress,
- strProtocol, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort);
- routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress,
- strProtocol, commHan.getComPort(strDeviceAddress), iDestDeviceDriverPort);
+ routerConfig.configureRouterMainPolicies(STR_ROUTER_ADD, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol, commHan.getComPort(strDeviceAddressKey),
+ iDestDeviceDriverPort);
+ routerConfig.configureHostMainPolicies(strIoTSlaveObjectHostAdd, strIoTSlaveObjectHostAdd, strDeviceAddress, strProtocol, commHan.getComPort(strDeviceAddressKey),
+ iDestDeviceDriverPort);
}
}
}
if(setInstrumenter.getObjTableName().equals(STR_IOT_DEV_ADD_CLS)) {
// Instrument the normal IoTDeviceAddress
synchronized(this) {
- instrumentIoTSetDevice(strFieldIdentifier, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
+ instrumentIoTSetDevice(strFieldIdentifier, strObjName, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
}
} else if(setInstrumenter.getObjTableName().equals(STR_IOT_ZB_ADD_CLS)) {
// Instrument the IoTZigbeeAddress - special feature for Zigbee device support
synchronized(this) {
- instrumentIoTSetZBDevice(map, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
+ instrumentIoTSetZBDevice(map, strObjName, strFieldName, strIoTSlaveObjectHostAdd, inStream, outStream);
}
} else if(setInstrumenter.getObjTableName().equals(STR_IOT_ADD_CLS)) {
// Instrument the IoTAddress
// Construct ssh command line and create a controller thread for e.g. AcmeProximity
String strSSHCommand = STR_SSH_USERNAME + strIoTSlaveControllerHostAdd + " cd " +
- STR_RUNTIME_DIR + " sudo java " + STR_CLS_PATH + " " +
+ STR_RUNTIME_DIR + " sudo java " + STR_JVM_INIT_HEAP_SIZE + " " +
+ STR_JVM_MAX_HEAP_SIZE + " " + STR_CLS_PATH + " " +
STR_RMI_PATH + " " + STR_IOT_SLAVE_CLS + " " + strIoTMasterHostAdd + " " +
commHan.getComPort(strObjControllerName) + " " +
commHan.getRMIRegPort(strObjControllerName) + " " +