46 lines
1.4 KiB
Java
46 lines
1.4 KiB
Java
import org.json.simple.JSONObject;
|
|
import org.json.simple.parser.JSONParser;
|
|
import org.json.simple.parser.ParseException;
|
|
|
|
import java.io.BufferedWriter;
|
|
import java.io.File;
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
import java.util.ArrayList;
|
|
import java.util.TimerTask;
|
|
import java.util.Date;
|
|
import java.util.concurrent.ExecutionException;
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
// Create a class extends with TimerTask
|
|
public class ScheduledTask extends TimerTask {
|
|
|
|
Date now; // to display current time
|
|
|
|
// Add your task here
|
|
public void run() {
|
|
// Display current time
|
|
now = new Date(); // initialize date
|
|
System.out.println("Time is :" + now);
|
|
String outputDevices = null;
|
|
String devicesExtension = "devices";
|
|
String sensorExtension = "sensors"; //read and readMultiple
|
|
try {
|
|
outputDevices = ApiCall.FetchDataFromApi(devicesExtension);
|
|
// outputDevices = ApiCall.FetchDataFromApi(sensorExtension);
|
|
|
|
} catch (InterruptedException e) {
|
|
e.printStackTrace();
|
|
} catch (ExecutionException e) {
|
|
e.printStackTrace();
|
|
} catch (TimeoutException e) {
|
|
e.printStackTrace();
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
System.out.println("Output :" + outputDevices); // Display current output
|
|
|
|
|
|
|
|
}
|
|
} |