Skip to content

Commit

Permalink
Added the properties file again - with Hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
dulichan committed May 18, 2014
1 parent 441b564 commit a01a047
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 5 deletions.
3 changes: 2 additions & 1 deletion rpi-agent/config.properties
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
serverpath=http://mdm.host:9763/mdm/api/notifications/iot
emmpath=http://mdm.host:9763/mdm/api/notifications/iot
mqttpath=mqtt.host
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}

0 comments on commit a01a047

Please sign in to comment.