From a01a0478cb2ab118164b2bdd3c22a23e361f4a78 Mon Sep 17 00:00:00 2001 From: Dulitha Wijewantha Date: Sun, 18 May 2014 13:33:20 +0530 Subject: [PATCH] Added the properties file again - with Hostnames --- rpi-agent/config.properties | 3 ++- .../org/wso2/iot/refarch/rpi/agent/Agent.java | 10 ++++++++-- .../wso2/iot/refarch/rpi/agent/Publisher.java | 17 ++++++++++++++++- .../wso2/iot/refarch/rpi/agent/Receiver.java | 17 +++++++++++++++++ .../refarch/rpi/agent/RpiAgentConstants.java | 2 +- 5 files changed, 44 insertions(+), 5 deletions(-) diff --git a/rpi-agent/config.properties b/rpi-agent/config.properties index aae868d..c75b56e 100644 --- a/rpi-agent/config.properties +++ b/rpi-agent/config.properties @@ -1 +1,2 @@ -serverpath=http://mdm.host:9763/mdm/api/notifications/iot \ No newline at end of file +emmpath=http://mdm.host:9763/mdm/api/notifications/iot +mqttpath=mqtt.host \ No newline at end of file diff --git a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Agent.java b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Agent.java index 8e7b3b5..443846d 100644 --- a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Agent.java +++ b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Agent.java @@ -33,6 +33,9 @@ import org.json.simple.JSONObject; import org.wso2.iot.refarch.rpi.agent.connector.HttpService; +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -48,8 +51,11 @@ public class Agent { Init block that creates the http service from a config file */ try{ - System.out.println("Server ip "+RpiAgentConstants.EMM_AGENT_HOSTNAME + ":9763/mdm/api/notifications/iot"); - httpService = new HttpService( RpiAgentConstants.EMM_AGENT_HOSTNAME + ":9763/mdm/api/notifications/iot"); + InputStream is = new FileInputStream("config.properties"); + Properties properties = new Properties(); + properties.load(is); + System.out.println("Server ip "+properties.getProperty("emmpath")); + httpService = new HttpService( properties.getProperty("emmpath")); }catch(Exception e){ e.printStackTrace(); } diff --git a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java index 5f818ec..95b0f29 100644 --- a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java +++ b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Publisher.java @@ -21,7 +21,11 @@ import org.eclipse.paho.client.mqttv3.MqttException; import org.json.simple.JSONObject; +import java.io.FileInputStream; +import java.io.FileNotFoundException; import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import java.util.concurrent.ExecutionException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -37,9 +41,20 @@ public class Publisher { private MQTTClient mqttClient; private MQTTBrokerConnectionConfig mqttBrokerConnectionConfig; private Agent agent; - public Publisher(int dataPinNumber) { dhtSensor = new DHTSensor(DHTSensorType.DHT11, dataPinNumber); + InputStream is = null; + try { + is = new FileInputStream("config.properties"); + Properties properties = new Properties(); + properties.load(is); + System.out.println("Server ip "+properties.getProperty("mqttpath")); + RpiAgentConstants.MQTT_AGENT_HOSTNAME = properties.getProperty("mqttpath"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } mqttBrokerConnectionConfig = new MQTTBrokerConnectionConfig(RpiAgentConstants.MQTT_AGENT_HOSTNAME,"1883"); String clientId = "R-Pi-Publisher"; String topicName = "wso2iot"; diff --git a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java index 061c2c0..51f8c22 100644 --- a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java +++ b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/Receiver.java @@ -24,6 +24,11 @@ import com.pi4j.io.gpio.RaspiPin; import org.json.simple.JSONObject; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -40,6 +45,18 @@ public class Receiver{ } //17 public Receiver() { + InputStream is = null; + try { + is = new FileInputStream("config.properties"); + Properties properties = new Properties(); + properties.load(is); + System.out.println("Server ip "+properties.getProperty("mqttpath")); + RpiAgentConstants.MQTT_AGENT_HOSTNAME = properties.getProperty("mqttpath"); + } catch (FileNotFoundException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } mqttBrokerConnectionConfig = new MQTTBrokerConnectionConfig(RpiAgentConstants.MQTT_AGENT_HOSTNAME,"1883"); String clientId = "R-Pi-Receiver"; String topicName = "iot/demo"; diff --git a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/RpiAgentConstants.java b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/RpiAgentConstants.java index 7bdc359..06878ac 100644 --- a/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/RpiAgentConstants.java +++ b/rpi-agent/core/src/main/java/org/wso2/iot/refarch/rpi/agent/RpiAgentConstants.java @@ -23,6 +23,6 @@ */ public final class RpiAgentConstants { - public static final String MQTT_AGENT_HOSTNAME = "mqqt.host"; + public static String MQTT_AGENT_HOSTNAME = "mqqt.host"; public static final String EMM_AGENT_HOSTNAME = "emm.host"; }