GGD/target/classes/rules/CriticalSoilMoisture.drl

44 lines
2.6 KiB
Plaintext
Raw Normal View History

2021-12-14 14:52:02 +01:00
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 "CriticalSoilMoisture"
when
device: Device(sensorDatas: sensorData)
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
2021-12-14 14:52:02 +01:00
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);
2021-12-14 14:52:02 +01:00
insert(new Notification("soilMoisture", sensorData, Severity.Critical));
// modify(device){
// setState(Severity.Critical)
// }
2021-12-14 14:52:02 +01:00
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