diff --git a/src/main/java/JSON_Unpack/BoxCall4Partner.java b/src/main/java/JSON_Unpack/BoxCall4Partner.java index 9b09126..c98d261 100644 --- a/src/main/java/JSON_Unpack/BoxCall4Partner.java +++ b/src/main/java/JSON_Unpack/BoxCall4Partner.java @@ -43,17 +43,18 @@ public class BoxCall4Partner { cName = readFile.ReadFromFile(homeRoot + cName + ".txt"); ArrayList listOfCompanyOutputs = new ArrayList(); - String[] arrayOfCompany = cName.split(","); - for (String iterator : arrayOfCompany) { + String[] listOfCompanyDevices = cName.split(","); + for (String companyExternalID : listOfCompanyDevices) { for (int i = 0; i < jsonarray.length(); i++) { - JSONObject jsonobject = jsonarray.getJSONObject(i); - String jsonExternalID = jsonobject.getString("externalId"); - if (iterator.equals(jsonExternalID)) { - String jsonID = jsonobject.getString("id"); + JSONObject deviceFromCall = jsonarray.getJSONObject(i); + String deviceExternalID = deviceFromCall.getString("externalId"); + + if (companyExternalID.equals(deviceExternalID)) { + String backendID = deviceFromCall.getString("id"); // String deviceID = jsonobject.getString("deviceId"); String companyOutput = httpCall.HttpGetCall(devUrl + "devices/" + jsonID + "/sensors" + "?access_token=" + token, token); listOfCompanyOutputs.add(companyOutput); - writingIntoFile.WriteFile(homeRoot + iterator + ".json", companyOutput); + writingIntoFile.WriteFile(homeRoot + companyExternalID + ".json", companyOutput); } } diff --git a/src/main/java/eu/hsrw/ias/ggd/Device.java b/src/main/java/eu/hsrw/ias/ggd/Device.java index 5e4f5ef..a34dd75 100644 --- a/src/main/java/eu/hsrw/ias/ggd/Device.java +++ b/src/main/java/eu/hsrw/ias/ggd/Device.java @@ -34,7 +34,6 @@ public class Device { return setId("70B3D570500042D7"); case "e8c3fca3-c5cd-48e7-9224-0f8c294fa3c0": return setId("70B3D57050004EF4"); - case "f9bb4a5c-f783-4bcf-8c34-0a7c3dd5a632": return setId("70B3D57050006223"); case "6c9efd4a-db04-453d-8ab8-d480ec97dd26": diff --git a/src/main/java/eu/hsrw/ias/ggd/Notification.java b/src/main/java/eu/hsrw/ias/ggd/Notification.java index 3d989ca..ba5df74 100644 --- a/src/main/java/eu/hsrw/ias/ggd/Notification.java +++ b/src/main/java/eu/hsrw/ias/ggd/Notification.java @@ -1,7 +1,7 @@ package eu.hsrw.ias.ggd; public class Notification { - private Severity severity = Severity.None; + private Severity severity = Severity.Optimal; private String type; private SensorData cause; diff --git a/src/main/java/eu/hsrw/ias/ggd/Severity.java b/src/main/java/eu/hsrw/ias/ggd/Severity.java index e3b963c..7ac5dd0 100644 --- a/src/main/java/eu/hsrw/ias/ggd/Severity.java +++ b/src/main/java/eu/hsrw/ias/ggd/Severity.java @@ -1,7 +1,7 @@ package eu.hsrw.ias.ggd; public enum Severity { - None, + Optimal, Info, Warning, Error, diff --git a/src/main/resources/rules/CriticalBattery.drl b/src/main/resources/rules/CriticalBattery.drl index 4051ee0..0310a6e 100644 --- a/src/main/resources/rules/CriticalBattery.drl +++ b/src/main/resources/rules/CriticalBattery.drl @@ -8,7 +8,7 @@ import eu.hsrw.ias.ggd.Severity; import eu.hsrw.ias.ggd.Device; -rule "Critical Battery" +rule "CriticalBattery" when device: Device(sensorDatas: sensorData) sensorData: SensorData(tag == "battery", value < 4.0) from sensorDatas @@ -19,7 +19,38 @@ rule "Critical Battery" HttpPost httpPost = new HttpPost(); final String criticalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput); - insert(new Notification("battery", sensorData, Severity.Info)); + insert(new Notification("battery", sensorData, Severity.Critical)); + +// modify(sensorData){ +// setState(Severity.Critical) +// } + +end + +rule "OptimalBattery" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "battery", value > 4.0) from sensorDatas + + then + + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String optimalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalBatteryOutput); + insert(new Notification("battery", sensorData, Severity.Optimal)); + +// modify(sensorData){ +// setState(Severity.Optimal) +// } + +end + + + + + + // System.out.println(sensorData.getTag()+" "+sensorData.getValue()); // System.out.println(device); @@ -92,7 +123,4 @@ rule "Critical Battery" // } finalOutput = String.format("{\"id\":\"70B3D570500042D7-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the device 1 is critical\",}]}}"); System.out.println(finalOutput); - }*/ - -end - + }*/ \ No newline at end of file diff --git a/src/main/resources/rules/CriticalPrecipitation.drl b/src/main/resources/rules/CriticalPrecipitation.drl new file mode 100644 index 0000000..1d32305 --- /dev/null +++ b/src/main/resources/rules/CriticalPrecipitation.drl @@ -0,0 +1,24 @@ +import java.util.HashMap; +import java.util.Map; +import eu.hsrw.ias.ggd.SensorData +import javax.swing.JOptionPane +import HttpCall.HttpPost +import eu.hsrw.ias.ggd.Notification +import eu.hsrw.ias.ggd.Severity; +import eu.hsrw.ias.ggd.Device; + +rule "CriticalPrecipitation" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "precipitation", value > 15.5) from sensorDatas + then + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String criticalPrecipitationOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Precipitation %s in the following sensor %s \", \"precipitation\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalPrecipitationOutput); + insert(new Notification("precipitation", sensorData, Severity.Warning)); + +// modify(sensorData){ +// setState(Severity.Critical) +// } +end diff --git a/src/main/resources/rules/CriticalSoilConductivity.drl b/src/main/resources/rules/CriticalSoilConductivity.drl new file mode 100644 index 0000000..c42a0f9 --- /dev/null +++ b/src/main/resources/rules/CriticalSoilConductivity.drl @@ -0,0 +1,7 @@ +package rules; +dialect "mvel" + +rule "CriticalSoilConductivity" + when + then +end diff --git a/src/main/resources/rules/CriticalSoilMoisture.drl b/src/main/resources/rules/CriticalSoilMoisture.drl index 958bfff..bd6a81d 100644 --- a/src/main/resources/rules/CriticalSoilMoisture.drl +++ b/src/main/resources/rules/CriticalSoilMoisture.drl @@ -16,5 +16,24 @@ rule "CriticalSoilMoisture" HttpPost httpPost = new HttpPost(); final String criticalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalSoilMoistureOutput); + final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\"}]}}",device.IdMapper(device.getId()),device.getId()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical); insert(new Notification("soilMoisture", sensorData, Severity.Critical)); end + +rule "OptimalSoilMoisture" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas + then + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String optimalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalSoilMoistureOutput); + insert(new Notification("soilMoisture", sensorData, Severity.Optimal)); + //device.setState(Severity.Optimal); + +// modify(device){ +// setState(Severity.Optimal) +// } +end \ No newline at end of file diff --git a/src/main/resources/rules/CriticalSoilTemperature.drl b/src/main/resources/rules/CriticalSoilTemperature.drl new file mode 100644 index 0000000..d143850 --- /dev/null +++ b/src/main/resources/rules/CriticalSoilTemperature.drl @@ -0,0 +1,7 @@ +package rules; +dialect "mvel" + +rule "CriticalSoilTemperature" + when + then +end diff --git a/src/main/resources/rules/CriticalTemperature.drl b/src/main/resources/rules/CriticalTemperature.drl index a6e8dd3..918f533 100644 --- a/src/main/resources/rules/CriticalTemperature.drl +++ b/src/main/resources/rules/CriticalTemperature.drl @@ -10,7 +10,7 @@ import eu.hsrw.ias.ggd.Device; rule "CriticalTemperature" when device: Device(sensorDatas: sensorData) - sensorData: SensorData(tag == "temperature", value < 10.0 || value >30.0) from sensorDatas + sensorData: SensorData(tag == "temperature", value < 10.0 || value > 30.0) from sensorDatas then String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; HttpPost httpPost = new HttpPost(); @@ -21,3 +21,22 @@ rule "CriticalTemperature" System.out.println(deviceCritical); insert(new Notification("temperature", sensorData, Severity.Critical)); end + +rule "OptimalTemperature" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "temperature", value > 10.0 && value < 30.0) from sensorDatas + then + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String optimalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalTemperatureOutput); + insert(new Notification("temperature", sensorData, Severity.Optimal)); + System.out.println("Optimal"); + +// modify(sensorData){ +// setState(Severity.Optimal) +// } + + end + diff --git a/src/main/resources/rules/DielectricPermittivity.drl b/src/main/resources/rules/DielectricPermittivity.drl index c8eef0c..80e781f 100644 --- a/src/main/resources/rules/DielectricPermittivity.drl +++ b/src/main/resources/rules/DielectricPermittivity.drl @@ -16,5 +16,5 @@ rule "DielectricPermittivity" HttpPost httpPost = new HttpPost(); final String dielectricPermittivityOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical dielectricPermittivity %s in the following sensor %s \", \"dielectricPermittivityOutput\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput); - insert(new Notification("dielectricPermittivity", sensorData, Severity.Info)); + insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning)); end diff --git a/src/main/resources/rules/optimal.drl b/src/main/resources/rules/optimal.drl new file mode 100644 index 0000000..950bda3 --- /dev/null +++ b/src/main/resources/rules/optimal.drl @@ -0,0 +1,15 @@ +import eu.hsrw.ias.ggd.Notification; +import eu.hsrw.ias.ggd.Severity +import HttpCall.HttpPost; +import eu.hsrw.ias.ggd.Device; + +rule "Green House Optimal" +when + warning: Notification(severity == Severity.Optimal) + +then + HttpPost httpPost = new HttpPost(); + final String optimalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is optimal\"}]}}"); +// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalGreenhouse); + System.out.println("Green House optimal, because of: '"+warning.getType()+"'"); +end diff --git a/src/main/resources/rules/warnings.drl b/src/main/resources/rules/warnings.drl index 21df222..bb4b855 100644 --- a/src/main/resources/rules/warnings.drl +++ b/src/main/resources/rules/warnings.drl @@ -2,14 +2,14 @@ import eu.hsrw.ias.ggd.Notification; import eu.hsrw.ias.ggd.Severity import HttpCall.HttpPost; -rule "Green House Critical" -when - warning: Notification(severity > Severity.Info) -then - HttpPost httpPost = new HttpPost(); - final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}"); - httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse); - System.out.println(criticalGreenhouse); - System.out.println("Green House critical, because of: '"+warning.getType()+"'"); - -end \ No newline at end of file +//rule "Green House Critical" +//when +// warning: Notification(severity > Severity.Warning) +//then +// HttpPost httpPost = new HttpPost(); +// final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}"); +// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse); +// System.out.println(criticalGreenhouse); +// System.out.println("Green House critical, because of: '"+warning.getType()+"'"); +// +//end \ No newline at end of file diff --git a/target/classes/rules/CriticalBattery.drl b/target/classes/rules/CriticalBattery.drl index 4051ee0..0310a6e 100644 --- a/target/classes/rules/CriticalBattery.drl +++ b/target/classes/rules/CriticalBattery.drl @@ -8,7 +8,7 @@ import eu.hsrw.ias.ggd.Severity; import eu.hsrw.ias.ggd.Device; -rule "Critical Battery" +rule "CriticalBattery" when device: Device(sensorDatas: sensorData) sensorData: SensorData(tag == "battery", value < 4.0) from sensorDatas @@ -19,7 +19,38 @@ rule "Critical Battery" HttpPost httpPost = new HttpPost(); final String criticalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput); - insert(new Notification("battery", sensorData, Severity.Info)); + insert(new Notification("battery", sensorData, Severity.Critical)); + +// modify(sensorData){ +// setState(Severity.Critical) +// } + +end + +rule "OptimalBattery" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "battery", value > 4.0) from sensorDatas + + then + + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String optimalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalBatteryOutput); + insert(new Notification("battery", sensorData, Severity.Optimal)); + +// modify(sensorData){ +// setState(Severity.Optimal) +// } + +end + + + + + + // System.out.println(sensorData.getTag()+" "+sensorData.getValue()); // System.out.println(device); @@ -92,7 +123,4 @@ rule "Critical Battery" // } finalOutput = String.format("{\"id\":\"70B3D570500042D7-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the device 1 is critical\",}]}}"); System.out.println(finalOutput); - }*/ - -end - + }*/ \ No newline at end of file diff --git a/target/classes/rules/CriticalSoilMoisture.drl b/target/classes/rules/CriticalSoilMoisture.drl index 958bfff..8340986 100644 --- a/target/classes/rules/CriticalSoilMoisture.drl +++ b/target/classes/rules/CriticalSoilMoisture.drl @@ -9,12 +9,36 @@ import eu.hsrw.ias.ggd.Device; rule "CriticalSoilMoisture" when - device: Device(sensorDatas: sensorData) - sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas then String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; HttpPost httpPost = new HttpPost(); final String criticalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalSoilMoistureOutput); + final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\"}]}}",device.IdMapper(device.getId()),device.getId()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical); insert(new Notification("soilMoisture", sensorData, Severity.Critical)); + +// modify(device){ +// setState(Severity.Critical) +// } + end + +rule "OptimalSoilMoisture" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas + then + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String optimalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Soil Moisture %s in the following device %s \", \"soilMoisture\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalSoilMoistureOutput); + insert(new Notification("soilMoisture", sensorData, Severity.Optimal)); + //device.setState(Severity.Optimal); + +// modify(device){ +// setState(Severity.Optimal) +// } +end \ No newline at end of file diff --git a/target/classes/rules/CriticalTemperature.drl b/target/classes/rules/CriticalTemperature.drl index 39be481..5472b34 100644 --- a/target/classes/rules/CriticalTemperature.drl +++ b/target/classes/rules/CriticalTemperature.drl @@ -10,14 +10,38 @@ import eu.hsrw.ias.ggd.Device; rule "CriticalTemperature" when device: Device(sensorDatas: sensorData) - sensorData: SensorData(tag == "temperature", value < 10.0 || value >30.0) from sensorDatas + sensorData: SensorData(tag == "temperature", value < 10.0 || value > 30.0) from sensorDatas then String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; HttpPost httpPost = new HttpPost(); final String criticalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalTemperatureOutput); - final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\",}]}}",device.IdMapper(device.getId()),device.getId()); + final String deviceCritical = String.format("{\"id\":\"%s-status\",\"data\":{\"measured\":[{ \"criticalStatus\": \"The status of %s device is critical\"}]}}",device.IdMapper(device.getId()),device.getId()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical); System.out.println(deviceCritical); insert(new Notification("temperature", sensorData, Severity.Critical)); + +// modify(device){ +// setState(Severity.Critical) +// } + end + +rule "OptimalTemperature" + when + device: Device(sensorDatas: sensorData) + sensorData: SensorData(tag == "temperature", value > 10.0 && value < 30.0) from sensorDatas + then + String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633"; + HttpPost httpPost = new HttpPost(); + final String optimalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); + httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalTemperatureOutput); + insert(new Notification("temperature", sensorData, Severity.Optimal)); + System.out.println("Optimal"); + +// modify(sensorData){ +// setState(Severity.Optimal) +// } + + end + diff --git a/target/classes/rules/DielectricPermittivity.drl b/target/classes/rules/DielectricPermittivity.drl index c8eef0c..80e781f 100644 --- a/target/classes/rules/DielectricPermittivity.drl +++ b/target/classes/rules/DielectricPermittivity.drl @@ -16,5 +16,5 @@ rule "DielectricPermittivity" HttpPost httpPost = new HttpPost(); final String dielectricPermittivityOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical dielectricPermittivity %s in the following sensor %s \", \"dielectricPermittivityOutput\": %s}]}}",greenhouse1, sensorData.getValue(),sensorData.getTag(),sensorData.getValue()); httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput); - insert(new Notification("dielectricPermittivity", sensorData, Severity.Info)); + insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning)); end diff --git a/target/classes/rules/warnings.drl b/target/classes/rules/warnings.drl index 5913553..bb4b855 100644 --- a/target/classes/rules/warnings.drl +++ b/target/classes/rules/warnings.drl @@ -2,14 +2,14 @@ import eu.hsrw.ias.ggd.Notification; import eu.hsrw.ias.ggd.Severity import HttpCall.HttpPost; -rule "Green House Critical" -when - warning: Notification(severity > Severity.Info) -then - HttpPost httpPost = new HttpPost(); - final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\",}]}}"); - httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse); - System.out.println(criticalGreenhouse); - System.out.println("Green House critical, because of: '"+warning.getType()+"'"); - -end \ No newline at end of file +//rule "Green House Critical" +//when +// warning: Notification(severity > Severity.Warning) +//then +// HttpPost httpPost = new HttpPost(); +// final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}"); +// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse); +// System.out.println(criticalGreenhouse); +// System.out.println("Green House critical, because of: '"+warning.getType()+"'"); +// +//end \ No newline at end of file