// Get and init the IoTCloud server address
// Setup table
t1 = new Table(BASE_URL, PASSWORD, LOCAL_MACHINE_ID, LISTENING_PORT);
- t1.initTable();
- // Setup is done somewhere else, we just do rebuild()
- //t1.rebuild();
+ t1.initTable();
System.out.println("DEBUG: Table initialized!");
// Initialize sensors!
- // TODO: Still deciding whether to initialize all devices here or inside each init method
int id = 0;
// Initialize alarms! One alarm for now
for(AlarmSmart alarm : alarmSet.values()) {
createKeyIoTCloud("alarm", NOT_ACTIVE);
System.out.println("DEBUG: Setting alarm to NOT-ACTIVE!");
}
- // TODO: We can extend the usage of other keys to have a complete monitoring system for every device
- /*for(SmartthingsSensorSmart smartSensor : smartSensorsSet.values()) {
-
- createKeyIoTCloud("sensor" + Integer.toString(id++), NOT_ACTIVE);
- System.out.println("DEBUG: Setting sensor" + id + " to NOT-ACTIVE!");
- }
- // Initialize cameras! One camera for now...
- for(CameraSmart cam : camSet.values()) {
- createKeyIoTCloud("camera", NOT_ACTIVE);
- System.out.println("DEBUG: Setting camera to NOT-ACTIVE!");
- }
- int doorId = 0;
- for(SmartthingsActuatorSmart doorlock : doorlockSet.values()) {
- createKeyIoTCloud("doorlock" + Integer.toString(doorId), NOT_ACTIVE);
- System.out.println("DEBUG: Setting doorlock" + id + " to NOT-ACTIVE!");
- }*/
} catch(Exception e) {
e.printStackTrace();
if(_activeValue) {
System.out.println("DEBUG: Sensor " + sensorId + " is detecting something: " + _activeValue);
senDetectStatus.put(_sensorId, true);
- //updateIoTCloud(sensor, ACTIVE);
} else {
- //System.out.println("DEBUG: Sensor " + sensorId + " is not detecting something: " + _activeValue);
+ System.out.println("DEBUG: Sensor " + sensorId + " is not detecting something: " + _activeValue);
senDetectStatus.put(_sensorId, false);
- //updateIoTCloud(sensor, NOT_ACTIVE);
}
}
if(_activeValue) {
System.out.println("DEBUG: Actuator " + _sensorId + " is detecting something: " + _activeValue);
doorlockStatus.put(_sensorId, true);
- //updateIoTCloud(actuator, ACTIVE);
} else {
//System.out.println("DEBUG: Actuator " + _sensorId + " is not detecting something: " + _activeValue);
doorlockStatus.put(_sensorId, false);
- //updateIoTCloud(actuator, NOT_ACTIVE);
}
}
System.out.println("DEBUG: Camera detected something!");
for(CameraSmart cam : cameras) {
camDetectStatus.put(cam, true);
- //updateIoTCloud("camera", ACTIVE);
}
} else {
// No motion was detected
- //System.out.println("DEBUG: Camera didn't detect anything!");
+ System.out.println("DEBUG: Camera didn't detect anything!");
for(CameraSmart cam : cameras) {
camDetectStatus.put(cam, false);
- //updateIoTCloud("camera", NOT_ACTIVE);
}
}
}
int doorId = doorlock.getId();
System.out.println("DEBUG: Lock doorlock! ID: " + doorId);
doorlockStatus.put(doorId, true);
- //updateIoTCloud("doorlock" + doorId, ACTIVE);
}
}
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);
*/
public void init() {
- // Initialize IoTCloud server
- initIoTCloudServer();
-
// Iterate over the set of rooms
for (RoomSmart rm : roomSet.values()) {
// Init all cameras
initCameras();
+ // Initialize IoTCloud server
+ initIoTCloudServer();
+
System.out.println("DEBUG: Initialized all devices! Now starting detection loop!");
// Run the main loop that will keep checking the sensors and cameras periodically