diff --git a/src/java/com/wasteinformationserver/Dateget.java b/src/java/com/wasteinformationserver/Dateget.java index 6ab8d4e..ee83d14 100644 --- a/src/java/com/wasteinformationserver/Dateget.java +++ b/src/java/com/wasteinformationserver/Dateget.java @@ -1,3 +1,6 @@ +/** + * dead code... + */ package com.wasteinformationserver; import com.wasteinformationserver.basicutils.Log; diff --git a/src/java/com/wasteinformationserver/main.java b/src/java/com/wasteinformationserver/main.java index 0e168e9..ffcf1ca 100644 --- a/src/java/com/wasteinformationserver/main.java +++ b/src/java/com/wasteinformationserver/main.java @@ -10,11 +10,10 @@ import java.io.IOException; public class main { public static void main(String[] args) { - Log.setLevel(Log.DEBUG); - Log.info("startup of WasteInformationServer"); + Info.init(); - Log.info("mem: " + Runtime.getRuntime().totalMemory()); + Log.info("startup of WasteInformationServer"); Runtime.getRuntime().addShutdownHook(new Thread(() -> { try { @@ -27,7 +26,6 @@ public class main { } })); - Info.init(); Log.info("Server version: " + Info.getVersion()); Log.debug("Build date: " + Info.getBuilddate()); @@ -55,7 +53,5 @@ public class main { } catch (Exception e) { Log.error("An error occured in the class mqtt"); } - - Log.info("mem: " + Runtime.getRuntime().totalMemory()); } } \ No newline at end of file diff --git a/src/java/com/wasteinformationserver/mqtt/MqttService.java b/src/java/com/wasteinformationserver/mqtt/MqttService.java index 7c36053..dabd55a 100644 --- a/src/java/com/wasteinformationserver/mqtt/MqttService.java +++ b/src/java/com/wasteinformationserver/mqtt/MqttService.java @@ -100,7 +100,7 @@ public class MqttService { if (timestamp == timestampnow || timestamp == timestampnow + 86400000) { // 86400000 == one day // valid time - // TODO: 12.01.20 read right waste type from db and replace below + // TODO: 12.01.20 read right waste type from db and replace below tramsmitMessage(deviceid + "," + "Plastic" + "," + 1); Log.debug("valid time"); return; diff --git a/src/java/com/wasteinformationserver/website/Webserver.java b/src/java/com/wasteinformationserver/website/Webserver.java index 79e62e8..66a3bc2 100644 --- a/src/java/com/wasteinformationserver/website/Webserver.java +++ b/src/java/com/wasteinformationserver/website/Webserver.java @@ -2,10 +2,7 @@ package com.wasteinformationserver.website; import com.sun.net.httpserver.HttpServer; import com.wasteinformationserver.basicutils.Log; -import com.wasteinformationserver.website.datarequests.AdminRequests; -import com.wasteinformationserver.website.datarequests.DataRequest; -import com.wasteinformationserver.website.datarequests.NewDateRequest; -import com.wasteinformationserver.website.datarequests.RegisterRequest; +import com.wasteinformationserver.website.datarequests.*; import com.wasteinformationserver.website.datarequests.login.CheckLoginState; import com.wasteinformationserver.website.datarequests.login.LoginRequest; @@ -29,6 +26,7 @@ public class Webserver { server.createContext("/senddata/wastedata", new DataRequest()); server.createContext("/senddata/admindata", new AdminRequests()); server.createContext("/senddata/newdate", new NewDateRequest()); + server.createContext("/senddata/Devicedata", new DeviceRequest()); server.setExecutor(null); // creates a default executor server.start(); diff --git a/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java b/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java new file mode 100644 index 0000000..c12139d --- /dev/null +++ b/src/java/com/wasteinformationserver/website/datarequests/DeviceRequest.java @@ -0,0 +1,43 @@ +package com.wasteinformationserver.website.datarequests; + +import com.wasteinformationserver.db.JDCB; +import com.wasteinformationserver.website.basicrequest.PostRequest; + +import java.io.IOException; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.HashMap; + +public class DeviceRequest extends PostRequest { + @Override + public String request(HashMap params) { + + JDCB jdcb = null; + try { + jdcb = JDCB.getInstance(); + } catch (IOException e) { + e.printStackTrace(); + } + + switch (params.get("action")) { + case "getdevices": + ResultSet set = jdcb.executeQuery("SELECT * from devices"); + StringBuilder sb = new StringBuilder("{\"data\":["); + try { + while (set.next()) { + sb.append("{\"name\":\"" + set.getString("devicename") + "\"}"); + if (!set.isLast()) { + sb.append(","); + } + } + sb.append("]}"); + return sb.toString(); + } catch (SQLException e) { + e.printStackTrace(); + } + + break; + } + return null; + } +} diff --git a/src/resources/wwwroot/device.html b/src/resources/wwwroot/device.html index 835dd47..531174c 100644 --- a/src/resources/wwwroot/device.html +++ b/src/resources/wwwroot/device.html @@ -186,21 +186,35 @@ - + + + - - + + + + + + + + + + + + - + + + - - diff --git a/src/resources/wwwroot/js/device.js b/src/resources/wwwroot/js/device.js index 5c700d1..f6ae7ef 100644 --- a/src/resources/wwwroot/js/device.js +++ b/src/resources/wwwroot/js/device.js @@ -1,37 +1,8 @@ $(document).ready(function () { - $('#btn-newdevice').click(function (e) { - e.preventDefault(); - Swal.showLoading({ - title: 'No connection to Database', - html: 'Setup DB here --> click.', - }); + $.post('/senddata/Devicedata', 'action=getdevices', function (data) { - // Swal.fire({ - // type: "error", - // title: 'No connection to Database', - // html: 'Setup DB here --> click.', - // onBeforeOpen: () => { - // Swal.showLoading() - // }, - // }).then((result) => { - // console.log('Popup closed. ') - // - // }); - - - // $.post('/senddata/loginget', 'username=' + username + '&password=' + password, function (data) { - // - // console.log(data); - // if (data.status == "nodbconn"){ - // - // } - // if (data.accept == true) { - // console.log("successfully logged in!"); - // document.cookie = "username=" + username; - // window.location = 'dashboard.html'; - // } - // }, 'json'); - }); + console.log(data); + }, 'json'); });
CityDevice IDDevicenameDevicelocation ZoneWaste TypeDate X
42new Device + +
42lukis anzigeshtl steyrSteyr/2/Plasticdel
CityDevice IDDevicenameDevicelocation ZoneWaste TypeDate X