diff --git a/cellar-app/src/main/java/nl/lengrand/Main.java b/cellar-app/src/main/java/nl/lengrand/Main.java index 0acf567..3fee4a4 100644 --- a/cellar-app/src/main/java/nl/lengrand/Main.java +++ b/cellar-app/src/main/java/nl/lengrand/Main.java @@ -43,7 +43,7 @@ public final class Main { Server server = startServer(); startMonitoring(); - System.out.println("http://localhost:" + server.port() + "/greet"); + System.out.println("http://localhost:" + server.port()); } static void startMonitoring(){ diff --git a/cellar-app/src/main/java/nl/lengrand/faunadb/SensorApi.java b/cellar-app/src/main/java/nl/lengrand/faunadb/SensorApi.java index e7548e3..dd6594e 100644 --- a/cellar-app/src/main/java/nl/lengrand/faunadb/SensorApi.java +++ b/cellar-app/src/main/java/nl/lengrand/faunadb/SensorApi.java @@ -20,19 +20,26 @@ public class SensorApi { connection.init(); } - public void add(SensorValue values) throws ExecutionException, InterruptedException { - Value addDataResult = connection.getClient().query( - Create( - Collection(Language.Value(COLLECTION_NAME)), - Obj("data", - Obj( "temperature", Language.Value(values.getTemperature()), - "humidity", Language.Value(values.getHumidity()) , - "reading", Language.Value(values.getReading()), - "timestamp", Language.Value(Instant.now()) - ) - ) - ) - ).get(); - System.out.println("Added sensor data to collection " + COLLECTION_NAME + ":\n " + addDataResult + "\n"); + public void add(SensorValue values) { + Value addDataResult = null; + try { + addDataResult = connection.getClient().query( + Create( + Collection(Language.Value(COLLECTION_NAME)), + Obj("data", + Obj( "temperature", Language.Value(values.getTemperature()), + "humidity", Language.Value(values.getHumidity()) , + "reading", Language.Value(values.getReading()), + "timestamp", Language.Value(Instant.now()) + ) + ) + ) + ).get(); + System.out.println("Added sensor data to collection " + COLLECTION_NAME + ":\n " + addDataResult + "\n"); + } catch (InterruptedException | ExecutionException e) { + System.out.println("Failing to upload data! Restarting Connection"); + e.printStackTrace(); + connection.init(); + } } } \ No newline at end of file