71 lines
2.0 KiB
Java
Raw Normal View History

2019-10-04 16:52:14 +02:00
package com.wasteinformationserver.mqtt;
import com.wasteinformationserver.db.jdcb;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.ResultSet;
import java.sql.SQLException;
2019-10-11 10:48:04 +02:00
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.GregorianCalendar;
2019-10-04 16:52:14 +02:00
public class mqtt {
2019-10-11 09:03:14 +02:00
public mqtt() {
2019-10-04 16:52:14 +02:00
}
2019-10-11 09:03:14 +02:00
public void notifymessage() {
2019-10-04 16:52:14 +02:00
2019-10-11 09:03:14 +02:00
mqttreceiver mr = new mqttreceiver();
2019-10-04 16:52:14 +02:00
mr.addMessageReceivedListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
}
});
}
2019-10-11 09:03:14 +02:00
public void getDatabasedata() {
2019-10-11 10:48:04 +02:00
String temptime = null;
String tempabfallart = null;
2019-10-11 09:03:14 +02:00
jdcb Database = new jdcb("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
ResultSet result = Database.executeQuery("SELECT*FROM place WHERE Zone=1");
try {
while (result.next()) {
2019-10-11 10:48:04 +02:00
temptime = String.valueOf(result.getString("Abholtag"));
tempabfallart = String.valueOf(result.getString("Abfallart"));
2019-10-11 09:03:14 +02:00
}
} catch (SQLException e) {
e.printStackTrace();
2019-10-04 16:52:14 +02:00
}
2019-10-11 10:48:04 +02:00
if (temptime != null && tempabfallart != null) {
transmitmessageAbfallart(tempabfallart);
//transmitmessageDate(temptime);
} else {
System.out.println("NO Connection");
}
2019-10-11 09:03:14 +02:00
}
2019-10-04 16:52:14 +02:00
2019-10-11 10:48:04 +02:00
private void transmitmessageAbfallart(String tempabfallart) {
2019-10-04 16:52:14 +02:00
2019-10-11 10:48:04 +02:00
mqtttransmitter mt = new mqtttransmitter();
mt.sendmessage(tempabfallart);
2019-10-04 16:52:14 +02:00
}
2019-10-11 10:48:04 +02:00
private void transmitmessageDate(String temptime) {
GregorianCalendar now = new GregorianCalendar();
DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG); // 14.04.12 21:34:07 MESZ
System.out.println(df.format(now.getTime()));
2019-10-04 16:52:14 +02:00
2019-10-11 10:48:04 +02:00
}
}