hi
This commit is contained in:
parent
fb2b191a73
commit
26fa5aacbb
@ -1,6 +1,7 @@
|
|||||||
package com.wasteinformationserver;
|
package com.wasteinformationserver;
|
||||||
|
|
||||||
import com.wasteinformationserver.mqtt.*;
|
import com.wasteinformationserver.mqtt.*;
|
||||||
|
|
||||||
public class main {
|
public class main {
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
/*
|
/*
|
||||||
@ -26,10 +27,8 @@ public class main {
|
|||||||
Log.message("thread started");*/
|
Log.message("thread started");*/
|
||||||
|
|
||||||
mqtt m = new mqtt();
|
mqtt m = new mqtt();
|
||||||
// m.notifymessage();
|
m.notifymessage();
|
||||||
m.getDatabasedata();
|
m.getDatabasedata();
|
||||||
m.printlist();
|
|
||||||
// Log.message("mqtt irgentwos");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,19 @@ package com.wasteinformationserver.mqtt;
|
|||||||
|
|
||||||
import com.wasteinformationserver.db.jdcb;
|
import com.wasteinformationserver.db.jdcb;
|
||||||
|
|
||||||
import javax.swing.table.DefaultTableModel;
|
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
import java.sql.Connection;
|
|
||||||
import java.sql.PreparedStatement;
|
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.text.DateFormat;
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.GregorianCalendar;
|
||||||
|
|
||||||
public class mqtt {
|
public class mqtt {
|
||||||
|
|
||||||
private ArrayList<String> mylist = new ArrayList<>();
|
|
||||||
private int index = 0;
|
|
||||||
|
|
||||||
public mqtt() {
|
public mqtt() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -33,37 +32,40 @@ public class mqtt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getDatabasedata() {
|
public void getDatabasedata() {
|
||||||
int n=0;
|
|
||||||
|
String temptime = null;
|
||||||
|
String tempabfallart = null;
|
||||||
|
|
||||||
jdcb Database = new jdcb("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
|
jdcb Database = new jdcb("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
|
||||||
ResultSet result = Database.executeQuery("SELECT*FROM place WHERE Zone=1");
|
ResultSet result = Database.executeQuery("SELECT*FROM place WHERE Zone=1");
|
||||||
try {
|
try {
|
||||||
while (result.next()) {
|
while (result.next()) {
|
||||||
String temp = String.valueOf(result.getString("Abholtag"));
|
temptime = String.valueOf(result.getString("Abholtag"));
|
||||||
System.out.println(temp);
|
tempabfallart = String.valueOf(result.getString("Abfallart"));
|
||||||
filllist(temp);
|
|
||||||
n++;
|
|
||||||
}
|
}
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
transmitmessagetoESP();
|
if (temptime != null && tempabfallart != null) {
|
||||||
}
|
transmitmessageAbfallart(tempabfallart);
|
||||||
|
//transmitmessageDate(temptime);
|
||||||
|
} else {
|
||||||
private void transmitmessagetoESP() {
|
System.out.println("NO Connection");
|
||||||
mqtttransmitter mt = new mqtttransmitter(mylist);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void filllist(String temp) {
|
|
||||||
mylist.add(index, temp);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void printlist() {
|
|
||||||
for (int n = 0; n < index; n++) {
|
|
||||||
System.out.println(mylist.get(index));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
private void transmitmessageAbfallart(String tempabfallart) {
|
||||||
|
|
||||||
|
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()));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -16,6 +16,8 @@ public class mqttreceiver {
|
|||||||
String message;
|
String message;
|
||||||
|
|
||||||
ArrayList<ActionListener> mylisteners = new ArrayList<>();
|
ArrayList<ActionListener> mylisteners = new ArrayList<>();
|
||||||
|
ArrayList<String> mylist=new ArrayList<>();
|
||||||
|
int index=0;
|
||||||
|
|
||||||
public mqttreceiver() {
|
public mqttreceiver() {
|
||||||
|
|
||||||
@ -33,6 +35,7 @@ public class mqttreceiver {
|
|||||||
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
public void messageArrived(String s, MqttMessage mqttMessage) throws Exception {
|
||||||
System.out.println(new String(mqttMessage.getPayload()));
|
System.out.println(new String(mqttMessage.getPayload()));
|
||||||
notifylisteners(new String(mqttMessage.getPayload()));
|
notifylisteners(new String(mqttMessage.getPayload()));
|
||||||
|
addmylist(new String(mqttMessage.getPayload()));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -40,7 +43,7 @@ public class mqttreceiver {
|
|||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
client.subscribe("test/topic");
|
client.subscribe("TopicIn");
|
||||||
} catch (MqttException e) {
|
} catch (MqttException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
@ -56,4 +59,9 @@ public class mqttreceiver {
|
|||||||
public void addMessageReceivedListener(ActionListener l) {
|
public void addMessageReceivedListener(ActionListener l) {
|
||||||
mylisteners.add(l);
|
mylisteners.add(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addmylist(String temp){
|
||||||
|
mylist.add(index,temp);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,19 +10,22 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
public class mqtttransmitter {
|
public class mqtttransmitter {
|
||||||
|
|
||||||
public mqtttransmitter(ArrayList<String> mylist) {
|
private String messagedatabase;
|
||||||
|
|
||||||
|
public mqtttransmitter() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendmessage(ArrayList mylist) {
|
public void sendmessage(String temp) {
|
||||||
String topic = "kk";
|
String topic = "TopicOut";
|
||||||
String content = "Message from MqttPublishSample";
|
String content = temp;
|
||||||
int qos = 2;
|
int qos = 2;
|
||||||
String broker = "tcp://192.168.65.15:1883";
|
String broker = "tcp://192.168.65.15:1883";
|
||||||
String clientId = "JavaSample";
|
String clientId = "JavaSample";
|
||||||
MemoryPersistence persistence = new MemoryPersistence();
|
MemoryPersistence persistence = new MemoryPersistence();
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
|
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
|
||||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||||
connOpts.setCleanSession(true);
|
connOpts.setCleanSession(true);
|
||||||
@ -37,6 +40,7 @@ public class mqtttransmitter {
|
|||||||
sampleClient.disconnect();
|
sampleClient.disconnect();
|
||||||
System.out.println("Disconnected");
|
System.out.println("Disconnected");
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
|
|
||||||
} catch (MqttException me) {
|
} catch (MqttException me) {
|
||||||
System.out.println("reason " + me.getReasonCode());
|
System.out.println("reason " + me.getReasonCode());
|
||||||
System.out.println("msg " + me.getMessage());
|
System.out.println("msg " + me.getMessage());
|
||||||
@ -47,4 +51,4 @@ public class mqtttransmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user