forked from kevin.shehu/GGD
FIX : Sensor reading
NEW : Idea for Rule Engine
This commit is contained in:
@@ -22,7 +22,7 @@ public class ApiCall {
|
||||
UserCredentials userCredentials = new UserCredentials();
|
||||
final String username = userCredentials.getUsername();
|
||||
final String password = userCredentials.getPassword();
|
||||
final String homeRoot = userCredentials.getHomeRoot();
|
||||
final String homeRoot = UserCredentials.getHomeRoot();
|
||||
String outputToken;
|
||||
WriteFile writingIntoFile = new WriteFile();
|
||||
Date now; // to display current time
|
||||
@@ -46,15 +46,28 @@ public class ApiCall {
|
||||
ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner();
|
||||
ArrayList<String> outputValue = (readSensors4Partner.FetchSensor4Box("Germes", token));
|
||||
for(int i=0;i<outputValue.size();i++){
|
||||
JSONArray jsonArray = new JSONArray(outputValue.get(i));
|
||||
for(int j=0; j<jsonArray.length(); j++){
|
||||
JSONObject jsonobject = jsonArray.getJSONObject(j);
|
||||
double value = jsonobject.getDouble("value");
|
||||
String sensorTag = jsonobject.getString("sensorTag");
|
||||
String sensorId = jsonobject.getString("sensorId");
|
||||
String deviceId = jsonobject.getString("deviceId");
|
||||
Device device;
|
||||
JSONArray sensorDatas = new JSONArray(outputValue.get(i));
|
||||
|
||||
finalOutput.put(sensorTag, new SensorData(deviceId, value,sensorId));
|
||||
for(int j=0; j<sensorDatas.length(); j++) { //15
|
||||
JSONObject sensorData = sensorDatas.getJSONObject(j);
|
||||
|
||||
String deviceId = sensorData.getString("deviceId");
|
||||
|
||||
double value = sensorData.getDouble("value");
|
||||
String sensorTag = sensorData.getString("sensorTag");
|
||||
String sensorId = sensorData.getString("sensorId");
|
||||
|
||||
SensorData sd = new SensorData(sensorId, value, sensorTag);
|
||||
|
||||
if(devices.containsKey(deviceId)) {
|
||||
device = devices.get(deviceId);
|
||||
device.addSensorData(sd);
|
||||
} else {
|
||||
device = new Device(deviceId);
|
||||
device.addSensorData(sd);
|
||||
devices.put(deviceId, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
return finalOutput;
|
||||
|
||||
59
src/main/java/eu/hsrw/ias/ggd/Device.java
Normal file
59
src/main/java/eu/hsrw/ias/ggd/Device.java
Normal file
@@ -0,0 +1,59 @@
|
||||
package eu.hsrw.ias.ggd;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class Device {
|
||||
private String id;
|
||||
private List<SensorData> data;
|
||||
|
||||
public Device(String identifier) {
|
||||
this.id = identifier;
|
||||
this.data = new LinkedList<SensorData>();
|
||||
}
|
||||
|
||||
public void addSensorData(SensorData d) {
|
||||
this.data.add(d);
|
||||
}
|
||||
|
||||
public List<SensorData> getSensorData() {
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public Boolean hasTag(String tag) {
|
||||
for (SensorData sensorData : data) {
|
||||
if (sensorData.getTag() == tag) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public SensorData getSensorDataByTag(String tag) {
|
||||
for (SensorData sd : data) {
|
||||
if (sd.getTag() == tag) return sd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public SensorData getSensorDataById(String id) {
|
||||
for (SensorData sd : data) {
|
||||
if (sd.getSensorId() == id) return sd;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
String str = "Device: '"+ id +"', data: [";
|
||||
|
||||
for(SensorData sd: data) {
|
||||
str += "SensorData(id: '"+ sd.getSensorId() +"',";
|
||||
str += " tag: '"+ sd.getTag() +"',";
|
||||
str += " value: "+ sd.getValue() +")";
|
||||
}
|
||||
|
||||
return str + "]";
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ public class Isis {
|
||||
|
||||
return httpMethodPost.HttpCallPost(baseURL, body);
|
||||
}
|
||||
public static void main(String args[]){
|
||||
public static void main(String[] args){
|
||||
try {
|
||||
String output = OnCallMethod("Greenhouse 1", "status");
|
||||
System.out.println(output);
|
||||
|
||||
37
src/main/java/eu/hsrw/ias/ggd/Notification.java
Normal file
37
src/main/java/eu/hsrw/ias/ggd/Notification.java
Normal file
@@ -0,0 +1,37 @@
|
||||
package eu.hsrw.ias.ggd;
|
||||
|
||||
public class Notification {
|
||||
private Severity severity = Severity.None;
|
||||
private String type;
|
||||
private SensorData cause;
|
||||
|
||||
public Notification(String t, SensorData d, Severity s) {
|
||||
this.type = t;
|
||||
this.cause = d;
|
||||
this.severity = s;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public SensorData getCause() {
|
||||
return cause;
|
||||
}
|
||||
|
||||
public void setCause(SensorData cause) {
|
||||
this.cause = cause;
|
||||
}
|
||||
|
||||
public Severity getSeverity() {
|
||||
return this.severity;
|
||||
}
|
||||
|
||||
public void setSeverity(Severity severity) {
|
||||
this.severity = severity;
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class ScheduledTask extends TimerTask {
|
||||
FactHandle fact1;
|
||||
fact1 = kSession.insert(outputDevices);
|
||||
// System.out.println(fact1);
|
||||
kSession.insert(fact1);
|
||||
// kSession.insert(fact1);
|
||||
kSession.fireAllRules();
|
||||
|
||||
|
||||
|
||||
9
src/main/java/eu/hsrw/ias/ggd/Severity.java
Normal file
9
src/main/java/eu/hsrw/ias/ggd/Severity.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package eu.hsrw.ias.ggd;
|
||||
|
||||
public enum Severity {
|
||||
None,
|
||||
Info,
|
||||
Warning,
|
||||
Error,
|
||||
Critical
|
||||
}
|
||||
Reference in New Issue
Block a user