GGD/target/classes/rules/CriticalTemperature.drl

24 lines
1.5 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 "CriticalTemperature"
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 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());
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
System.out.println(deviceCritical);
insert(new Notification("temperature", sensorData, Severity.Critical));
end