mirror of
https://github.com/jlengrand/cellar.git
synced 2026-03-10 08:01:19 +00:00
Simple retry mechanism, and start script
This commit is contained in:
@@ -32,4 +32,6 @@ ping raspberrypi.local
|
||||
|
||||
|
||||
http://hirt.se/blog/?p=1116
|
||||
https://github.com/fauna/faunadb-jvm/blob/master/docs/java.md
|
||||
https://github.com/fauna/faunadb-jvm/blob/master/docs/java.md
|
||||
|
||||
Stack Overflow Question : https://iot.stackexchange.com/questions/4662/in-what-form-should-i-store-data-in-the-cloud-for-a-single-device
|
||||
@@ -7,10 +7,24 @@ import javax.enterprise.context.ApplicationScoped;
|
||||
@ApplicationScoped
|
||||
public class CellarProvider {
|
||||
|
||||
private static final int N_TRIES = 5;
|
||||
|
||||
private Dht11Driver driver = new Dht11Driver();
|
||||
|
||||
public SensorValue getSensorValues(){
|
||||
float[] values = driver.getTemperatureAndHumidity();
|
||||
|
||||
int counter = 0;
|
||||
float[] values;
|
||||
do {
|
||||
values = driver.getTemperatureAndHumidity();
|
||||
counter++;
|
||||
}
|
||||
while (noSensorData(values) && counter < N_TRIES);
|
||||
|
||||
return new SensorValue(values);
|
||||
}
|
||||
|
||||
private boolean noSensorData(float[] values) {
|
||||
return values[0] == 0 && values[1] == 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ public class SensorApi {
|
||||
Obj("data",
|
||||
Obj( "temperature", Language.Value(values.getTemperature()),
|
||||
"humidity", Language.Value(values.getHumidity()) ,
|
||||
"reading", Language.Value(values.getReading()),
|
||||
"timestamp", Language.Value(Instant.now())
|
||||
)
|
||||
)
|
||||
@@ -34,36 +35,4 @@ public class SensorApi {
|
||||
).get();
|
||||
System.out.println("Added sensor data to collection " + COLLECTION_NAME + ":\n " + addDataResult + "\n");
|
||||
}
|
||||
|
||||
public void add(float[] res) throws ExecutionException, InterruptedException {
|
||||
Value addDataResult = connection.getClient().query(
|
||||
Create(
|
||||
Collection(Language.Value(COLLECTION_NAME)),
|
||||
Obj("data",
|
||||
Obj( "temperature", Language.Value(res[0]),
|
||||
"humidity", Language.Value(res[1]),
|
||||
"timestamp", Language.Value(Instant.now())
|
||||
)
|
||||
)
|
||||
)
|
||||
).get();
|
||||
System.out.println("Added sensor data to collection " + COLLECTION_NAME + ":\n " + addDataResult + "\n");
|
||||
}
|
||||
|
||||
public void update(float[] res) throws ExecutionException, InterruptedException {
|
||||
Value updateDataResult =
|
||||
connection.getClient().query(
|
||||
Update(
|
||||
Select(Language.Value("ref"), Get(Match(Index(INDEX_NAME), Language.Value(UPDATE_DEVICE_NAME)))),
|
||||
Obj("data",
|
||||
Obj(
|
||||
"temperature", Language.Value(res[0]),
|
||||
"humidity", Language.Value(res[1]),
|
||||
"timestamp", Language.Value(Instant.now())
|
||||
)
|
||||
)
|
||||
)
|
||||
).get();
|
||||
System.out.println("Updated sensor data from collection " + COLLECTION_NAME + ":\n " + updateDataResult + "\n");
|
||||
}
|
||||
}
|
||||
3
startCellar.sh
Executable file
3
startCellar.sh
Executable file
@@ -0,0 +1,3 @@
|
||||
#!/bin/bash
|
||||
|
||||
nohup java -jar cellar-app/target/cellar-app.jar &
|
||||
Reference in New Issue
Block a user