Commit 10fe54d0 authored by Nicolas Metts's avatar Nicolas Metts

Checking in changes to allow using IoTManager in demo mode.

parent c7b41300
xmppServer=nmettsmbpr15
xmppUser=iot_manager
xmppPass=cablelabs
xmppResource=urn:schemas-upnp-org:cloud-1-0:ControlPoint:1:5de3c794-8d3e-4acd-b176-17ea58a1e6fd
hueIp=192.168.1.111
manager_ip=127.0.0.1
oic_ip=10.4.2.38
oic_ip_peer=10.4.2.38
oic_peer_port=8080
oic_local_port=8081
allseen_ip=127.0.0.1
allseen_ip_peer=127.0.0.1
allseen_local_port=8080
allseen_peer_port=8080
oic_data_format=JSON
camera_bridge_ip=127.0.0.1
camera_bridge_port=26000
reset_interval=30
emulate_iot_networks=true
xg1_available=false
scenario_interval=5
\ No newline at end of file
......@@ -2,17 +2,14 @@
"Devices" : {
"Device" : [ {
"onOff" : false,
"name" : "LivingRoomTV",
"manufacturer" : "Sony",
"hwVersion" : "Bravia Z4X55",
"stackVersion" : "LOS 3.4.2",
"name" : "Door Sensor",
"manufacturerDate" : "2006-05-02-06:00",
"lastConfiguredBy" : "18.19.44.202",
"objectId" : 451431,
"objectId" : 2,
"manufacturerId" : 1492,
"networkAddress" : "FE00::00ac:2234:5678",
"enabled" : true,
"type" : "OnOffSwitch",
"type" : "OpenClosedContactSensor",
"Translators" : {
"Translator" : [ {
"type" : "OIC"
......@@ -20,16 +17,16 @@
}
}, {
"onOff" : true,
"name" : "BedroomLamp",
"name" : "Living Room Presence",
"manufacturer" : "GE",
"hwVersion" : "GE 697",
"stackVersion" : "104",
"manufacturerDate" : "2010-04-07-06:00",
"objectId" : 7302,
"objectId" : 3,
"manufacturerId" : 9176,
"networkAddress" : "192.168.0.5",
"enabled" : true,
"type" : "Light",
"type" : "Presence",
"Translators" : {
"Translator" : [ {
"type" : "AllSeen"
......@@ -39,19 +36,17 @@
}
}, {
"onOff" : true,
"name" : "FamilyRoomLight",
"manufacturer" : "Philips",
"hwVersion" : "Hue 697",
"name" : "Door Bell",
"stackVersion" : "1.0",
"manufacturerDate" : "1918-11-11-07:00",
"objectId" : 4440,
"objectId" : 4,
"manufacturerId" : 701,
"networkAddress" : "192.168.2.25",
"enabled" : true,
"brightness" : 67,
"hue" : 346,
"saturation" : 87,
"type" : "ColorLight",
"type" : "DoorBell",
"Energy" : {
"wattage" : 100,
"voltage" : 115,
......@@ -65,17 +60,17 @@
}
}, {
"onOff" : false,
"name" : "FamilyRoomMovieLight",
"name" : "DoorBell",
"manufacturer" : "Sylvania",
"hwVersion" : "90",
"stackVersion" : "00013",
"manufacturerDate" : "2003-06-04-06:00",
"objectId" : 2229,
"objectId" : 5,
"manufacturerId" : 6520,
"networkAddress" : "192.168.2.19",
"enabled" : true,
"brightness" : 0,
"type" : "DimmerLight",
"type" : "PulseOxygenMeter",
"Location" : {
"description" : "FamilyRoom Overhead Light",
"floor" : 1
......@@ -85,25 +80,6 @@
"type" : "OneM2M"
} ]
}
}, {
"onOff" : true,
"name" : "Whirlpool Dryer",
"manufacturer" : "Whirlpool",
"hwVersion" : "Duet Steam 2",
"objectId" : 471257975,
"manufacturerId" : 789453,
"networkAddress" : "192.168.5.29",
"dryMode" : "Heat",
"completionAlarm" : true,
"type" : "Dryer",
"Translators" : {
"Translator" : [ {
"type" : "OIC"
} ]
},
"doorState" : {
"openClosed" : "Closed"
}
}
]
}
......
......@@ -234,21 +234,7 @@ public class IoTManager extends Thread implements IoTListener, MessageListener {
LOG.info("Reset interval is set to " + reset_interval);
emulate_iot_networks = appConfig.getBoolean(EMULATE_IOT_NETWORKS);
xg1_available = appConfig.getBoolean(XG1_AVAILABLE);
String xmppServer = appConfig.getString(IoTConstants.XMPP_SERVER);
ConnectionConfiguration config = new ConnectionConfiguration(
xmppServer);
config.setSecurityMode(SecurityMode.disabled);
//config.setDebuggerEnabled(true);
xmppConnection = new XMPPTCPConnection(config);
xmppConnection.connect();
String username = appConfig.getString(IoTConstants.XMPP_USER);
String pass = appConfig.getString(IoTConstants.XMPP_PASS);
String resource = appConfig.getString(IoTConstants.XMPP_RESOURCE);
ChatManager.getInstanceFor(xmppConnection).addChatListener(
new ChatManagerListenerImpl(this));
xmppConnection.login(username, pass, resource);
String oicLocalIp = appConfig.getString(OIC_IP);
String oicPeerlIp = appConfig.getString(OIC_IP_PEER);
String allseenLocalIp = appConfig.getString(ALLSEEN_IP);
......@@ -271,28 +257,56 @@ public class IoTManager extends Thread implements IoTListener, MessageListener {
if (demoMode) {
initDevices();
initRulesMap(CONFIG_PATH + "rules.json");
setName("IoTManager");
setDaemon(true);
start();
}
setName("IoTManager");
setDaemon(true);
start();
allSeenAPI.initialize(cameraAPI);
oicAPI.initialize();
if (!phUtils.hueBridgeFound()) {
if (appConfig.containsKey(IoTConstants.HUE_IP_KEY)) {
String hueIp = appConfig.getString(IoTConstants.HUE_IP_KEY);
LOG.info("Hue bridge search failed. Using IP Address: "
+ hueIp);
phUtils.setIpAddress(hueIp);
else {
if (appConfig.containsKey(IoTConstants.XMPP_SERVER) &&
appConfig.containsKey(IoTConstants.XMPP_USER) &&
appConfig.containsKey(IoTConstants.XMPP_PASS)) {
String xmppServer = appConfig.getString(IoTConstants.XMPP_SERVER);
ConnectionConfiguration config = new ConnectionConfiguration(
xmppServer);
config.setSecurityMode(SecurityMode.disabled);
//config.setDebuggerEnabled(true);
xmppConnection = new XMPPTCPConnection(config);
xmppConnection.connect();
String username = appConfig.getString(IoTConstants.XMPP_USER);
String pass = appConfig.getString(IoTConstants.XMPP_PASS);
String resource = appConfig.getString(IoTConstants.XMPP_RESOURCE);
ChatManager.getInstanceFor(xmppConnection).addChatListener(
new ChatManagerListenerImpl(this));
xmppConnection.login(username, pass, resource);
}
}
if (phUtils.hueBridgeFound()) {
List<ColorLight> hueLights = phUtils.getHueLights();
for (ColorLight hueLight : hueLights) {
receive(hueLight);
else {
LOG.warn("No XMPP Configuration info. No XMPP connection will be made!");
}
setName("IoTManager");
setDaemon(true);
start();
allSeenAPI.initialize(cameraAPI);
oicAPI.initialize();
if (!phUtils.hueBridgeFound()) {
if (appConfig.containsKey(IoTConstants.HUE_IP_KEY)) {
String hueIp = appConfig.getString(IoTConstants.HUE_IP_KEY);
LOG.info("Hue bridge search failed. Using IP Address: "
+ hueIp);
phUtils.setIpAddress(hueIp);
}
}
if (phUtils.hueBridgeFound()) {
List<ColorLight> hueLights = phUtils.getHueLights();
for (ColorLight hueLight : hueLights) {
receive(hueLight);
}
}
}
}
......@@ -819,8 +833,9 @@ public class IoTManager extends Thread implements IoTListener, MessageListener {
"org.eclipse.persistence.jaxb.JAXBContextFactory");
final JSONObject devicesConfig = IoTUtils.readJsonFile(new File(
CONFIG_PATH + "devices.json"));
final JSONArray devicesArray = devicesConfig
.getJSONArray(IoTConstants.DEVICES_KEY);
final JSONObject devices = devicesConfig.getJSONObject(IoTConstants.DEVICES_KEY);
final JSONArray devicesArray = devices
.getJSONArray(IoTConstants.DEVICE_KEY);
try {
JAXBContext context = JAXBContext
.newInstance(IoTConstants.IOT_CLASSES);
......@@ -984,7 +999,7 @@ public class IoTManager extends Thread implements IoTListener, MessageListener {
// manager.oicAPI.test();
// manager.cameraAPI.test();
if (!xg1_available) {
HTTPTestServer testServer = new HTTPTestServer(1234,
HTTPTestServer testServer = new HTTPTestServer(43124,
"/test");
new Thread(testServer).start();
}
......@@ -995,7 +1010,7 @@ public class IoTManager extends Thread implements IoTListener, MessageListener {
OICTestClient client = null;
while (manager.isRunning) {
if (client == null) {
client = new OICTestClient(IoTManager.oicAPI);
client = new OICTestClient(manager.getOICAPI());
client.initialize();
}
LOG.info("Sending door open to trigger Scenario 1");
......
......@@ -5,10 +5,16 @@ import java.io.IOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.SocketException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.cablelabs.iot.common.IoTManager;
public class OICTestClient extends Thread {
private static final Logger LOG = LogManager.getLogger(OICTestClient.class);
private boolean isRunning = false;
protected byte[] myIP = null;
......@@ -44,9 +50,13 @@ public class OICTestClient extends Thread {
setDaemon(true);
start();
}
catch (Exception e) {
catch (SocketException e) {
LOG.error("SocketException in initialize()", e);
}
catch (IOException e) {
LOG.error("Exception in initialize()", e);
}
}
public void sendMessage(byte[] data) throws IOException {
......@@ -236,7 +246,7 @@ public class OICTestClient extends Thread {
}
catch (Exception ex) {
// UnknownHostException
handleException(ex);
LOG.error("Exception in sendNewDevice()", ex);
}
}
......@@ -250,7 +260,7 @@ public class OICTestClient extends Thread {
}
catch (Exception ex) {
// UnknownHostException
handleException(ex);
LOG.error("Exception in sendPulseOxygen()", ex);
}
}
......@@ -292,17 +302,17 @@ public class OICTestClient extends Thread {
}
}
catch (IOException ex) {
ex.printStackTrace();
LOG.error(ex);
return;
}
catch (Exception ex) {
ex.printStackTrace();
LOG.error(ex);
}
}
}
catch (Exception ex) {
ex.printStackTrace();
LOG.error(ex);
}
finally {
isRunning = false;
......@@ -311,7 +321,7 @@ public class OICTestClient extends Thread {
sock.close();
}
catch (IOException ex) {
// TODO
LOG.error("IOException", ex);
}
}
}
......@@ -337,7 +347,7 @@ public class OICTestClient extends Thread {
}
catch (Exception e) {
LOG.error("Exception in main()", e);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment