mqtt improvements

new device page
This commit is contained in:
lukas-heiligenbrunner 2020-01-10 16:38:18 +01:00
parent c44a0dd9ec
commit 0518c1c809
9 changed files with 381 additions and 69 deletions

View File

@ -4,7 +4,7 @@
<component name="JavaScriptSettings"> <component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" /> <option name="languageLevel" value="ES6" />
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_13" default="true" project-jdk-name="13" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_11" default="true" project-jdk-name="11" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" /> <output url="file://$PROJECT_DIR$/out" />
</component> </component>
</project> </project>

View File

@ -5,7 +5,7 @@ plugins {
} }
group 'com.wasteinformationserver' group 'com.wasteinformationserver'
version '0.2-Beta' version '0.2.1-Beta'
sourceCompatibility = 1.8 sourceCompatibility = 1.8

View File

@ -14,6 +14,7 @@ public class main {
Log.setLevel(Log.INFO); Log.setLevel(Log.INFO);
Log.info("startup of WasteInformationServer"); Log.info("startup of WasteInformationServer");
Log.info("mem: "+Runtime.getRuntime().totalMemory());
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try { try {
@ -56,5 +57,7 @@ public class main {
} catch (Exception e) { } catch (Exception e) {
Log.error("An error occured in the class mqtt"); Log.error("An error occured in the class mqtt");
} }
Log.info("mem: "+Runtime.getRuntime().totalMemory());
} }
} }

View File

@ -27,7 +27,7 @@ public class mqtt {
public void notifymessage() { public void notifymessage() {
try { try {
client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample"); client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample42");
MqttConnectOptions connOpts = new MqttConnectOptions(); MqttConnectOptions connOpts = new MqttConnectOptions();
connOpts.setCleanSession(true); connOpts.setCleanSession(true);
client.connect(connOpts); client.connect(connOpts);
@ -39,6 +39,7 @@ public class mqtt {
mr.addMessageReceivedListener(new ActionListener() { mr.addMessageReceivedListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
Log.debug("received message");
String[] split = e.getActionCommand().split(","); String[] split = e.getActionCommand().split(",");
String wastetyp = getTyp(Integer.parseInt(split[2])); String wastetyp = getTyp(Integer.parseInt(split[2]));
getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + wastetyp + "' AND cities.zone=" + split[3] + ")", wastetyp, Integer.parseInt(split[0])); getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + wastetyp + "' AND cities.zone=" + split[3] + ")", wastetyp, Integer.parseInt(split[0]));
@ -63,6 +64,12 @@ public class mqtt {
ResultSet result = Database.executeQuery(message); ResultSet result = Database.executeQuery(message);
try { try {
result.last();
if (result.getFetchSize() == 0){
//if not found in db --> send zero
transmitmessageAbfallart(clientidentify + "," + wastenumber + "," + 0);
}
result.first();
while (result.next()) { while (result.next()) {
String newDate = getDateDatabase(String.valueOf(result.getString("pickupdate"))); String newDate = getDateDatabase(String.valueOf(result.getString("pickupdate")));
String currentDate = getcurrentDate(); String currentDate = getcurrentDate();
@ -81,7 +88,7 @@ public class mqtt {
private void transmitmessageAbfallart(String temp) { private void transmitmessageAbfallart(String temp) {
Log.debug("sending message >>>"+temp);
mqtttransmitter mt = new mqtttransmitter(client); mqtttransmitter mt = new mqtttransmitter(client);
Log.debug(temp); Log.debug(temp);
mt.sendmessage(temp); mt.sendmessage(temp);

View File

@ -29,6 +29,7 @@ public class mqttreceiver {
@Override @Override
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception { public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
message = new String(mqttMessage.getPayload()); message = new String(mqttMessage.getPayload());
Log.info("received Request from PCB");
notifylisteners(message); notifylisteners(message);
} }

View File

@ -17,9 +17,9 @@ import java.net.InetSocketAddress;
public class Webserver { public class Webserver {
public void startserver() { public void startserver() {
Log.info("starting Webserver"); Log.info("starting Webserver");
HttpServer server = null;
try { try {
server = HttpServer.create(new InetSocketAddress(8000), 0); HttpServer server = HttpServer.create(new InetSocketAddress(8000), 0);
server.createContext("/", new MainPage()); server.createContext("/", new MainPage());
@ -33,72 +33,10 @@ public class Webserver {
server.setExecutor(null); // creates a default executor server.setExecutor(null); // creates a default executor
server.start(); server.start();
Log.info("Server available at http://127.0.0.1:8000 now"); Log.info("Server available at http://127.0.0.1:8000 now");
}catch (BindException e){ } catch (BindException e) {
Log.criticalerror("The Port 8000 is already in use!"); Log.criticalerror("The Port 8000 is already in use!");
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
/*
try {
server = HttpsServer.create(new InetSocketAddress(8000), 0);
// initialise the HTTPS server
SSLContext sslContext = SSLContext.getInstance("TLS");
// initialise the keystore
char[] password = "password".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
FileInputStream fis = new FileInputStream("testkey.jks");
ks.load(fis, password);
// setup the key manager factory
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, password);
// setup the trust manager factory
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
// setup the HTTPS context and parameters
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
server.setHttpsConfigurator(new HttpsConfigurator(sslContext) {
public void configure(HttpsParameters params) {
try {
// initialise the SSL context
SSLContext context = getSSLContext();
SSLEngine engine = context.createSSLEngine();
params.setNeedClientAuth(false);
params.setCipherSuites(engine.getEnabledCipherSuites());
params.setProtocols(engine.getEnabledProtocols());
// Set the SSL parameters
SSLParameters sslParameters = context.getSupportedSSLParameters();
params.setSSLParameters(sslParameters);
} catch (Exception ex) {
System.out.println("Failed to create HTTPS port");
}
}
});
} catch (IOException e) {
e.printStackTrace();
} catch (CertificateException e) {
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
e.printStackTrace();
} catch (KeyStoreException e) {
e.printStackTrace();
} catch (KeyManagementException e) {
e.printStackTrace();
}
*/
} }
} }

View File

@ -98,6 +98,15 @@
</p> </p>
</a> </a>
</li> </li>
<li id="devicepanel" class="nav-item">
<a href="device.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Devices
</p>
</a>
</li>
</ul> </ul>
</nav> </nav>
<!-- /.sidebar-menu --> <!-- /.sidebar-menu -->

View File

@ -0,0 +1,317 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>WasteInformation Server</title>
<!-- Tell the browser to be responsive to screen width -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Font Awesome -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/fontawesome-free/css/all.min.css">
<!-- Ionicons -->
<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
<!-- DataTables -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/datatables-bs4/css/dataTables.bootstrap4.css">
<!-- Tempusdominus Bbootstrap 4 -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/tempusdominus-bootstrap-4/css/tempusdominus-bootstrap-4.min.css">
<!-- iCheck -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/icheck-bootstrap/icheck-bootstrap.min.css">
<!-- JQVMap -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/jqvmap/jqvmap.min.css">
<!-- Theme style -->
<link rel="stylesheet" href="lib/AdminLTE/dist/css/adminlte.min.css">
<!-- overlayScrollbars -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/overlayScrollbars/css/OverlayScrollbars.min.css">
<!-- Daterange picker -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/daterangepicker/daterangepicker.css">
<!-- summernote -->
<link rel="stylesheet" href="lib/AdminLTE/plugins/summernote/summernote-bs4.css">
<!-- Google Font: Source Sans Pro -->
<link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700" rel="stylesheet">
<!-- Bootstrap Date-Picker Plugin -->
<link rel="stylesheet"
href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/css/bootstrap-datepicker3.css"/>
<!-- <link rel="stylesheet" type="text/css" href="css/user.css">-->
<link rel="stylesheet" type="text/css" href="css/general.css">
</head>
<body class="hold-transition sidebar-mini layout-fixed">
<div class="wrapper">
<!-- Main Sidebar Container -->
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<!-- Brand Logo -->
<a href="dashboard.html" class="brand-link">
<img src="lib/AdminLTE/dist/img/AdminLTELogo.png" alt="AdminLTE Logo"
class="brand-image img-circle elevation-3"
style="opacity: .8">
<span class="brand-text font-weight-light">Waste Control</span>
</a>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<!-- <img src="lib/AdminLTE/dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image"> -->
<i class="nav-icon fas fa-user img-circle elevation-2" style="color:white"></i>
</div>
<!-- <i class="nav-icon fas fa-tachometer-alt"></i> -->
<div class="info">
<a href="user.html" class="d-block" id="userlabel">Username to set!</a>
</div>
</div>
<!-- Sidebar -->
<div class="sidebar">
<!-- Sidebar user panel (optional) -->
<div class="user-panel mt-3 pb-3 mb-3 d-flex">
<div class="image">
<!-- <img src="lib/AdminLTE/dist/img/user2-160x160.jpg" class="img-circle elevation-2" alt="User Image"> -->
<i class="nav-icon fas fa-user img-circle elevation-2" style="color:white"></i>
</div>
<!-- <i class="nav-icon fas fa-tachometer-alt"></i> -->
<div class="info">
<a href="user.html" class="d-block" id="userlabel">Username to set!</a>
</div>
</div>
<!-- Sidebar Menu -->
<nav class="mt-2">
<ul class="nav nav-pills nav-sidebar flex-column" data-widget="treeview" role="menu"
data-accordion="false">
<li class="nav-item">
<a href="#todo" class="nav-link">
<i class="nav-icon fas fa-cog"></i>
<p>
Settings
</p>
</a>
</li>
<li class="nav-item">
<a href="index.html" class="nav-link" id="logoutbtn">
<i class="nav-icon fas fa-sign-out-alt"></i>
<p>
Logout
</p>
</a>
</li>
<li id="adminpanel" class="nav-item hideit">
<a href="adminpanel.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Admin panel
</p>
</a>
</li>
<li id="devicepanel" class="nav-item">
<a href="device.html" class="nav-link">
<i class="nav-icon fas fa-plus-circle"></i>
<p>
Devices
</p>
</a>
</li>
</ul>
</nav>
<!-- /.sidebar-menu -->
</div>
<!-- /.sidebar -->
</aside>
<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
<!-- Content Header (Page header) -->
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
<h1 class="m-0 text-dark">Dashboard</h1>
</div><!-- /.col -->
<div class="col-sm-6">
<ol class="breadcrumb float-sm-right">
<li class="breadcrumb-item"><a href="dashboard.html">Home</a></li>
<li class="breadcrumb-item active">Users</li>
</ol>
</div><!-- /.col -->
</div><!-- /.row -->
</div><!-- /.container-fluid -->
</div>
<!-- /.content-header -->
<!-- Main content -->
<section class="content">
<div class="container-fluid">
<!-- Small boxes (Stat box) -->
<div class="row">
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-info">
<div class="inner">
<h3>150</h3>
<p>Todo</p>
</div>
<div class="icon">
<i class="ion ion-bag"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
<div class="col-lg-3 col-6">
<!-- small box -->
<div class="small-box bg-success">
<div class="inner">
<h3>42</h3>
<p>Devices</p>
</div>
<div class="icon">
<i class="ion ion-stats-bars"></i>
</div>
<a href="#" class="small-box-footer">More info <i class="fas fa-arrow-circle-right"></i></a>
</div>
</div>
<!-- ./col -->
</div>
<!-- /.row -->
<!-- Main row -->
<div class="row">
<!-- Left col -->
<section class="col-lg-7 connectedSortable">
<!-- Custom tabs (Charts with tabs)-->
<div class="card">
<div class="card-header">
<h3 class="card-title">
<i class="fas fa-chart-pie mr-1"></i>
User Data
</h3>
<button id="btn-newdevice" type="button" class="btn btn-success"
style="float:right;">Save
</button>
</div><!-- /.card-header -->
<div class="card-body">
<div class="form-group" style="margin-top: 15px; width: 10cm;">
<!-- todo todo -->
<label for="new_city_cityname">City/Village name</label>
<input type="email" class="form-control" id="new_city_cityname"
aria-describedby="emailHelp" placeholder="Enter city name here">
<small class="form-text text-muted">Please try to use no special
characters</small>
</div>
<div class="form-group" style="width: 10cm;">
<label for="new_city_zonename">Zone Name</label>
<input type="email" class="form-control" id="new_city_zonename"
aria-describedby="emailHelp" placeholder="Enter Zone name here">
<small class="form-text text-muted">Please try to use no special
characters</small>
</div>
<div class="input-group-prepend">
<button id="dropdown-wastetype" type="button"
class="btn btn-outline-dark dropdown-toggle"
data-toggle="dropdown">
Select waste type
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="#">Plastic</a>
<a class="dropdown-item" href="#">Metal</a>
<a class="dropdown-item" href="#">Residual waste</a>
<a class="dropdown-item" href="#">Biowaste</a>
</div>
</div>
</div><!-- /.card-body -->
</div>
</section>
<!-- /.Left col -->
<!-- right col (We are only adding the ID to make the widgets sortable)-->
<section class="col-lg-5 connectedSortable">
<!-- /.card -->
</section>
<!-- right col -->
</div>
<!-- /.row (main row) -->
</div><!-- /.container-fluid -->
</section>
<!-- /.content -->
</div>
<!-- /.content-wrapper -->
<footer class="main-footer">
<strong>By Gregor Dutzler & Lukas Heiligenbrunner & Emil Meindl</strong>
<div class="float-right d-none d-sm-inline-block">
<b>Version</b> 3.0.0
<b>Build</b> 2019-8-8 9:30
</div>
</footer>
<!-- Control Sidebar -->
<aside class="control-sidebar control-sidebar-dark">
<!-- Control sidebar content goes here -->
</aside>
<!-- /.control-sidebar -->
</div>
<!-- ./wrapper -->
<!-- jQuery -->
<script src="lib/AdminLTE/plugins/jquery/jquery.min.js"></script>
<!-- jQuery UI 1.11.4 -->
<script src="lib/AdminLTE/plugins/jquery-ui/jquery-ui.min.js"></script>
<!-- Resolve conflict in jQuery UI tooltip with Bootstrap tooltip -->
<script>
$.widget.bridge('uibutton', $.ui.button)
</script>
<!-- Bootstrap 4 -->
<script src="lib/AdminLTE/plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- ChartJS -->
<script src="lib/AdminLTE/plugins/chart.js/Chart.min.js"></script>
<!-- Sparkline -->
<script src="lib/AdminLTE/plugins/sparklines/sparkline.js"></script>
<!-- JQVMap -->
<script src="lib/AdminLTE/plugins/jqvmap/jquery.vmap.min.js"></script>
<script src="lib/AdminLTE/plugins/jqvmap/maps/jquery.vmap.usa.js"></script>
<!-- jQuery Knob Chart -->
<script src="lib/AdminLTE/plugins/jquery-knob/jquery.knob.min.js"></script>
<!-- daterangepicker -->
<script src="lib/AdminLTE/plugins/moment/moment.min.js"></script>
<script src="lib/AdminLTE/plugins/daterangepicker/daterangepicker.js"></script>
<!-- Tempusdominus Bootstrap 4 -->
<script src="lib/AdminLTE/plugins/tempusdominus-bootstrap-4/js/tempusdominus-bootstrap-4.min.js"></script>
<!-- Summernote -->
<script src="lib/AdminLTE/plugins/summernote/summernote-bs4.min.js"></script>
<!-- overlayScrollbars -->
<script src="lib/AdminLTE/plugins/overlayScrollbars/js/jquery.overlayScrollbars.min.js"></script>
<!-- AdminLTE App -->
<script src="lib/AdminLTE/dist/js/adminlte.js"></script>
<!-- AdminLTE dashboard demo (This is only for demo purposes) -->
<script src="lib/AdminLTE/dist/js/pages/dashboard.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="lib/AdminLTE/dist/js/demo.js"></script>
<script type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.4.1/js/bootstrap-datepicker.min.js"></script>
<!--<script type="text/javascript" src="js/user.js"></script>-->
<!-- DataTables -->
<script src="lib/AdminLTE/plugins/datatables/jquery.dataTables.js"></script>
<script src="lib/AdminLTE/plugins/datatables-bs4/js/dataTables.bootstrap4.js"></script>
<script src="lib/AdminLTE/plugins/sweetalert2/sweetalert2.all.js"></script>
<script src="js/device.js"></script>
</body>
</html>

View File

@ -0,0 +1,37 @@
$(document).ready(function () {
$('#btn-newdevice').click(function (e) {
e.preventDefault();
Swal.showLoading({
title: 'No connection to Database',
html: 'Setup DB here --> <a href="index.html">click<a/>.',
});
// Swal.fire({
// type: "error",
// title: 'No connection to Database',
// html: 'Setup DB here --> <a href="index.html">click<a/>.',
// 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');
});
});