... | ... | @@ -2,6 +2,10 @@ |
|
|
|
|
|
A display and a script to show the data of the different sensors were already added as part of the first follow up. You can find the documentation here. Displaying the values was realized with a python script and a system service and no Basyx implementation existed for the LCD. Therefore, it was not possible to show a custom text. The display now is fully integrated into the Basyx environment and has its own AAS with invokable operations to do so.
|
|
|
|
|
|
## Setup
|
|
|
|
|
|
Use `docker-compose.lcd-monitor.yml` to build and run a Docker container. The docker compose file reuses `Rfid.Dockerfile`. The component could be run without Docker too.
|
|
|
|
|
|
## Implementation Basyx
|
|
|
|
|
|
The concept of the implementation is compareable to the one for the light or sensor implementation. An interface ```IDisplay``` as well as the class ```Display``` implementig it are used. The `LcdDisplayController` creates the displays and uses the `DisplaySubmodelProvider` to create, register and upload the AAS as well as host and register the submodules.
|
... | ... | @@ -75,16 +79,15 @@ This method enables to publish MQTT messages. A MQTT client is initialized and t |
|
|
|
|
|
### LcdDisplayController
|
|
|
|
|
|
The file can be found here.
|
|
|
The file can be found here.
|
|
|
|
|
|
```java
|
|
|
public static void main(String[] args) {
|
|
|
final int HOSTPORT = Common.getHostPort();
|
|
|
displayAmount = getAmount();
|
|
|
boolean inDocker = Common.inDocker();
|
|
|
|
|
|
for (int i = 0; i < displayAmount; i++) {
|
|
|
LcdDisplay display = new LcdDisplay(Integer.toString(i), inDocker);
|
|
|
LcdDisplay display = new LcdDisplay(Integer.toString(i));
|
|
|
DisplaySubmodelProvider dsp = new DisplaySubmodelProvider("Display:Lcd_" + display.getID());
|
|
|
dsp.hostUploadAndRegister(display, "Lcd_"+display.getID(), "Lcd_"+display.getID(), HOSTPORT+i);
|
|
|
display.cycleSensorValues();
|
... | ... | @@ -92,11 +95,11 @@ public static void main(String[] args) { |
|
|
}
|
|
|
```
|
|
|
|
|
|
The amount of displays which need to be created is retrieved from the environment variable.
|
|
|
The amount of displays which need to be created is retrieved from the environment variable. The amount determines the number of displays that are initialized. For each created display, an AAS and a submodel are created, registered and uploaded using the `DisplaySubmodelProvider`. The function for cycling through the sensor values is called to instantly show the data.
|
|
|
|
|
|
### DisplaySubmodelProvider
|
|
|
|
|
|
Like in the other submodel provider in the project a method for creating a submodel is defined and the operations are added.
|
|
|
The file can be found here. Like in the other submodel provider in the project a method for creating a submodel is defined and the operations are added.
|
|
|
|
|
|
```java
|
|
|
Function<Object[], Object> cycleFunction = (args) -> display.cycleSensorValues();
|
... | ... | @@ -120,7 +123,7 @@ displayTextOperation.setInputVariables(Arrays.asList(var)); |
|
|
displaySubmodel.addSubmodelElement(displayTextOperation);
|
|
|
```
|
|
|
|
|
|
Because an input variable is necessary to pass the text which will be displayed, a propterty is initialized and its modeling kind and value type are set. The defined function passes the first argument to `displayText()`. Using the function and the property the second operation is added to the submodel.
|
|
|
Because an input variable is necessary to pass the text which will be displayed, a propterty is initialized and its modeling kind and value type are set. A default value seems to be necessary if one wants to invoke the operation within Java. The defined function passes the first argument to `displayText()`. Using the function and the property the second operation is added to the submodel.
|
|
|
|
|
|
The created submodel is returned and used to host, upload and register it in the following step.
|
|
|
|
... | ... | @@ -141,15 +144,20 @@ In this script, a paho MQTT client is implemented. Depending on the received mes |
|
|
|
|
|
```python
|
|
|
brokerAddress = environ.get('MQTTBROKERHOST')
|
|
|
displayId = environ.get('DISPLAYID')
|
|
|
|
|
|
topicCycle = "display/Lcd_"+displayId+"/cycle"
|
|
|
topicText = "display/Lcd_"+displayId+"/text"
|
|
|
|
|
|
proc = None
|
|
|
```
|
|
|
|
|
|
The broker address is retrieved from the environment variable and an empty variable for the currently running process is defined.
|
|
|
The broker address and the ID are retrieved from the environment variables. The ID is used to set the coressponding topics. Afterwards, an empty variable for the currently running process is defined.
|
|
|
|
|
|
```python
|
|
|
def on_connect(client, userdata, flags, rc):
|
|
|
client.subscribe("display/Lcd_0/cycle")
|
|
|
client.subscribe("display/Lcd_0/text")
|
|
|
client.subscribe(topicCycle)
|
|
|
client.subscribe(topicText)
|
|
|
```
|
|
|
|
|
|
The function is used to subscribe to the necessary topics.
|
... | ... | @@ -172,14 +180,14 @@ def on_message(client, userdata, message): |
|
|
except Exception as e:
|
|
|
print(e)
|
|
|
|
|
|
if(message.topic == "display/Lcd_0/cycle"):
|
|
|
if(message.topic == topicCycle):
|
|
|
try:
|
|
|
proc = subprocess.Popen([sys.executable, 'cycle_lcd.py'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
except Exception as e:
|
|
|
print("Error. Could not start cycle: ")
|
|
|
print(e)
|
|
|
|
|
|
if(message.topic == "display/Lcd_0/text"):
|
|
|
if(message.topic == topicText):
|
|
|
try:
|
|
|
text = payload
|
|
|
proc = subprocess.Popen([sys.executable, 'display_text_lcd.py', text], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
... | ... | @@ -202,7 +210,7 @@ A MQTT client is initialized and the previous functions are assigned as on_conne |
|
|
|
|
|
### display_text_lcd.py
|
|
|
|
|
|
After setting all the pins and the settings for the LCD, text an be displayed.
|
|
|
The script can be found here. After setting all the pins and the settings for the LCD, text an be displayed.
|
|
|
|
|
|
```python
|
|
|
lines = sys.argv[1].split(',')
|
... | ... | @@ -249,3 +257,4 @@ The json body should look like this: |
|
|
```
|
|
|
|
|
|
The second value parameter should contain the text to display. To show multiple lines of text, separate the parts by commas.
|
|
|
|