add token parameter
This commit is contained in:
parent
8652123986
commit
905ee4ca78
@ -23,14 +23,15 @@ public class MinecraftController {
|
|||||||
System.out.println();
|
System.out.println();
|
||||||
System.out.println("In development mode, just add to your running configuration the needed parameters (see usage below).");
|
System.out.println("In development mode, just add to your running configuration the needed parameters (see usage below).");
|
||||||
System.out.println("In running mode, the application's usage is the following:");
|
System.out.println("In running mode, the application's usage is the following:");
|
||||||
System.out.println("java MinecraftController <InfluxDB Server> <DB Name> <DB Measurement> <DB Username> <ModbusTCP Server> <ModbusTCP port> [-modbus4j] [-keepAlive]");
|
System.out.println("java MinecraftController <db_url> <db_org> <db_bucket> <db_token> <modbus_host> <modbus_port> [-erasedb]");
|
||||||
System.out.println("where:");
|
System.out.println("where:");
|
||||||
System.out.println("- <InfluxDB Server>: The complete URL of the InfluxDB server, including the protocol (http or https)...");
|
System.out.println("- <db_url>: The complete URL of the InfluxDB server, including the protocol (http or https)...");
|
||||||
System.out.println(" Example: https://influx.sdi.hevs.ch");
|
System.out.println(" Example: https://influx.sdi.hevs.ch");
|
||||||
System.out.println("- <DB Name>: The name of the Influx DB to use. For this project, this name is the name of the group you've been affected to. (SInXX)");
|
System.out.println("- <db_org>: The name of the Influx DB to use. For this project, this name is the name of the group you've been affected to. (SInXX)");
|
||||||
System.out.println("- <DB Username: The user's name to use to access the DB. It's also your group's name. (SInXX)");
|
System.out.println("- <db_bucket>: The user's name to use to access the DB. It's also your group's name. (SInXX)");
|
||||||
System.out.println("- <ModbusTCP Server>: The IP address of the Minecraft ModbusTCP server (default value: localhost)");
|
System.out.println("- <db_token>: The Token to use to access the DB.");
|
||||||
System.out.println("- <ModbusTCP port>: The port number of the Minecraft ModbusTCP server (default value: 1502)");
|
System.out.println("- <modbus_host>: The IP address of the Minecraft ModbusTCP server (default value: localhost)");
|
||||||
|
System.out.println("- <modbus_port>: The port number of the Minecraft ModbusTCP server (default value: 1502)");
|
||||||
System.out.println("- [-eraseDB]: Optional parameter! If set, the application will erase the previous data in InfluxDB...");
|
System.out.println("- [-eraseDB]: Optional parameter! If set, the application will erase the previous data in InfluxDB...");
|
||||||
System.out.println();
|
System.out.println();
|
||||||
System.exit(1);
|
System.exit(1);
|
||||||
@ -45,6 +46,7 @@ public class MinecraftController {
|
|||||||
String dbName = "labo";
|
String dbName = "labo";
|
||||||
String dbUserName = "root";
|
String dbUserName = "root";
|
||||||
String dbPassword = "root";
|
String dbPassword = "root";
|
||||||
|
String dbToken = "super-token";
|
||||||
|
|
||||||
String modbusTcpHost = "localhost";
|
String modbusTcpHost = "localhost";
|
||||||
int modbusTcpPort = 1502;
|
int modbusTcpPort = 1502;
|
||||||
@ -53,7 +55,7 @@ public class MinecraftController {
|
|||||||
String[] parameters = null;
|
String[] parameters = null;
|
||||||
|
|
||||||
// If there is only one number given as parameter, construct the parameters according the group number.
|
// If there is only one number given as parameter, construct the parameters according the group number.
|
||||||
if (args.length >= 5) {
|
if (args.length >= 6) {
|
||||||
parameters = args;
|
parameters = args;
|
||||||
|
|
||||||
// Decode parameters for influxDB
|
// Decode parameters for influxDB
|
||||||
@ -67,10 +69,11 @@ public class MinecraftController {
|
|||||||
dbName = parameters[1];
|
dbName = parameters[1];
|
||||||
dbUserName = parameters[2];
|
dbUserName = parameters[2];
|
||||||
dbPassword = Utility.md5sum(dbUserName);
|
dbPassword = Utility.md5sum(dbUserName);
|
||||||
|
dbToken = parameters[3];
|
||||||
|
|
||||||
// Decode parameters for Modbus TCP
|
// Decode parameters for Modbus TCP
|
||||||
modbusTcpHost = parameters[3];
|
modbusTcpHost = parameters[4];
|
||||||
modbusTcpPort = Integer.parseInt(parameters[4]);
|
modbusTcpPort = Integer.parseInt(parameters[5]);
|
||||||
|
|
||||||
for (int i = 5; i < args.length; i++) {
|
for (int i = 5; i < args.length; i++) {
|
||||||
if (parameters[i].compareToIgnoreCase("-erasedb") == 0) {
|
if (parameters[i].compareToIgnoreCase("-erasedb") == 0) {
|
||||||
@ -84,11 +87,13 @@ public class MinecraftController {
|
|||||||
// ------------------------------------ /DO NOT CHANGE THE FOLLOWING LINES -------------------------------------
|
// ------------------------------------ /DO NOT CHANGE THE FOLLOWING LINES -------------------------------------
|
||||||
|
|
||||||
// Read the config.properties file
|
// Read the config.properties file
|
||||||
try (InputStream input = new FileInputStream("src/config.properties")) {
|
/*
|
||||||
|
try (InputStream input = new FileInputStream("config.properties")) {
|
||||||
properties.load(input);
|
properties.load(input);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
// Initialize the database connector
|
// Initialize the database connector
|
||||||
if(dbName != null){
|
if(dbName != null){
|
||||||
@ -97,21 +102,25 @@ public class MinecraftController {
|
|||||||
if(dbUserName != null){
|
if(dbUserName != null){
|
||||||
DatabaseConnector.bucket = dbUserName;
|
DatabaseConnector.bucket = dbUserName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DatabaseConnector.token = dbToken;
|
||||||
if((dbProtocol != null) && (dbHostName != null)){
|
if((dbProtocol != null) && (dbHostName != null)){
|
||||||
DatabaseConnector.url = dbProtocol+ "://" + dbHostName;
|
DatabaseConnector.url = dbProtocol+ "://" + dbHostName;
|
||||||
Utility.pDebug("Database URL: " + DatabaseConnector.url);
|
|
||||||
Utility.pDebug("Config: " + properties.getProperty("DB.URL"));
|
|
||||||
DatabaseConnector.getMySelf().initialize(DatabaseConnector.url);
|
DatabaseConnector.getMySelf().initialize(DatabaseConnector.url);
|
||||||
System.out.println("Database is running on " + DatabaseConnector.url);
|
System.out.println("Database is running on " + DatabaseConnector.url);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize the Modbus TCP connector
|
// Initialize the Modbus TCP connector
|
||||||
FieldConnector.getMySelf().initialize(modbusTcpHost, modbusTcpPort,"src/main/resources/ModbusMap.csv");
|
FieldConnector.getMySelf().initialize(modbusTcpHost, modbusTcpPort,"ModbusMap.csv");
|
||||||
System.out.println("Field is running on " + modbusTcpHost + ":" + modbusTcpPort);
|
System.out.println("Field is running on " + modbusTcpHost + ":" + modbusTcpPort);
|
||||||
|
|
||||||
// Initialize the web server
|
// Initialize the web server
|
||||||
|
/*
|
||||||
String host = properties.getProperty("WEB.URL");
|
String host = properties.getProperty("WEB.URL");
|
||||||
int port = Integer.parseInt(properties.getProperty("WEB.PORT"));
|
int port = Integer.parseInt(properties.getProperty("WEB.PORT"));
|
||||||
|
*/
|
||||||
|
String host = "localhost";
|
||||||
|
int port = 8888;
|
||||||
WebConnector.getMySelf().initialize(host, port);
|
WebConnector.getMySelf().initialize(host, port);
|
||||||
System.out.println("Web server is running on " + host + ":" + port);
|
System.out.println("Web server is running on " + host + ":" + port);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user