8.11.2019 MQTT finished

This commit is contained in:
Gregor_Dutzler 2019-11-08 14:13:32 +01:00
parent 6a3edc2269
commit a4563def38
5 changed files with 17 additions and 34 deletions

View File

@ -1,2 +1,7 @@
$(document).ready(function() { $(document).ready(function() {
$("#firstname").value("hhh");
$.post('/senddata/checkloginstate', 'action=getfirstname', function (data) {
console.log(data);
}, 'json');
}); });

View File

@ -67,8 +67,8 @@
<div class="form-row"> <div class="form-row">
<!-- form column --> <!-- form column -->
<div class="col-md-6 mb-3"> <div class="col-md-6 mb-3">
<label for="input01">First Name</label> <label for="firstname">First Name</label>
<input type="text" class="form-control" id="input01" value="Max" required=""></div> <input type="text" class="form-control" id="firstname" value="Max" required=""></div>
<!-- /form column --> <!-- /form column -->
<!-- form column --> <!-- form column -->
<div class="col-md-6 mb-3"> <div class="col-md-6 mb-3">

View File

@ -9,7 +9,7 @@ public class main {
Runtime.getRuntime().addShutdownHook(new Thread(() -> { /* Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try { try {
Thread.sleep(200); Thread.sleep(200);
Log.warning("Shutting down ..."); Log.warning("Shutting down ...");
@ -23,7 +23,7 @@ public class main {
Thread mythread = new Thread(() -> new Webserver().startserver()); Thread mythread = new Thread(() -> new Webserver().startserver());
mythread.start(); mythread.start();
Log.message("thread started"); Log.message("thread started");*/
mqtt m = new mqtt(); mqtt m = new mqtt();
m.notifymessage(); m.notifymessage();

View File

@ -22,53 +22,30 @@ public class mqtt {
public void notifymessage() { public void notifymessage() {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
String date = df.format(now.getTime());
Log.debug(date);
String[] parts = date.split(" ");
String temp2=parts[0];
Log.debug(temp2);
String[] partstwo=temp2.split("\\.");
String newDate="20"+partstwo[2]+"-"+partstwo[1]+"-"+partstwo[0];
mqttreceiver mr = new mqttreceiver(); mqttreceiver mr = new mqttreceiver();
// Log.debug(message);
mr.addMessageReceivedListener(new ActionListener() { mr.addMessageReceivedListener(new ActionListener() {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
String temp = e.getActionCommand(); String temp = e.getActionCommand();
System.out.println(temp);
String[] split = temp.split(","); String[] split = temp.split(",");
String message = "SELECT*FROM place WHERE Ort='" + split[0] + "' AND Abfallart='" + split[1] + "' AND Zone='" + split[2] + "' AND ABholtag='"+newDate+"'"; getDatabasedata("SELECT pickupdates.pickupdate FROM pickupdates WHERE pickupdates.citywastezoneid=(SELECT cities.zone FROM cities WHERE cities.name='" + split[1] + "' AND cities.wastetype='" + split[2] + "' AND cities.zone=" + split[3] + ")",split[2], Integer.parseInt(split[0]));
getDatabasedata(message);
} }
}); });
mr.getmessage(); mr.getmessage();
} }
public void getDatabasedata(String message) { public void getDatabasedata(String message,String wastetyp, int clientidentify) {
String temp; String temp;
Log.debug(message); Log.debug(message);
JDCB Database = new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation"); JDCB Database = new JDCB("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
ResultSet result = Database.executeQuery(message); ResultSet result = Database.executeQuery(message);
try { try {
while (result.next()) { while (result.next()) {
String temptime = String.valueOf(result.getString("Abholtag")); String temptime = String.valueOf(result.getString("pickupdate"));
String tempabfallart = String.valueOf(result.getString("Abfallart"));
GregorianCalendar now = new GregorianCalendar(); GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
@ -91,17 +68,19 @@ public class mqtt {
} else { } else {
abholtag = 0; abholtag = 0;
} }
temp = tempabfallart + "," + abholtag; temp = clientidentify+","+ wastetyp + "," + abholtag;
System.out.println(temp); System.out.println(temp);
if (temp != null) { if (temp != null) {
transmitmessageAbfallart(temp); transmitmessageAbfallart(temp);
notifymessage();
} else { } else {
Log.debug("NO Connection"); Log.debug("NO Connection");
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
System.out.println("Exception");
e.printStackTrace(); e.printStackTrace();
} }
@ -109,6 +88,7 @@ public class mqtt {
} }
private void transmitmessageAbfallart(String temp) { private void transmitmessageAbfallart(String temp) {
mqtttransmitter mt = new mqtttransmitter(); mqtttransmitter mt = new mqtttransmitter();

View File

@ -23,8 +23,6 @@ public class mqttreceiver {
public String getmessage() { public String getmessage() {
String temp;
try { try {
client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample"); client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample");
client.connect(); client.connect();