1
0

add web on main

This commit is contained in:
Rémi Heredero 2023-06-06 13:51:28 +02:00
parent be9c484001
commit fa54c5fbb3
3 changed files with 27 additions and 10 deletions

View File

@ -1,3 +1,5 @@
URL = https://influx.sdi.hevs.ch
ORG = SIn15
BUCKET = SIn15
DB.URL = https://influx.sdi.hevs.ch
DB.ORG = SIn15
DB.BUCKET = SIn15
WEB.URL = localhost
WEB.PORT = 8888

View File

@ -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);
}
}

View File

@ -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);