hi
This commit is contained in:
		@@ -28,7 +28,6 @@ public class main {
 | 
			
		||||
 | 
			
		||||
        mqtt m = new mqtt();
 | 
			
		||||
        m.notifymessage();
 | 
			
		||||
        m.getDatabasedata();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -7,52 +7,103 @@ import java.awt.event.ActionListener;
 | 
			
		||||
import java.sql.ResultSet;
 | 
			
		||||
import java.sql.SQLException;
 | 
			
		||||
import java.text.DateFormat;
 | 
			
		||||
import java.text.ParseException;
 | 
			
		||||
import java.text.SimpleDateFormat;
 | 
			
		||||
import java.time.LocalDateTime;
 | 
			
		||||
import java.util.Date;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.GregorianCalendar;
 | 
			
		||||
 | 
			
		||||
public class mqtt {
 | 
			
		||||
 | 
			
		||||
    ArrayList<String> mylist = new ArrayList<>();
 | 
			
		||||
    int index = 0;
 | 
			
		||||
 | 
			
		||||
    public mqtt() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void notifymessage() {
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        GregorianCalendar now = new GregorianCalendar();
 | 
			
		||||
        DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
 | 
			
		||||
        String date = df.format(now.getTime());
 | 
			
		||||
 | 
			
		||||
        System.out.println(date);
 | 
			
		||||
 | 
			
		||||
        String[] parts = date.split(" ");
 | 
			
		||||
        String temp2=parts[0];
 | 
			
		||||
        System.out.println(temp2);
 | 
			
		||||
        String[] partstwo=temp2.split("\\.");
 | 
			
		||||
        String newDate="20"+partstwo[2]+"-"+partstwo[1]+"-"+partstwo[0];
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        mqttreceiver mr = new mqttreceiver();
 | 
			
		||||
 | 
			
		||||
//        System.out.println(message);
 | 
			
		||||
 | 
			
		||||
        mr.addMessageReceivedListener(new ActionListener() {
 | 
			
		||||
            @Override
 | 
			
		||||
            public void actionPerformed(ActionEvent e) {
 | 
			
		||||
                System.out.println(e.getActionCommand());
 | 
			
		||||
                String temp = e.getActionCommand();
 | 
			
		||||
 | 
			
		||||
                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(message);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
        mr.getmessage();
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public void getDatabasedata() {
 | 
			
		||||
    public void getDatabasedata(String message) {
 | 
			
		||||
 | 
			
		||||
        String temptime = null;
 | 
			
		||||
        String tempabfallart = null;
 | 
			
		||||
        String temp;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        System.out.println(message);
 | 
			
		||||
        jdcb Database = new jdcb("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
 | 
			
		||||
        ResultSet result = Database.executeQuery("SELECT*FROM place WHERE Zone=1");
 | 
			
		||||
        ResultSet result = Database.executeQuery(message);
 | 
			
		||||
        try {
 | 
			
		||||
            while (result.next()) {
 | 
			
		||||
                temptime = String.valueOf(result.getString("Abholtag"));
 | 
			
		||||
                tempabfallart = String.valueOf(result.getString("Abfallart"));
 | 
			
		||||
                String temptime = String.valueOf(result.getString("Abholtag"));
 | 
			
		||||
                String tempabfallart = String.valueOf(result.getString("Abfallart"));
 | 
			
		||||
 | 
			
		||||
                GregorianCalendar now = new GregorianCalendar();
 | 
			
		||||
                DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.LONG);
 | 
			
		||||
                String date = df.format(now.getTime());
 | 
			
		||||
 | 
			
		||||
                String[] parts = temptime.split("-");
 | 
			
		||||
                String tempyear = parts[0];
 | 
			
		||||
 | 
			
		||||
                String[] yearsplit = tempyear.split("0");
 | 
			
		||||
                String tempyearnew = yearsplit[1];
 | 
			
		||||
 | 
			
		||||
                String newDate = parts[2] + "." + parts[1] + "." + tempyearnew;
 | 
			
		||||
 | 
			
		||||
                String[] partstwo = date.split(" ");
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                boolean abholtag;
 | 
			
		||||
                if (partstwo[0].contains(newDate)) {
 | 
			
		||||
                    abholtag = true;
 | 
			
		||||
                } else {
 | 
			
		||||
                    abholtag = false;
 | 
			
		||||
                }
 | 
			
		||||
                temp = tempabfallart + "," + abholtag;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                if (temp != null) {
 | 
			
		||||
                    transmitmessageAbfallart(temp);
 | 
			
		||||
                } else {
 | 
			
		||||
                    System.out.println("NO Connection");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        } catch (SQLException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        if (temptime != null && tempabfallart != null) {
 | 
			
		||||
            transmitmessageAbfallart(tempabfallart);
 | 
			
		||||
            //transmitmessageDate(temptime);
 | 
			
		||||
        } else {
 | 
			
		||||
            System.out.println("NO Connection");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -61,11 +112,4 @@ public class mqtt {
 | 
			
		||||
        mqtttransmitter mt = new mqtttransmitter();
 | 
			
		||||
        mt.sendmessage(tempabfallart);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    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()));
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -12,15 +12,18 @@ import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
public class mqttreceiver {
 | 
			
		||||
 | 
			
		||||
    MqttClient client;
 | 
			
		||||
    String message;
 | 
			
		||||
 | 
			
		||||
    ArrayList<ActionListener> mylisteners = new ArrayList<>();
 | 
			
		||||
    ArrayList<String> mylist=new ArrayList<>();
 | 
			
		||||
    int index=0;
 | 
			
		||||
    private MqttClient client;
 | 
			
		||||
    public ArrayList<ActionListener> mylisteners = new ArrayList<>();
 | 
			
		||||
    public String message;
 | 
			
		||||
 | 
			
		||||
    public mqttreceiver() {
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public String getmessage() {
 | 
			
		||||
 | 
			
		||||
         String temp;
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
            client = new MqttClient("tcp://192.168.65.15:1883", "JavaSample");
 | 
			
		||||
            client.connect();
 | 
			
		||||
@@ -33,9 +36,9 @@ public class mqttreceiver {
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
                public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
 | 
			
		||||
                    System.out.println(new String(mqttMessage.getPayload()));
 | 
			
		||||
                    notifylisteners(new String(mqttMessage.getPayload()));
 | 
			
		||||
                    addmylist(new String(mqttMessage.getPayload()));
 | 
			
		||||
                    message =new String(mqttMessage.getPayload());
 | 
			
		||||
                    notifylisteners(message);
 | 
			
		||||
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                @Override
 | 
			
		||||
@@ -44,15 +47,17 @@ public class mqttreceiver {
 | 
			
		||||
                }
 | 
			
		||||
            });
 | 
			
		||||
            client.subscribe("TopicIn");
 | 
			
		||||
            System.out.println("subscribed topic");
 | 
			
		||||
        } catch (MqttException e) {
 | 
			
		||||
            e.printStackTrace();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return message;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    private void notifylisteners(String message) {
 | 
			
		||||
        for (ActionListener ac : mylisteners) {
 | 
			
		||||
            new ActionEvent(this, 0, message);
 | 
			
		||||
            ac.actionPerformed(new ActionEvent(this, 0, message));
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@@ -60,8 +65,5 @@ public class mqttreceiver {
 | 
			
		||||
        mylisteners.add(l);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private void addmylist(String temp){
 | 
			
		||||
        mylist.add(index,temp);
 | 
			
		||||
        index++;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user