Skip to content

Commit

Permalink
activate MQTT automatically if using the webserver and added start
Browse files Browse the repository at this point in the history
scripts
  • Loading branch information
ai-republic committed Jan 27, 2024
1 parent dddf4ad commit 9667018
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -224,21 +224,26 @@ private void buildApplication(final String config) {
Files.write(installDirectory.resolve("config.properties"), config.toString().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);

// generate start scripts
final StringBuffer commands = new StringBuffer("java -jar lib/bms-to-inverter-main-0.0.1-SNAPSHOT.jar -DconfigFile=config.properties\n");
final StringBuffer windowsCommands = new StringBuffer("start java -jar lib/bms-to-inverter-main-0.0.1-SNAPSHOT.jar -DconfigFile=config.properties\n");
final StringBuffer linuxCommands = new StringBuffer("#!/bin/bash\njava -jar lib/bms-to-inverter-main-0.0.1-SNAPSHOT.jar -DconfigFile=config.properties &\n");

if (servicesPanel.isWebserverEnabled()) {
commands.append("java -jar lib/webserver-0.0.1-SNAPSHOT.jar --spring.config.location=file://config.properties\n");
windowsCommands.append("start java -jar lib/webserver-0.0.1-SNAPSHOT.jar --spring.config.location=file://config.properties\n");
linuxCommands.append("java -jar lib/webserver-0.0.1-SNAPSHOT.jar --spring.config.location=file://config.properties &\n");
}

final Path windowsStart = Path.of("start.cmd");
final Path windowsStart = installDirectory.resolve("start.cmd");
Files.deleteIfExists(windowsStart);
Files.createFile(windowsStart);
Files.write(windowsStart, commands.toString().getBytes());
Files.write(windowsStart, windowsCommands.toString().getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);

final Path linuxStart = Path.of("start");
if (servicesPanel.isWebserverEnabled()) {
}

final Path linuxStart = installDirectory.resolve("start");
Files.deleteIfExists(windowsStart);
Files.createFile(windowsStart);
Files.write(linuxStart, ("#!/bin/bash\n" + commands.toString()).getBytes());
Files.write(linuxStart, ("" + linuxCommands.toString()).getBytes(), StandardOpenOption.CREATE, StandardOpenOption.WRITE);

} catch (final Exception e) {
System.out.println("Installation FAILED!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

public class MQTTServicePanel extends JPanel {
private static final long serialVersionUID = 1L;
private final JLabel mqttProducerLocatorLabel;
private final JTextField mqttProducerLocatorField;
private final JLabel mqttProducerTopicLabel;
private final JTextField mqttProducerTopicField;
private final JCheckBox activateMQTTBrokerCheckBox;
private final JCheckBox activateMQTTProducerCheckBox;
Expand Down Expand Up @@ -39,7 +41,7 @@ public MQTTServicePanel() {
gbc_activateMQTTProducerCheckBox.gridy = 0;
add(activateMQTTProducerCheckBox, gbc_activateMQTTProducerCheckBox);

final JLabel mqttProducerLocatorLabel = new JLabel("Locator");
mqttProducerLocatorLabel = new JLabel("Locator");
mqttProducerLocatorLabel.setEnabled(false);
final GridBagConstraints gbc_mqttProducerLocatorLabel = new GridBagConstraints();
gbc_mqttProducerLocatorLabel.anchor = GridBagConstraints.EAST;
Expand All @@ -58,7 +60,7 @@ public MQTTServicePanel() {
gbc_mqttProducerLocatorField.gridy = 1;
add(mqttProducerLocatorField, gbc_mqttProducerLocatorField);

final JLabel mqttProducerTopicLabel = new JLabel("Topic");
mqttProducerTopicLabel = new JLabel("Topic");
mqttProducerTopicLabel.setEnabled(false);
final GridBagConstraints gbc_mqttProducerTopicLabel = new GridBagConstraints();
gbc_mqttProducerTopicLabel.anchor = GridBagConstraints.EAST;
Expand Down Expand Up @@ -197,8 +199,18 @@ protected void generateConfiguration(final StringBuffer config) {
}


public void enableMQTTBroker() {
public void enableMQTT() {
activateMQTTBrokerCheckBox.setSelected(true);
mqttBrokerLocatorLabel.setEnabled(activateMQTTBrokerCheckBox.isSelected());
mqttBrokerLocatorField.setEnabled(activateMQTTBrokerCheckBox.isSelected());
mqttBrokerTopicLabel.setEnabled(activateMQTTBrokerCheckBox.isSelected());
mqttBrokerTopicField.setEnabled(activateMQTTBrokerCheckBox.isSelected());

activateMQTTProducerCheckBox.setSelected(true);
mqttProducerLocatorLabel.setEnabled(activateMQTTProducerCheckBox.isSelected());
mqttProducerLocatorField.setEnabled(activateMQTTProducerCheckBox.isSelected());
mqttProducerTopicLabel.setEnabled(activateMQTTProducerCheckBox.isSelected());
mqttProducerTopicField.setEnabled(activateMQTTProducerCheckBox.isSelected());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public ServicesPanel() {

enableComponent(webserverPanel, false);
webserverCheckBox.addActionListener(t -> {
mqttPanel.enableMQTTBroker();
mqttPanel.enableMQTT();
enableComponent(webserverPanel, webserverCheckBox.isSelected());
});

Expand Down

0 comments on commit 9667018

Please sign in to comment.