GGD/target/classes/rules/SoilMoisture.drl

41 lines
2.2 KiB
Plaintext
Raw Normal View History

import java.util.List;
import java.util.HashMap;
import java.util.Map;
import java.util.Iterator;
import eu.hsrw.ias.ggd.ScheduledTask;
import javax.swing.JOptionPane;
import HttpCall.HttpPost;
import eu.hsrw.ias.ggd.SensorData
rule "Soil Moisture"
when
$tMap: HashMap( containsKey("soilMoisture") == true )
//In this part we are iterating through the entire map
e: Map.Entry(k:key, v:value) from $tMap.entrySet()
// for(e <- $tMap) {
SensorData(level: value ) from v
SensorData(tag: sensorTag) from v
SensorData(id : deviceId) from v
then
HttpPost httpPost = new HttpPost();
String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
if (level <= 30 && k.equals("soilMoisture") ) {
JOptionPane.showMessageDialog(null,"Be Careful the soil is dry : "+level+" in the following sensor :"+tag +"in the device:"+id,"Soil Moisture",JOptionPane.INFORMATION_MESSAGE);
final String dataInfo = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Be Careful the soil sensor %s is dry: %s \", \"soilMoisture\": %s}]}}", fixedIdG1,tag,level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dataInfo);
System.out.println("Soil is dry"+level+" in the following sensor"+tag);
}
else if (level <= 80 && k.equals("soilMoisture") ) {
JOptionPane.showMessageDialog(null,"Optimal moisture in the soil : "+level+" in the following sensor"+tag,"Soil Moisture",JOptionPane.INFORMATION_MESSAGE);
final String data = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Be Careful the soil sensor %s is wet: %s\", \"soilMoisture\": %s}]}}", fixedIdG1,tag,level,level);
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",data);
System.out.println("Optimal moisture in the soil"+level+" in the following sensor"+tag);
}
end