|
|
Here, I'll walk you through the java source code, responsible for starting the [ESP32 Controller](What-am-I-looking-at-here#esp32-controller). Additional startup procedures are explained in the documentation for the [`start_component.sh`](implementation/start_component.sh) and the [`run_demo.sh`](implementation/run_demo.sh) scripts.
|
|
|
|
|
|
The discussed file can be found [here](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/blob/64e67bdaae14ef6945ab3e73b5a9c70c9c1ced67/basyx.lichterkette/src/main/java/de/olipar/basyx/lichterkette/ProprietaryLightstrand.java).
|
|
|
The discussed file can be found [here](https://gitlab.hrz.tu-chemnitz.de/vws-demo/vws-spielwiese/-/blob/b24685111e7cf05e66120fa0a890efe9e44219a3/basyx.lichterkette/src/main/java/de/olipar/basyx/lichterkette/ProprietaryLightstrand.java).
|
|
|
|
|
|
We'll skip the license headers, imports and comments, as they are either pretty much self explanatory or not the product of conscious development effort.
|
|
|
This class uses the [Eclipse Paho MQTT Client](https://www.eclipse.org/paho/index.php?page=clients/java/index.php).
|
... | ... | @@ -25,13 +25,14 @@ We start of again by establishing, how many Proprietary lights we should connect |
|
|
```java
|
|
|
MqttClient mqttClient = null;
|
|
|
try {
|
|
|
mqttClient = new MqttClient("tcp://esp-controller.local:1883", "ProprietaryLightstrand", new MemoryPersistence());
|
|
|
mqttClient = new MqttClient(Common.getMQTTBrokerHost(), "ProprietaryLightstrand", new MemoryPersistence());
|
|
|
} catch (MqttException e) {
|
|
|
logger.warn("MQTT client could not be created: " + e.getMessage());
|
|
|
logger.warn("No lights will be switched in the real world.");
|
|
|
}
|
|
|
```
|
|
|
Then, we initialize a MQTT Client with `null` and try to connect to the MQTT broker hosted on the ESP32 Controller. If a client can't be created, a warning is issued and lights will only be created as virtual lights on the machine.
|
|
|
Then, we initialize a MQTT Client with `null` and try to connect to the MQTT broker we provide in the `MQTTBROKERHOST` environment variable.
|
|
|
If a client can't be created, a warning is issued and lights will only be created as virtual lights on the machine.
|
|
|
|
|
|
```java
|
|
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
... | ... | |