ADD: New rules for the rule Engine

FIX: ApiCall.java
REWORK : JSON_Unpack
This commit is contained in:
2021-11-18 13:22:12 +01:00
parent 1e0ec23d08
commit 141d474ef3
21 changed files with 241 additions and 87 deletions

View File

@@ -27,6 +27,8 @@ public class ApiCall {
WriteFile writingIntoFile = new WriteFile();
Date now; // to display current time
now = new Date();
HashMap<String,
SensorData> finalOutput = new HashMap();
if (token.equals(oldId)) {
//do nothing
} else {
@@ -43,24 +45,18 @@ public class ApiCall {
}
ReadSensors4Partner readSensors4Partner = new ReadSensors4Partner();
ArrayList<String> outputValue = (readSensors4Partner.FetchSensor4Box("Germes", token));
String workingArray = String.valueOf(outputValue).replace("[{", "{").replace("}]", "}");
JSONArray jsonArray = new JSONArray(workingArray);
HashMap<String,
SensorData> finalOutput = new HashMap();
for (int j = 0; j < jsonArray.length(); j++) {
JSONObject jsonobject = jsonArray.getJSONObject(j);
double value = jsonobject.getDouble("value");
String sensorTag = jsonobject.getString("sensorTag");
String sensorId = jsonobject.getString("sensorId");
finalOutput.put(sensorTag, new SensorData(sensorId, value));
for(int i=0;i<outputValue.size();i++){
JSONArray jsonArray = new JSONArray(outputValue.get(i));
for(int j=0; j<jsonArray.length(); j++){
JSONObject jsonobject = jsonArray.getJSONObject(j);
double value = jsonobject.getDouble("value");
String sensorTag = jsonobject.getString("sensorTag");
String sensorId = jsonobject.getString("sensorId");
String deviceId = jsonobject.getString("deviceId");
finalOutput.put(sensorTag, new SensorData(deviceId, value,sensorId));
}
}
return finalOutput;
}

View File

@@ -7,7 +7,7 @@ public class MainExe {
Timer time = new Timer(); // Instantiate Timer Object
ScheduledTask scheduledTask = new ScheduledTask(); // Instantiate SheduledTask class
time.schedule(scheduledTask, 0, 1000 * 60 * 5 ); // Create Repetitively task for every 2 min
time.schedule(scheduledTask, 0, 1000 * 60 * 1 ); // Create Repetitively task for every 2 min
}
}

View File

@@ -10,9 +10,10 @@ public class SecurityToken {
//CONFIG PARAMETERS:
//BEGIN------------CONFIG PARAMETERS BELOW TO YOUR ENVIRONMENT---------------------------------------
String baseURL = "https://api.whysor.com/users/login";
final String body = String.format("{\"email\": \"%s\", \"password\": \"%s\", \"domain\": \"my.yookr.org\"}", username, password);
String devURL = "https://api.dev.whysor.com/users/login";
final String body = String.format("{\"email\": \"%s\", \"password\": \"%s\", \"domain\": \"my.dev.yookr.org\"}", username, password);
HttpPost httpMethodPost = new HttpPost();
return httpMethodPost.HttpCallPost(baseURL, body);
return httpMethodPost.HttpCallPost(devURL, body);
}
}

View File

@@ -4,10 +4,12 @@ public class SensorData {
private String sensorId;
private double value;
private String deviceId;
public SensorData(String sensorId, double value) {
public SensorData(String sensorId, double value,String deviceId) {
this.sensorId = sensorId;
this.value = value;
this.deviceId = deviceId;
}
public String getSensorTag() {
@@ -25,4 +27,9 @@ public class SensorData {
public void setValue(double value) {
this.value = value;
}
public String getDeviceId() {return deviceId;}
public void setDeviceId(String deviceTag){ this.deviceId = deviceTag;
}
}