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 then // String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";//Germes String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica HttpPost httpPost = new HttpPost(); final String criticalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Soil Moisture %s in the following device: %s. It’s too dry and the field needs fertilizer \", \"soilMoisture\": %s}]}}",greenhouse2, 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="e5ec9f15-f214-455d-9f02-3c134c770dc1"; HttpPost httpPost = new HttpPost(); final String optimalSoilMoistureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal Soil Moisture %s in the following device %s. Everything is in order. \", \"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