From 8946430b973fd9dcdf6fcb6ae8697906d68f6860 Mon Sep 17 00:00:00 2001 From: Medad Rufus Newman Date: Sat, 7 May 2022 18:31:33 +0100 Subject: [PATCH] drop doc id and use correct path --- .../AmateurSondehubUploader.java | 28 ++++--------------- .../IAmateurSondehubRestApi.java | 14 +++------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/AmateurSondehubUploader.java b/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/AmateurSondehubUploader.java index 5191c39..48151da 100644 --- a/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/AmateurSondehubUploader.java +++ b/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/AmateurSondehubUploader.java @@ -109,12 +109,10 @@ public final class AmateurSondehubUploader { // encode sentence as raw bytes byte[] bytes = sentence.getBytes(StandardCharsets.US_ASCII); - // determine docId - String docId = createDocId(bytes); for (HabReceiver receiver : receivers) { // create Json - HabitatPayloadTelemetryDoc doc = new HabitatPayloadTelemetryDoc(instant, bytes); + PayloadTelemetryDoc doc = new payloadTelemetryDoc(instant, bytes); doc.addCallSign(receiver.getCallsign()); String json = doc.format(); @@ -127,17 +125,16 @@ public final class AmateurSondehubUploader { * Performs the actual payload telemetry upload as a REST-like call towards * amateurSondehub. * - * @param docId the document id * @param json the JSON payload */ - private void uploadPayloadTelemetry(String docId, String json) { - LOG.info("Upload payload telemetry doc {}: {}", docId, json); + private void uploadPayloadTelemetry(String json) { + LOG.info("Upload payload telemetry: {}", json); try { - Response response = restClient.updateListener(docId, json).execute(); + Response response = restClient.updateListener(json).execute(); if (response.isSuccessful()) { - LOG.info("Result payload telemetry doc {}: {}", docId, response.body()); + LOG.info("Result payload telemetry: {}", response.body()); } else { - LOG.warn("Result payload telemetry doc {}: {}", docId, response.message()); + LOG.warn("Result payload telemetry: {}", response.message()); } } catch (IOException e) { LOG.warn("Caught IOException: {}", e.getMessage()); @@ -145,17 +142,4 @@ public final class AmateurSondehubUploader { LOG.error("Caught Exception: {}", e); } } - - /** - * Creates the document id from the raw payload telemetry sentence. - * - * @param bytes the raw sentence - * @return the document id - */ - private String createDocId(byte[] bytes) { - byte[] base64 = base64Encoder.encode(bytes); - byte[] hash = sha256.digest(base64); - return DatatypeConverter.printHexBinary(hash).toLowerCase(Locale.ROOT); - } - } diff --git a/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/IAmateurSondehubRestApi.java b/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/IAmateurSondehubRestApi.java index e95c54b..9d257b5 100644 --- a/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/IAmateurSondehubRestApi.java +++ b/ttnhabbridge/src/main/java/nl/sikken/bertrik/hab/amateurSondehub/IAmateurSondehubRestApi.java @@ -3,20 +3,14 @@ package nl.sikken.bertrik.hab.amateurSondehub; import nl.sikken.bertrik.hab.UploadResult; import retrofit2.Call; import retrofit2.http.Body; -import retrofit2.http.GET; import retrofit2.http.PUT; -import retrofit2.http.Path; -import retrofit2.http.Query; /** - * Interface definition for payload telemetry and listener telemetry towards AmateurSondehub. + * Interface definition for payload telemetry and listener telemetry towards + * AmateurSondehub. */ public interface IAmateurSondehubRestApi { - - @PUT("/habitat/_design/payload_telemetry/_update/add_listener/{doc_id}") - Call updateListener(@Path("doc_id") String docId, @Body String json); - - @PUT("/habitat/{doc_id}") - Call uploadDocument(@Path("doc_id") String docId, @Body String document); + @PUT("/amateur/telemetry") + Call uploadDocument(@Body String document); }