forked from kevin.shehu/GGD
Compare commits
6 Commits
Author | SHA1 | Date |
---|---|---|
|
c2f1337c14 | |
|
58cb531ec7 | |
|
d4f4b993bc | |
|
182f58e2f8 | |
|
af0bf649dc | |
|
f66fb9dd95 |
|
@ -2,9 +2,7 @@
|
||||||
### Java template
|
### Java template
|
||||||
# Compiled class file
|
# Compiled class file
|
||||||
*.class
|
*.class
|
||||||
|
|
||||||
src/main/java/Data/*.json
|
src/main/java/Data/*.json
|
||||||
node_modules
|
|
||||||
|
|
||||||
# Log file
|
# Log file
|
||||||
*.log
|
*.log
|
||||||
|
|
|
@ -1,10 +0,0 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="RunConfigurationProducerService">
|
|
||||||
<option name="ignoredProducers">
|
|
||||||
<set>
|
|
||||||
<option value="com.android.tools.idea.compose.preview.runconfiguration.ComposePreviewRunConfigurationProducer" />
|
|
||||||
</set>
|
|
||||||
</option>
|
|
||||||
</component>
|
|
||||||
</project>
|
|
72
README.md
72
README.md
|
@ -1,18 +1,37 @@
|
||||||
### **Gardeners Green Thumb Decision Support System** (GGD-DDS)
|
## **Gardeners Green Thumb Decision Support System** (GGD-DDS)
|
||||||
|
|
||||||
The service of decision support system is inferring knowledge from the available data of the greenhouse, the user input, and historical data what a user/the gardener should do & which action a gardener should execute to be successful with the growing process of the plants.
|
An open source rule engine, GGD engine and complex event processing (CEP) engine for Java™ and the JVM Platform.
|
||||||
These actions are called goals.
|
|
||||||
The list of inferred active goals is offered to other services of the system.
|
Drools is a business rule management system with a forward-chaining and backward-chaining inference based rules engine, allowing fast and reliable evaluation of rules and complex event processing.
|
||||||
|
A rule engine is also a fundamental building block to create an expert system which, in artificial intelligence, is a computer system that emulates the decision-making ability of a human expert.
|
||||||
|
|
||||||
|
Putting all of this together, a decision support system is designed with the help of drools library which is used in the project.
|
||||||
|
The service of decision support system is inferring knowledge from the available data of the greenhouse, the user input, and historical data what a user/the gardener should do.
|
||||||
|
The inferred knowledge derived from the algorithm are presented to the gardener where an action is taken.
|
||||||
|
These actions can be presented as goals where each goal is offered to other services of the system (partners).
|
||||||
The approach of the DSS is based on three eu.hsrw.ias.ggd.MainExe concepts:
|
The approach of the DSS is based on three eu.hsrw.ias.ggd.MainExe concepts:
|
||||||
|
|
||||||
**Fact knowledge (Knowledgebase)**
|
### **Facts Knowledgesession,and Knowledgebase**
|
||||||
|
|
||||||
1. Hardware Information(sensor data info)
|
***Facts are nothing but plain old java objects (POJO) that represents the data which serves as input for rules.***
|
||||||
2. Data information was given by an expert that is overwriting sensor data
|
|
||||||
3. User Input (We assume that the user is every time honest and that input is every time correct)
|
|
||||||
|
|
||||||
**Rules (General structure, if premises then consequence)**
|
***Knowledgesession :This component holds all the resources required for firing rule.
|
||||||
1. Explicit given by expert (before and during runtime)
|
Here, all facts are inserted into the single session, and then matching rules are fired.***
|
||||||
|
|
||||||
|
***KnowledgeBase is an interface which manages a collection of knowledge definitions like rules.
|
||||||
|
Knowledge packages are created by grouping knowledge definition.***
|
||||||
|
|
||||||
|
Since the creation of Knowledge packages is very expensive, KnowledgeBase stores and reuse them.
|
||||||
|
Knowledge Sessions are created from KnowledgeBase, which consumes less memory.
|
||||||
|
KnowledgeBase keeps track of each Knowledge Session, so that updates to knowledge base can be applied to all the session at run time.
|
||||||
|
Another advantage of KnowledgeBase is that, it is completely serializable.
|
||||||
|
We can restore serializable object of KnowledgeBase rather creating a new one.
|
||||||
|
In the following case StatefulKnowledgeSession are used.
|
||||||
|
So facts are inserted first and stored to KnowledgeSession where it is latter on provided to Knowledgebase.
|
||||||
|
|
||||||
|
|
||||||
|
### **Rules (General structure, if premises then consequence)**
|
||||||
|
1. Rules are given explicitly by the expert. The list of rules created for this project are:
|
||||||
1. Battery
|
1. Battery
|
||||||
2. Dielectric Permittivity
|
2. Dielectric Permittivity
|
||||||
3. Precipitation
|
3. Precipitation
|
||||||
|
@ -20,20 +39,27 @@ The list of inferred active goals is offered to other services of the system.
|
||||||
5. Soil Moisture
|
5. Soil Moisture
|
||||||
6. Soil Temperature
|
6. Soil Temperature
|
||||||
7. Temperature
|
7. Temperature
|
||||||
2. All this information is considered as facts which are part of the entire knowledge graph
|
2. One particular rule can be fired or multiple rules can be fired at the same time.
|
||||||
3. One particular rule can be fire on multiple rules can be fired. User defined.
|
|
||||||
|
|
||||||
**Goals**
|
### **Goals (Rule Outcome)**
|
||||||
1. Goals are active rules which are able to change the fact
|
1. Goals are active rules which are able to change the value of the fact.
|
||||||
2. Goals can be activated and deactivated based on the user preferences
|
2. Goals can be activated and deactivated based on the user preferences
|
||||||
3. Goals can have priorities
|
|
||||||
|
|
||||||
#### **Build**
|
|
||||||
Run the MainExe.java which is part of the eu.hsrw.ias.ggd package
|
### **Build**
|
||||||
#### **Usage**
|
1. Go to Build and build project in order to index all the dependecies required.
|
||||||
|
2. Run the *MainExe.java* which is part of the src/main/java/eu.hsrw.ias.ggd package
|
||||||
|
|
||||||
|
### **Usage**
|
||||||
You can reuse the project by changing the UserCredentials.java file located on the Credentials package.
|
You can reuse the project by changing the UserCredentials.java file located on the Credentials package.
|
||||||
It is possible to create new rules tailored to the needs.
|
It is possible to create new rules tailored to the needs of the use case scenario.
|
||||||
#### **Examples**
|
### **Examples**
|
||||||
For each sensor mentioned in the list of rules an example is given. You may change the values based on the needs of the expert/user.
|
For each sensor mentioned in the list of rules(src/main/resources/rules) an example is given.
|
||||||
#### **Dependencies**
|
You may change the values based on the needs of the expert/user.
|
||||||
drools.org
|
|
||||||
|
### **Dependencies**
|
||||||
|
org.drools version 7.48
|
||||||
|
|
||||||
|
org.slf4j version 1.7.30
|
||||||
|
|
||||||
|
com.google.code.gson 2.8.6
|
||||||
|
|
17
pom.xml
17
pom.xml
|
@ -109,6 +109,23 @@
|
||||||
<!-- <version>${runtime.version}</version>-->
|
<!-- <version>${runtime.version}</version>-->
|
||||||
<!-- </dependency>-->
|
<!-- </dependency>-->
|
||||||
|
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
|
||||||
|
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi</artifactId>
|
||||||
|
<version>5.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.poi</groupId>
|
||||||
|
<artifactId>poi-ooxml</artifactId>
|
||||||
|
<version>5.2.1</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jbpm</groupId>
|
<groupId>org.jbpm</groupId>
|
||||||
<artifactId>jbpm-test</artifactId>
|
<artifactId>jbpm-test</artifactId>
|
||||||
|
|
|
@ -0,0 +1,40 @@
|
||||||
|
package Credentials;
|
||||||
|
|
||||||
|
public class PlonkTest {
|
||||||
|
|
||||||
|
private final String server = "https://demo.m3lab.de"; // add your Keycloak-URL here (without /auth)
|
||||||
|
private final String realm = "Dokutool"; // the name of the realm
|
||||||
|
private final String grantType = "password"; // the granttype, with password you can login as a normal user
|
||||||
|
private final String clientId = "dokutool-postman"; // the name of the client you created in Keycloak
|
||||||
|
private final String clientSecret = "d102ee78-697d-4d1c-903b-f5883af2cf17"; // the secret you copied earlier
|
||||||
|
private final String username = "demo"; // the username of the user you want to test with
|
||||||
|
private final String password = "demo"; // the password of the user you want to test with
|
||||||
|
|
||||||
|
public String getServer() {
|
||||||
|
return server;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRealm() {
|
||||||
|
return realm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantType() {
|
||||||
|
return grantType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientId() {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientSecret() {
|
||||||
|
return clientSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
}
|
Binary file not shown.
|
@ -1 +1 @@
|
||||||
0Q6cHVQo9umiVSiZVf4DnsFMO4CgSv7RvpFiNMFTvZF1qiKDEVzSNpUOHegBv8wP
|
ZW6n3ZlQ5NFeWjfjhX3aQmdUJJxkCGy6tsZbMeZqHLiyAcHOAiR0f7QCQj655VBV
|
|
@ -0,0 +1,17 @@
|
||||||
|
package Files;
|
||||||
|
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static Credentials.UserCredentials.getHomeRoot;
|
||||||
|
|
||||||
|
|
||||||
|
public class ReadExcelFile {
|
||||||
|
|
||||||
|
public void readExcel() throws IOException {
|
||||||
|
// Create an instance of the class that reads Excel files
|
||||||
|
|
||||||
|
// Read XLSX file
|
||||||
|
FileInputStream file = new FileInputStream(getHomeRoot() + "Spritztagebuch.xlsx");
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,113 @@
|
||||||
|
package Files;
|
||||||
|
|
||||||
|
import Credentials.UserCredentials;
|
||||||
|
import HttpCall.PlonkHttpGet;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
public class UnZipFile {
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
//
|
||||||
|
// UserCredentials userCredentials = new UserCredentials();
|
||||||
|
// String workPath = userCredentials.getHomeRoot();
|
||||||
|
//
|
||||||
|
// Path source = Paths.get(workPath+"PlonkData.zip");
|
||||||
|
// Path target = Paths.get(workPath);
|
||||||
|
//
|
||||||
|
// try {
|
||||||
|
//
|
||||||
|
// unzipFolder(source, target);
|
||||||
|
// System.out.println("Done");
|
||||||
|
//
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
|
||||||
|
public static void unzipFolder(Path source, Path target) throws IOException {
|
||||||
|
|
||||||
|
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(source.toFile()))) {
|
||||||
|
|
||||||
|
// list files in zip
|
||||||
|
ZipEntry zipEntry = zis.getNextEntry();
|
||||||
|
|
||||||
|
while (zipEntry != null) {
|
||||||
|
|
||||||
|
boolean isDirectory = false;
|
||||||
|
// example 1.1
|
||||||
|
// some zip stored files and folders separately
|
||||||
|
// e.g data/
|
||||||
|
// data/folder/
|
||||||
|
// data/folder/file.txt
|
||||||
|
if (zipEntry.getName().endsWith(File.separator)) {
|
||||||
|
isDirectory = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
Path newPath = zipSlipProtect(zipEntry, target);
|
||||||
|
|
||||||
|
if (isDirectory) {
|
||||||
|
Files.createDirectories(newPath);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// example 1.2
|
||||||
|
// some zip stored file path only, need create parent directories
|
||||||
|
// e.g data/folder/file.txt
|
||||||
|
if (newPath.getParent() != null) {
|
||||||
|
if (Files.notExists(newPath.getParent())) {
|
||||||
|
Files.createDirectories(newPath.getParent());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// copy files, nio
|
||||||
|
Files.copy(zis, newPath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
// copy files, classic
|
||||||
|
/*try (FileOutputStream fos = new FileOutputStream(newPath.toFile())) {
|
||||||
|
byte[] buffer = new byte[1024];
|
||||||
|
int len;
|
||||||
|
while ((len = zis.read(buffer)) > 0) {
|
||||||
|
fos.write(buffer, 0, len);
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
}
|
||||||
|
|
||||||
|
zipEntry = zis.getNextEntry();
|
||||||
|
|
||||||
|
}
|
||||||
|
zis.closeEntry();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// protect zip slip attack
|
||||||
|
public static Path zipSlipProtect(ZipEntry zipEntry, Path targetDir)
|
||||||
|
throws IOException {
|
||||||
|
|
||||||
|
// test zip slip vulnerability
|
||||||
|
// Path targetDirResolved = targetDir.resolve("../../" + zipEntry.getName());
|
||||||
|
|
||||||
|
Path targetDirResolved = targetDir.resolve(zipEntry.getName());
|
||||||
|
|
||||||
|
// make sure normalized file still has targetDir as its prefix
|
||||||
|
// else throws exception
|
||||||
|
Path normalizePath = targetDirResolved.normalize();
|
||||||
|
if (!normalizePath.startsWith(targetDir)) {
|
||||||
|
throw new IOException("Bad zip entry: " + zipEntry.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
return normalizePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,8 @@
|
||||||
package HttpCall;
|
package HttpCall;
|
||||||
|
|
||||||
|
import Credentials.PlonkTest;
|
||||||
|
import eu.hsrw.ias.ggd.PlonkHttpPostRequest;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
import java.net.http.HttpClient;
|
import java.net.http.HttpClient;
|
||||||
|
@ -23,6 +26,7 @@ public class HttpPost {
|
||||||
.newBuilder(new URI(baseUrl))
|
.newBuilder(new URI(baseUrl))
|
||||||
.POST(HttpRequest.BodyPublishers.ofString(body))
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
.setHeader("Content-Type", "application/json")
|
.setHeader("Content-Type", "application/json")
|
||||||
|
// .setHeader("Content-Type","application/x-www-form-urlencoded")
|
||||||
.setHeader("Accept", "application/json")
|
.setHeader("Accept", "application/json")
|
||||||
.build();
|
.build();
|
||||||
} catch (URISyntaxException e) {
|
} catch (URISyntaxException e) {
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
package HttpCall;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
public class PlonkHttpGet {
|
||||||
|
public String PlonkHttpGetCall(String baseURL, String token)
|
||||||
|
throws InterruptedException, ExecutionException, TimeoutException {
|
||||||
|
var client = HttpClient
|
||||||
|
.newBuilder()
|
||||||
|
.version(HttpClient.Version.HTTP_1_1)
|
||||||
|
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||||
|
.build();
|
||||||
|
HttpRequest request = null;
|
||||||
|
try {
|
||||||
|
request =
|
||||||
|
HttpRequest
|
||||||
|
.newBuilder(new URI(baseURL))
|
||||||
|
.setHeader("Authorization","Bearer "+ token)
|
||||||
|
.setHeader("Content-Type", "application/json")
|
||||||
|
.build();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
CompletableFuture<HttpResponse<String>> response = client.sendAsync(
|
||||||
|
request,
|
||||||
|
HttpResponse.BodyHandlers.ofString()
|
||||||
|
);
|
||||||
|
String result = response
|
||||||
|
.thenApply(HttpResponse::body)
|
||||||
|
.get(5, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,46 @@
|
||||||
|
package HttpCall;
|
||||||
|
|
||||||
|
|
||||||
|
import Credentials.PlonkTest;
|
||||||
|
import eu.hsrw.ias.ggd.PlonkHttpPostRequest;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.http.HttpClient;
|
||||||
|
import java.net.http.HttpRequest;
|
||||||
|
import java.net.http.HttpResponse;
|
||||||
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
public class PlonkHttpPost {
|
||||||
|
|
||||||
|
public String PlonkHttpCallPost(String baseUrl, String body) throws Exception {
|
||||||
|
var client = HttpClient
|
||||||
|
.newBuilder()
|
||||||
|
.version(HttpClient.Version.HTTP_1_1)
|
||||||
|
.followRedirects(HttpClient.Redirect.ALWAYS)
|
||||||
|
.build();
|
||||||
|
HttpRequest request = null;
|
||||||
|
try {
|
||||||
|
request =
|
||||||
|
HttpRequest
|
||||||
|
.newBuilder(new URI(baseUrl))
|
||||||
|
.POST(HttpRequest.BodyPublishers.ofString(body))
|
||||||
|
.setHeader("Content-Type","application/x-www-form-urlencoded")
|
||||||
|
.setHeader("Accept", "application/json")
|
||||||
|
.build();
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
CompletableFuture<HttpResponse<String>> response = client.sendAsync(
|
||||||
|
request,
|
||||||
|
HttpResponse.BodyHandlers.ofString()
|
||||||
|
);
|
||||||
|
String result = response
|
||||||
|
.thenApply(HttpResponse::body)
|
||||||
|
.get(5, TimeUnit.SECONDS);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -42,7 +42,7 @@ public class ApiCall {
|
||||||
|
|
||||||
ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner();
|
ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner();
|
||||||
ArrayList<String> outputValue =
|
ArrayList<String> outputValue =
|
||||||
(readSensors4Partner.FetchSensor4Box("Germes", token));
|
(readSensors4Partner.FetchSensor4Box("Nica", token));
|
||||||
|
|
||||||
for (int i = 0; i < outputValue.size(); i++) {
|
for (int i = 0; i < outputValue.size(); i++) {
|
||||||
Device device;
|
Device device;
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.util.List;
|
||||||
public class Greenhouse {
|
public class Greenhouse {
|
||||||
|
|
||||||
private String id = "8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
private String id = "8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
private String id2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
private Severity state = Severity.Unknown;
|
private Severity state = Severity.Unknown;
|
||||||
|
|
||||||
public Greenhouse() {
|
public Greenhouse() {
|
||||||
|
@ -16,6 +17,14 @@ public class Greenhouse {
|
||||||
this.devices = devices;
|
this.devices = devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getId2() {
|
||||||
|
return id2;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId2(String id2) {
|
||||||
|
this.id2 = id2;
|
||||||
|
}
|
||||||
|
|
||||||
public void addDevice(Device device) {
|
public void addDevice(Device device) {
|
||||||
this.devices.add(device);
|
this.devices.add(device);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,5 +28,6 @@ public class Isis {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
package eu.hsrw.ias.ggd;
|
package eu.hsrw.ias.ggd;
|
||||||
|
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
|
|
||||||
//Before pushing files to the git run : npx prettier --write "**/*.java"
|
//Before pushing files to the git run : npx prettier --write "**/*.java"
|
||||||
public class MainExe {
|
public class MainExe {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Timer time = new Timer(); // Instantiate Timer Object
|
Timer time = new Timer(); // Instantiate Timer Object
|
||||||
ScheduledTask scheduledTask = new ScheduledTask(); // Instantiate SheduledTask class
|
ScheduledTask scheduledTask = new ScheduledTask(); // Instantiate SheduledTask class
|
||||||
time.schedule(scheduledTask, 0, 1000 * 60 * 1); // Create Repetitively task for every 2 min
|
time.schedule(scheduledTask, 0, 1000 * 60 * 2); // Create Repetitively task for every 2 min
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
package eu.hsrw.ias.ggd;
|
||||||
|
|
||||||
|
import Credentials.PlonkTest;
|
||||||
|
import Credentials.UserCredentials;
|
||||||
|
import Files.ReadExcelFile;
|
||||||
|
import Files.UnZipFile;
|
||||||
|
import HttpCall.PlonkHttpGet;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
|
||||||
|
public class PlonkDataRequest {
|
||||||
|
public static String x() throws Exception {
|
||||||
|
String token;
|
||||||
|
String result;
|
||||||
|
{
|
||||||
|
PlonkTest plonkTest = new PlonkTest();
|
||||||
|
PlonkHttpGet plonkHttpGet = new PlonkHttpGet();
|
||||||
|
String outputToken = PlonkHttpPostRequest.OnCallMethod();
|
||||||
|
JSONObject obj = new JSONObject(outputToken);
|
||||||
|
token = obj.getString("access_token");
|
||||||
|
String urlExtension= plonkTest.getServer()+"/api/pre/ ubersicht/data/Gießen-Düngen%20(Stufen)";
|
||||||
|
result = plonkHttpGet.PlonkHttpGetCall(urlExtension,token);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
//if we want to fetch data from PlonkApi
|
||||||
|
|
||||||
|
// try {
|
||||||
|
// String output = x();
|
||||||
|
// System.out.println(output);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
|
||||||
|
//This part is unziping the excel file from the url
|
||||||
|
UnZipFile unZipFile = new UnZipFile();
|
||||||
|
UserCredentials userCredentials = new UserCredentials();
|
||||||
|
String workPath = userCredentials.getHomeRoot();
|
||||||
|
|
||||||
|
Path source = Paths.get(workPath+"PlonkData.zip");
|
||||||
|
Path target = Paths.get(workPath);
|
||||||
|
ReadExcelFile DT = new ReadExcelFile();
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
unZipFile.unzipFolder(source, target);
|
||||||
|
DT.readExcel();
|
||||||
|
System.out.println("Done");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,30 @@
|
||||||
|
package eu.hsrw.ias.ggd;
|
||||||
|
|
||||||
|
import Credentials.PlonkTest;
|
||||||
|
import HttpCall.HttpPost;
|
||||||
|
import HttpCall.PlonkHttpPost;
|
||||||
|
|
||||||
|
public class PlonkHttpPostRequest {
|
||||||
|
public static String OnCallMethod()
|
||||||
|
throws Exception {
|
||||||
|
PlonkTest plonkTest = new PlonkTest();
|
||||||
|
PlonkHttpPost plonkHttpPost = new PlonkHttpPost();
|
||||||
|
|
||||||
|
//creating the request URL
|
||||||
|
String url = plonkTest.getServer() + "/auth/realms/" + plonkTest.getRealm() + "/protocol/openid-connect/token";
|
||||||
|
//creating the body of the request
|
||||||
|
String data = String.format("grant_type=%s&client_id=%s&username=%s&password=%s&client_secret=%s", plonkTest.getGrantType(), plonkTest.getClientId(), plonkTest.getUsername(), plonkTest.getPassword(), plonkTest.getClientSecret());
|
||||||
|
|
||||||
|
return plonkHttpPost.PlonkHttpCallPost(url, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// public static void main(String[] args) {
|
||||||
|
// try {
|
||||||
|
// String output = OnCallMethod();
|
||||||
|
// System.out.println(output);
|
||||||
|
// } catch (Exception e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
}
|
|
@ -46,4 +46,8 @@ public class SensorData {
|
||||||
this.state = state;
|
this.state = state;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetState() {
|
||||||
|
this.state = Severity.Unknown;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,9 @@ rule "CriticalBattery"
|
||||||
then
|
then
|
||||||
|
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
final String criticalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput);
|
||||||
insert(new Notification("battery", sensorData, Severity.Critical));
|
insert(new Notification("battery", sensorData, Severity.Critical));
|
||||||
|
|
||||||
|
@ -45,82 +46,3 @@ rule "OptimalBattery"
|
||||||
// }
|
// }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// System.out.println(sensorData.getTag()+" "+sensorData.getValue());
|
|
||||||
// System.out.println(device);
|
|
||||||
|
|
||||||
/*String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
|
||||||
HttpPost httpPost = new HttpPost();
|
|
||||||
// System.out.println("Tag: '"+tag+"' has low battery with value: '"+level+"'");
|
|
||||||
final String battery = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical! Low Battery %s \", \"battery\": %s}]}}", fixedIdG1,level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",battery);
|
|
||||||
System.out.println("Low Battery"+level+"in the following sensor"+tag);
|
|
||||||
*/
|
|
||||||
/*HttpPost httpPost = new HttpPost();
|
|
||||||
|
|
||||||
final String finalOutput;
|
|
||||||
boolean critical = false;
|
|
||||||
HashMap<String,Double> test = new HashMap<>();
|
|
||||||
if (tag.equals("fd694041-581e-4c2c-9810-505e62b762e6")){ // This matches 70B3D570500042D7
|
|
||||||
if (level < 7.2 && k.equals("battery") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Low Battery : "+level+"! Please swap the battery soon of the following sensor:"+tag,"Low Battery Level",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String battery = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical! Low Battery %s \", \"battery\": %s}]}}", fixedIdG1,level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",battery);
|
|
||||||
System.out.println("Low Battery"+level+"in the following sensor"+tag);
|
|
||||||
critical = true;
|
|
||||||
test.put("battery",level);
|
|
||||||
}
|
|
||||||
if (level > 80 && k.equals("temperature") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"High Temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"Temperature",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String temperature = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical!High Temperature %s \", \"temperature\": %s}]}}", fixedIdG1,level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",temperature);
|
|
||||||
System.out.println("High Temp");
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level > 14.5 && k.equals("precipitation") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"High water level : "+level+" in the following sensor"+tag,"Precipitation",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String precipitation = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High water level %s\", \"precipitation\": %s}]}}", fixedIdG1, level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",precipitation);
|
|
||||||
System.out.println("High water level"+level +" in the following sensor:"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level < 22 && k.equals("soilTemperature") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Low soil temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"soil Temperature",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String soilTemperature = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Low soil temperature %s in the following sensor: %s \", \"soilTemperature\": %s}]}}", fixedIdG1,level, tag,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",soilTemperature);
|
|
||||||
System.out.println("Low soil Temperature"+level+" in the following sensor "+tag);
|
|
||||||
critical = true;
|
|
||||||
test.put("soilTemperature",level);
|
|
||||||
}
|
|
||||||
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 soilMoisture = 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",soilMoisture);
|
|
||||||
System.out.println("Soil is dry"+level+" in the following sensor"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level <= 0.57 && level >= 0.11 && k.equals("soilConductivity") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Optimal EC levels in the soil : "+level+" in the following sensor"+tag,"Soil Conductivity",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String soilConductivity = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal EC levels in the soil %s\", \"soilConductivity\": %s}]}}", fixedIdG1, level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",soilConductivity);
|
|
||||||
System.out.println("Optimal EC levels in the soil"+level +" in the following sensor:"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level > 20 && k.equals("dielectricPermittivity") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"High dielectricPermittivity : "+level+" in the following sensor"+tag,"dielectricPermittivity",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String dielectricPermittivity = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High dielectricPermittivity %s\", \"dielectricPermittivity\": %s}]}}", fixedIdG1, level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivity);
|
|
||||||
System.out.println("High dielectricPermittivity"+level +" in the following sensor:"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
// if(critical == true){
|
|
||||||
// finalOutput
|
|
||||||
// }
|
|
||||||
finalOutput = String.format("{\"id\":\"70B3D570500042D7-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the device 1 is critical\",}]}}");
|
|
||||||
System.out.println(finalOutput);
|
|
||||||
}*/
|
|
|
@ -12,11 +12,12 @@ rule "CriticalPrecipitation"
|
||||||
device: Device(sensorDatas: sensorData)
|
device: Device(sensorDatas: sensorData)
|
||||||
sensorData: SensorData(tag == "precipitation", value > 15.5) from sensorDatas
|
sensorData: SensorData(tag == "precipitation", value > 15.5) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
// String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
HttpPost httpPost = new HttpPost();
|
// String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
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 httpPost = new HttpPost();
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalPrecipitationOutput);
|
// final String criticalPrecipitationOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Precipitation %s in the following sensor %s \", \"precipitation\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
insert(new Notification("precipitation", sensorData, Severity.Warning));
|
// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalPrecipitationOutput);
|
||||||
|
// insert(new Notification("precipitation", sensorData, Severity.Warning));
|
||||||
|
|
||||||
// modify(sensorData){
|
// modify(sensorData){
|
||||||
// setState(Severity.Critical)
|
// setState(Severity.Critical)
|
||||||
|
|
|
@ -12,9 +12,10 @@ rule "CriticalSoilMoisture"
|
||||||
device: Device(sensorDatas: sensorData)
|
device: Device(sensorDatas: sensorData)
|
||||||
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
|
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
// String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";//Germes
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
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);
|
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());
|
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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
|
||||||
|
@ -26,9 +27,9 @@ rule "OptimalSoilMoisture"
|
||||||
device: Device(sensorDatas: sensorData)
|
device: Device(sensorDatas: sensorData)
|
||||||
sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas
|
sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="e5ec9f15-f214-455d-9f02-3c134c770dc1";
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalSoilMoistureOutput);
|
||||||
insert(new Notification("soilMoisture", sensorData, Severity.Optimal));
|
insert(new Notification("soilMoisture", sensorData, Severity.Optimal));
|
||||||
//device.setState(Severity.Optimal);
|
//device.setState(Severity.Optimal);
|
||||||
|
|
|
@ -13,8 +13,9 @@ rule "CriticalTemperature"
|
||||||
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
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
final String criticalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalTemperatureOutput);
|
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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
|
||||||
|
@ -39,9 +40,5 @@ rule "OptimalTemperature"
|
||||||
insert(new Notification("temperature", sensorData, Severity.Optimal));
|
insert(new Notification("temperature", sensorData, Severity.Optimal));
|
||||||
System.out.println("Optimal");
|
System.out.println("Optimal");
|
||||||
|
|
||||||
// modify(sensorData){
|
|
||||||
// setState(Severity.Optimal)
|
|
||||||
// }
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,9 @@ rule "DielectricPermittivity"
|
||||||
sensorData: SensorData(tag == "dielectricPermittivity", value > 20.0) from sensorDatas
|
sensorData: SensorData(tag == "dielectricPermittivity", value > 20.0) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
final String dielectricPermittivityOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical dielectricPermittivity %s in the following sensor %s \", \"dielectricPermittivityOutput\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput);
|
||||||
insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning));
|
insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning));
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package rules;
|
||||||
|
dialect "mvel"
|
||||||
|
|
||||||
|
rule "FinalChecker"
|
||||||
|
when
|
||||||
|
then
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ when
|
||||||
|
|
||||||
then
|
then
|
||||||
HttpPost httpPost = new HttpPost();
|
HttpPost httpPost = new HttpPost();
|
||||||
final String optimalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is optimal\"}]}}");
|
final String optimalGreenhouse = String.format("{\"id\":\"nica-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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalGreenhouse);
|
||||||
System.out.println("Green House optimal, because of: '"+warning.getType()+"'");
|
System.out.println("Green House optimal, because of: '"+warning.getType()+"'");
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,14 @@ import eu.hsrw.ias.ggd.Notification;
|
||||||
import eu.hsrw.ias.ggd.Severity
|
import eu.hsrw.ias.ggd.Severity
|
||||||
import HttpCall.HttpPost;
|
import HttpCall.HttpPost;
|
||||||
|
|
||||||
//rule "Green House Critical"
|
rule "Green House Critical"
|
||||||
//when
|
when
|
||||||
// warning: Notification(severity > Severity.Warning)
|
warning: Notification(severity > Severity.Warning)
|
||||||
//then
|
then
|
||||||
// HttpPost httpPost = new HttpPost();
|
HttpPost httpPost = new HttpPost();
|
||||||
// final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}");
|
final String criticalGreenhouse = String.format("{\"id\":\"nica-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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse);
|
||||||
// System.out.println(criticalGreenhouse);
|
System.out.println(criticalGreenhouse);
|
||||||
// System.out.println("Green House critical, because of: '"+warning.getType()+"'");
|
System.out.println("Green House critical, because of: '"+warning.getType()+"'");
|
||||||
//
|
|
||||||
//end
|
end
|
|
@ -16,8 +16,9 @@ rule "CriticalBattery"
|
||||||
then
|
then
|
||||||
|
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
final String criticalBatteryOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Battery %s in the following sensor %s \", \"battery\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalBatteryOutput);
|
||||||
insert(new Notification("battery", sensorData, Severity.Critical));
|
insert(new Notification("battery", sensorData, Severity.Critical));
|
||||||
|
|
||||||
|
@ -45,82 +46,3 @@ rule "OptimalBattery"
|
||||||
// }
|
// }
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// System.out.println(sensorData.getTag()+" "+sensorData.getValue());
|
|
||||||
// System.out.println(device);
|
|
||||||
|
|
||||||
/*String fixedIdG1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
|
||||||
HttpPost httpPost = new HttpPost();
|
|
||||||
// System.out.println("Tag: '"+tag+"' has low battery with value: '"+level+"'");
|
|
||||||
final String battery = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical! Low Battery %s \", \"battery\": %s}]}}", fixedIdG1,level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",battery);
|
|
||||||
System.out.println("Low Battery"+level+"in the following sensor"+tag);
|
|
||||||
*/
|
|
||||||
/*HttpPost httpPost = new HttpPost();
|
|
||||||
|
|
||||||
final String finalOutput;
|
|
||||||
boolean critical = false;
|
|
||||||
HashMap<String,Double> test = new HashMap<>();
|
|
||||||
if (tag.equals("fd694041-581e-4c2c-9810-505e62b762e6")){ // This matches 70B3D570500042D7
|
|
||||||
if (level < 7.2 && k.equals("battery") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Low Battery : "+level+"! Please swap the battery soon of the following sensor:"+tag,"Low Battery Level",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String battery = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical! Low Battery %s \", \"battery\": %s}]}}", fixedIdG1,level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",battery);
|
|
||||||
System.out.println("Low Battery"+level+"in the following sensor"+tag);
|
|
||||||
critical = true;
|
|
||||||
test.put("battery",level);
|
|
||||||
}
|
|
||||||
if (level > 80 && k.equals("temperature") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"High Temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"Temperature",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String temperature = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical!High Temperature %s \", \"temperature\": %s}]}}", fixedIdG1,level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",temperature);
|
|
||||||
System.out.println("High Temp");
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level > 14.5 && k.equals("precipitation") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"High water level : "+level+" in the following sensor"+tag,"Precipitation",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String precipitation = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High water level %s\", \"precipitation\": %s}]}}", fixedIdG1, level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",precipitation);
|
|
||||||
System.out.println("High water level"+level +" in the following sensor:"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level < 22 && k.equals("soilTemperature") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Low soil temperature : "+level+" in the following sensor: "+tag+"in the following device id: "+id,"soil Temperature",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String soilTemperature = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Low soil temperature %s in the following sensor: %s \", \"soilTemperature\": %s}]}}", fixedIdG1,level, tag,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",soilTemperature);
|
|
||||||
System.out.println("Low soil Temperature"+level+" in the following sensor "+tag);
|
|
||||||
critical = true;
|
|
||||||
test.put("soilTemperature",level);
|
|
||||||
}
|
|
||||||
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 soilMoisture = 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",soilMoisture);
|
|
||||||
System.out.println("Soil is dry"+level+" in the following sensor"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level <= 0.57 && level >= 0.11 && k.equals("soilConductivity") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"Optimal EC levels in the soil : "+level+" in the following sensor"+tag,"Soil Conductivity",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String soilConductivity = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Optimal EC levels in the soil %s\", \"soilConductivity\": %s}]}}", fixedIdG1, level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",soilConductivity);
|
|
||||||
System.out.println("Optimal EC levels in the soil"+level +" in the following sensor:"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
if (level > 20 && k.equals("dielectricPermittivity") ) {
|
|
||||||
JOptionPane.showMessageDialog(null,"High dielectricPermittivity : "+level+" in the following sensor"+tag,"dielectricPermittivity",JOptionPane.INFORMATION_MESSAGE);
|
|
||||||
final String dielectricPermittivity = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"High dielectricPermittivity %s\", \"dielectricPermittivity\": %s}]}}", fixedIdG1, level,level);
|
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivity);
|
|
||||||
System.out.println("High dielectricPermittivity"+level +" in the following sensor:"+tag);
|
|
||||||
critical = true;
|
|
||||||
}
|
|
||||||
// if(critical == true){
|
|
||||||
// finalOutput
|
|
||||||
// }
|
|
||||||
finalOutput = String.format("{\"id\":\"70B3D570500042D7-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the device 1 is critical\",}]}}");
|
|
||||||
System.out.println(finalOutput);
|
|
||||||
}*/
|
|
|
@ -12,11 +12,12 @@ rule "CriticalPrecipitation"
|
||||||
device: Device(sensorDatas: sensorData)
|
device: Device(sensorDatas: sensorData)
|
||||||
sensorData: SensorData(tag == "precipitation", value > 15.5) from sensorDatas
|
sensorData: SensorData(tag == "precipitation", value > 15.5) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
// String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
HttpPost httpPost = new HttpPost();
|
// String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
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 httpPost = new HttpPost();
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalPrecipitationOutput);
|
// final String criticalPrecipitationOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Precipitation %s in the following sensor %s \", \"precipitation\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
insert(new Notification("precipitation", sensorData, Severity.Warning));
|
// httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalPrecipitationOutput);
|
||||||
|
// insert(new Notification("precipitation", sensorData, Severity.Warning));
|
||||||
|
|
||||||
// modify(sensorData){
|
// modify(sensorData){
|
||||||
// setState(Severity.Critical)
|
// setState(Severity.Critical)
|
||||||
|
|
|
@ -12,9 +12,10 @@ rule "CriticalSoilMoisture"
|
||||||
device: Device(sensorDatas: sensorData)
|
device: Device(sensorDatas: sensorData)
|
||||||
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
|
sensorData: SensorData(tag == "soilMoisture", value < 28.0) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
// String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";//Germes
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
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);
|
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());
|
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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
|
||||||
|
@ -31,9 +32,9 @@ rule "OptimalSoilMoisture"
|
||||||
device: Device(sensorDatas: sensorData)
|
device: Device(sensorDatas: sensorData)
|
||||||
sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas
|
sensorData: SensorData(tag == "soilMoisture", value > 28.0) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="e5ec9f15-f214-455d-9f02-3c134c770dc1";
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalSoilMoistureOutput);
|
||||||
insert(new Notification("soilMoisture", sensorData, Severity.Optimal));
|
insert(new Notification("soilMoisture", sensorData, Severity.Optimal));
|
||||||
//device.setState(Severity.Optimal);
|
//device.setState(Severity.Optimal);
|
||||||
|
|
|
@ -13,8 +13,9 @@ rule "CriticalTemperature"
|
||||||
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
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
final String criticalTemperatureOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical Temperature %s in the following device %s \", \"temperature\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalTemperatureOutput);
|
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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",deviceCritical);
|
||||||
|
@ -39,9 +40,5 @@ rule "OptimalTemperature"
|
||||||
insert(new Notification("temperature", sensorData, Severity.Optimal));
|
insert(new Notification("temperature", sensorData, Severity.Optimal));
|
||||||
System.out.println("Optimal");
|
System.out.println("Optimal");
|
||||||
|
|
||||||
// modify(sensorData){
|
|
||||||
// setState(Severity.Optimal)
|
|
||||||
// }
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -13,8 +13,9 @@ rule "DielectricPermittivity"
|
||||||
sensorData: SensorData(tag == "dielectricPermittivity", value > 20.0) from sensorDatas
|
sensorData: SensorData(tag == "dielectricPermittivity", value > 20.0) from sensorDatas
|
||||||
then
|
then
|
||||||
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
String greenhouse1="8bdbe6ae-eafb-4e99-bb01-db8784dd9633";
|
||||||
|
String greenhouse2="e5ec9f15-f214-455d-9f02-3c134c770dc1";//Nica
|
||||||
HttpPost httpPost = new HttpPost();
|
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());
|
final String dielectricPermittivityOutput = String.format("{\"id\":\"%s\",\"data\":{\"measured\":[{ \"status\": \"Critical dielectricPermittivity %s in the following sensor %s \", \"dielectricPermittivityOutput\": %s}]}}",greenhouse2, sensorData.getValue(),sensorData.getTag(),sensorData.getValue());
|
||||||
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",dielectricPermittivityOutput);
|
||||||
insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning));
|
insert(new Notification("dielectricPermittivity", sensorData, Severity.Warning));
|
||||||
end
|
end
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
package rules;
|
||||||
|
dialect "mvel"
|
||||||
|
|
||||||
|
rule "FinalChecker"
|
||||||
|
when
|
||||||
|
then
|
||||||
|
end
|
|
@ -9,7 +9,7 @@ when
|
||||||
|
|
||||||
then
|
then
|
||||||
HttpPost httpPost = new HttpPost();
|
HttpPost httpPost = new HttpPost();
|
||||||
final String optimalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is optimal\"}]}}");
|
final String optimalGreenhouse = String.format("{\"id\":\"nica-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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",optimalGreenhouse);
|
||||||
System.out.println("Green House optimal, because of: '"+warning.getType()+"'");
|
System.out.println("Green House optimal, because of: '"+warning.getType()+"'");
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,14 +2,14 @@ import eu.hsrw.ias.ggd.Notification;
|
||||||
import eu.hsrw.ias.ggd.Severity
|
import eu.hsrw.ias.ggd.Severity
|
||||||
import HttpCall.HttpPost;
|
import HttpCall.HttpPost;
|
||||||
|
|
||||||
//rule "Green House Critical"
|
rule "Green House Critical"
|
||||||
//when
|
when
|
||||||
// warning: Notification(severity > Severity.Warning)
|
warning: Notification(severity > Severity.Warning)
|
||||||
//then
|
then
|
||||||
// HttpPost httpPost = new HttpPost();
|
HttpPost httpPost = new HttpPost();
|
||||||
// final String criticalGreenhouse = String.format("{\"id\":\"germes-greenhouse-status\",\"data\":{\"measured\":[{ \"status\": \"The status of the greenhouse is critical\"}]}}");
|
final String criticalGreenhouse = String.format("{\"id\":\"nica-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);
|
httpPost.HttpCallPost("http://connector.dev.whysor.com/default/insert?access_token=3hosOhAeh4k0XmcuAMQGfYldvTuQDvtAj2PJJ4irKPBefD5Ijij6gnUkLtVLd4fW",criticalGreenhouse);
|
||||||
// System.out.println(criticalGreenhouse);
|
System.out.println(criticalGreenhouse);
|
||||||
// System.out.println("Green House critical, because of: '"+warning.getType()+"'");
|
System.out.println("Green House critical, because of: '"+warning.getType()+"'");
|
||||||
//
|
|
||||||
//end
|
end
|
Loading…
Reference in New Issue