From fa54c5fbb372b480d52781b49a1292a46bcdfed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Heredero?= Date: Tue, 6 Jun 2023 13:51:28 +0200 Subject: [PATCH] add web on main --- src/config.properties | 8 ++++--- .../java/ch/hevs/isi/MinecraftController.java | 21 ++++++++++++++++--- .../ch/hevs/isi/db/DatabaseConnector.java | 8 +++---- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/src/config.properties b/src/config.properties index bba40f7..8f4c695 100644 --- a/src/config.properties +++ b/src/config.properties @@ -1,3 +1,5 @@ -URL = https://influx.sdi.hevs.ch -ORG = SIn15 -BUCKET = SIn15 \ No newline at end of file +DB.URL = https://influx.sdi.hevs.ch +DB.ORG = SIn15 +DB.BUCKET = SIn15 +WEB.URL = localhost +WEB.PORT = 8888 \ No newline at end of file diff --git a/src/main/java/ch/hevs/isi/MinecraftController.java b/src/main/java/ch/hevs/isi/MinecraftController.java index 6bc5059..2567af5 100644 --- a/src/main/java/ch/hevs/isi/MinecraftController.java +++ b/src/main/java/ch/hevs/isi/MinecraftController.java @@ -1,13 +1,17 @@ package ch.hevs.isi; -import ch.hevs.isi.core.BooleanDataPoint; -import ch.hevs.isi.core.FloatDataPoint; import ch.hevs.isi.db.DatabaseConnector; import ch.hevs.isi.utils.Utility; +import ch.hevs.isi.web.WebConnector; + +import java.io.FileInputStream; +import java.io.InputStream; +import java.util.Properties; public class MinecraftController { public static boolean ERASE_PREVIOUS_DATA_INB_DB = false; + private static final Properties properties = new Properties(); // Properties of the config.properties file public static void usage() { System.out.println(); @@ -75,7 +79,12 @@ public class MinecraftController { // ------------------------------------ /DO NOT CHANGE THE FOLLOWING LINES ------------------------------------- - // Start coding here ... + // Read the config.properties file + try (InputStream input = new FileInputStream("src/config.properties")) { + properties.load(input); + } catch (Exception e) { + e.printStackTrace(); + } // Initialize the database connector if((dbProtocol != null) && (dbHostName != null)){ @@ -92,5 +101,11 @@ public class MinecraftController { // Initialize the Modbus TCP connector + // Initialize the web server + String host = properties.getProperty("WEB.URL"); + int port = Integer.parseInt(properties.getProperty("WEB.PORT")); + WebConnector.getMySelf().initialize(host, port); + + } } diff --git a/src/main/java/ch/hevs/isi/db/DatabaseConnector.java b/src/main/java/ch/hevs/isi/db/DatabaseConnector.java index 163d6d2..d87b584 100644 --- a/src/main/java/ch/hevs/isi/db/DatabaseConnector.java +++ b/src/main/java/ch/hevs/isi/db/DatabaseConnector.java @@ -48,13 +48,13 @@ public class DatabaseConnector implements DataPointListener { // Get the URL, the organization and the bucket from the config.properties file if their are null if (url == null){ - url = properties.getProperty("URL"); + url = properties.getProperty("DB.URL"); } if (org == null){ - org = properties.getProperty("ORG"); + org = properties.getProperty("DB.ORG"); } if (bucket == null){ - bucket = properties.getProperty("BUCKET"); + bucket = properties.getProperty("DB.BUCKET"); } // Subscribe to the update of DataPoints @@ -80,7 +80,7 @@ public class DatabaseConnector implements DataPointListener { try{ if(urlForWrite == null){ if(url == null){ - url = properties.getProperty("URL"); + url = properties.getProperty("DB.URL"); } fullURL = url + "/api/v2/write?org=" + org + "&bucket=" + bucket; Utility.pDebug("URL: " + fullURL);