diff --git a/README.md b/README.md index 0ec17c6..b659de8 100644 --- a/README.md +++ b/README.md @@ -8,23 +8,24 @@ This code will run on a Raspberry PI in a chicken barn. There are scales under t ### Epic v1: Chicken scale recognizes weight change and sends message about state (which chicken, an egg) via Whatsapp -* Story: (done) create Webservice GET base -* Story: (done) using Github Actions to automatic build and create an image -* Story: (done) install current Docker image on Raspberry PI and start it initially -* Story: (done) create structure with timer service pulling dummy scale service and show data via GET service -* Story: (done) give calibrate webservice operation for load cell -* Story: (done) create scale service that delivers current weight - -* Story: change discovery webserivce to use DO instead of strings * Story: write tests and mock for scale service * Story: respect box/UID of load cell +* Story: Integration test with whole process * Story: get current weight and calculate the "state" (chicken, egg) -* Story: Integration test with whole process * Story: integrate Whatsapp and send messages -* Story: integrate Prometheus -* Story: manage chickens * Story: read data from scale and show by webservice (GET) +* Story: (done) change discovery webservice to use DO instead of strings +* Story: (done) create scale service that delivers current weight +* Story: (done) give calibrate webservice operation for load cell +* Story: (done) create structure with timer service pulling dummy scale service and show data via GET service +* Story: (done) install current Docker image on Raspberry PI and start it initially +* Story: (done) using Github Actions to automatic build and create an image +* Story: (done) create Webservice GET base + +### Epic v2: Recognize chicken +* Story: manage chickens +* Story: integrate Prometheus diff --git a/raspi/docker-chicken-farm.service b/raspi/docker-chicken-farm.service index b55b21e..6ac9a09 100644 --- a/raspi/docker-chicken-farm.service +++ b/raspi/docker-chicken-farm.service @@ -14,7 +14,7 @@ ExecStart=/usr/bin/docker run -d --restart unless-stopped \ -p 8080:8080 --network="host" \ --name chicken-farm stephanst/chicken-farm:latest ExecStop=/usr/bin/docker stop chicken-farm -TimeoutSec=120 +TimeoutSec=300 [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/src/main/java/ch/stephan/chickenfarm/dto/Discovery.java b/src/main/java/ch/stephan/chickenfarm/dto/Discovery.java index 50dd97d..4e3bbb0 100644 --- a/src/main/java/ch/stephan/chickenfarm/dto/Discovery.java +++ b/src/main/java/ch/stephan/chickenfarm/dto/Discovery.java @@ -1,5 +1,5 @@ package ch.stephan.chickenfarm.dto; -public record Discovery(String uid, String connectedUid, int position, String hardwareVersion, String firmwareVersion, - int deviceIdentifier, int enumerationType) { +public record Discovery(String uid, String parentUid, String position, String hardwareVersion, String firmwareVersion, + String deviceIdentifier, String enumerationType) { } diff --git a/src/main/java/ch/stephan/chickenfarm/scale/ScaleService.java b/src/main/java/ch/stephan/chickenfarm/scale/ScaleService.java index 3907ec1..5fce72a 100644 --- a/src/main/java/ch/stephan/chickenfarm/scale/ScaleService.java +++ b/src/main/java/ch/stephan/chickenfarm/scale/ScaleService.java @@ -7,6 +7,7 @@ import org.springframework.stereotype.Service; import com.tinkerforge.AlreadyConnectedException; +import com.tinkerforge.BrickHAT; import com.tinkerforge.BrickletLoadCellV2; import com.tinkerforge.IPConnection; import com.tinkerforge.NetworkException; @@ -103,8 +104,9 @@ private final class EnumerateListenerImpl implements IPConnection.EnumerateListe public void enumerate(String uid, String connectedUid, char position, short[] hardwareVersion, short[] firmwareVersion, int deviceIdentifier, short enumerationType) { - Discovery discovery = new Discovery(uid, connectedUid, position, asString(hardwareVersion), - asString(firmwareVersion), deviceIdentifier, enumerationType); + Discovery discovery = new Discovery(uid, connectedUid, Character.toString(position), + asString(hardwareVersion), asString(firmwareVersion), deviceAsString(deviceIdentifier), + enumAsString(enumerationType)); discoveryResult.add(discovery); } @@ -112,6 +114,30 @@ private String asString(short[] version) { return version[0] + "." + version[1] + "." + version[2]; } + private String enumAsString(short enumerationType) { + switch (enumerationType) { + case IPConnection.ENUMERATION_TYPE_AVAILABLE: + return "AVAILABLE"; + case IPConnection.ENUMERATION_TYPE_CONNECTED: + return "CONNECTED"; + case IPConnection.ENUMERATION_TYPE_DISCONNECTED: + return "DISCONNECTED"; + default: + return "UNKNOWN"; + } + } + + private String deviceAsString(int deviceIdentifier) { + switch (deviceIdentifier) { + case BrickletLoadCellV2.DEVICE_IDENTIFIER: + return "Load Cell V2 Bricklet"; + case BrickHAT.DEVICE_IDENTIFIER: + return "HAT Brick"; + default: + return String.valueOf(deviceIdentifier); + } + } + } }