hi
This commit is contained in:
parent
032d3a9b9c
commit
fb2b191a73
@ -17,43 +17,43 @@ public class Log {
|
||||
private static final String ANSI_CYAN = "\u001B[36m";
|
||||
private static final String ANSI_WHITE = "\u001B[37m";
|
||||
|
||||
public static final int CRITICAL_ERROR=6;
|
||||
public static final int ERROR=5;
|
||||
public static final int WARNING=4;
|
||||
public static final int INFO=3;
|
||||
public static final int MESSAGE=2;
|
||||
public static final int DEBUG=1;
|
||||
public static final int CRITICAL_ERROR = 6;
|
||||
public static final int ERROR = 5;
|
||||
public static final int WARNING = 4;
|
||||
public static final int INFO = 3;
|
||||
public static final int MESSAGE = 2;
|
||||
public static final int DEBUG = 1;
|
||||
|
||||
private static ArrayList<String> colors= new ArrayList<String>(Arrays.asList("","DEBUG","MESSAGE","INFO","WARNING","ERROR","CRITICAL_ERROR"));
|
||||
private static ArrayList<String> colors = new ArrayList<String>(Arrays.asList("", "DEBUG", "MESSAGE", "INFO", "WARNING", "ERROR", "CRITICAL_ERROR"));
|
||||
|
||||
public static void criticalerror(String msg){
|
||||
log(msg,CRITICAL_ERROR);
|
||||
public static void criticalerror(String msg) {
|
||||
log(msg, CRITICAL_ERROR);
|
||||
}
|
||||
|
||||
public static void error(String msg){
|
||||
log(msg,ERROR);
|
||||
public static void error(String msg) {
|
||||
log(msg, ERROR);
|
||||
}
|
||||
|
||||
public static void warning(String msg){
|
||||
log(msg,WARNING);
|
||||
public static void warning(String msg) {
|
||||
log(msg, WARNING);
|
||||
}
|
||||
|
||||
public static void info(String msg){
|
||||
log(msg,INFO);
|
||||
public static void info(String msg) {
|
||||
log(msg, INFO);
|
||||
}
|
||||
|
||||
public static void message(String msg){
|
||||
log(msg,MESSAGE);
|
||||
public static void message(String msg) {
|
||||
log(msg, MESSAGE);
|
||||
}
|
||||
|
||||
public static void debug(String msg){
|
||||
log(msg,DEBUG);
|
||||
public static void debug(String msg) {
|
||||
log(msg, DEBUG);
|
||||
}
|
||||
|
||||
|
||||
public static void log(String msg, int level){
|
||||
public static void log(String msg, int level) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
switch (level){
|
||||
switch (level) {
|
||||
case INFO:
|
||||
builder.append(ANSI_CYAN);
|
||||
break;
|
||||
|
@ -52,7 +52,7 @@ Database {
|
||||
System.out.println(row);
|
||||
}
|
||||
|
||||
} catch(SQLException e) {
|
||||
} catch (SQLException e) {
|
||||
}
|
||||
}
|
||||
|
||||
@ -68,7 +68,7 @@ Database {
|
||||
|
||||
Vector<Vector<Object>> data = new Vector<>();
|
||||
|
||||
while(res.next()) {
|
||||
while (res.next()) {
|
||||
Vector<Object> row = new Vector();
|
||||
|
||||
for (int i = 1; i <= columnCount; ++i) {
|
||||
@ -79,7 +79,7 @@ Database {
|
||||
}
|
||||
|
||||
return new DefaultTableModel(data, columnNames);
|
||||
} catch(SQLException e) {
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
@ -10,9 +10,9 @@ import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class jdcb {
|
||||
Connection conn;
|
||||
Connection conn;
|
||||
|
||||
public jdcb(String username, String password,String dbname) {
|
||||
public jdcb(String username, String password, String dbname) {
|
||||
Database db = new MySQLConnector(
|
||||
username,
|
||||
password,
|
||||
@ -29,7 +29,6 @@ Connection conn;
|
||||
}
|
||||
|
||||
public ResultSet executeQuery(String sql) {
|
||||
|
||||
try {
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
return stmt.executeQuery();
|
||||
@ -39,7 +38,7 @@ Connection conn;
|
||||
return null;
|
||||
}
|
||||
|
||||
public int executeUpdate(String sql){
|
||||
public int executeUpdate(String sql) {
|
||||
try {
|
||||
PreparedStatement stmt = conn.prepareStatement(sql);
|
||||
|
||||
|
@ -1,11 +1,6 @@
|
||||
package com.wasteinformationserver;
|
||||
|
||||
import com.wasteinformationserver.mqtt.*;
|
||||
import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
|
||||
import java.net.URISyntaxException;
|
||||
import java.sql.SQLException;
|
||||
|
||||
public class main {
|
||||
public static void main(String[] args) {
|
||||
/*
|
||||
@ -30,13 +25,11 @@ public class main {
|
||||
|
||||
Log.message("thread started");*/
|
||||
|
||||
mqtt m=new mqtt();
|
||||
// m.notifymessage();
|
||||
try {
|
||||
m.getDatabasedata();
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mqtt m = new mqtt();
|
||||
// m.notifymessage();
|
||||
m.getDatabasedata();
|
||||
m.printlist();
|
||||
// Log.message("mqtt irgentwos");
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -2,24 +2,27 @@ package com.wasteinformationserver.mqtt;
|
||||
|
||||
import com.wasteinformationserver.db.jdcb;
|
||||
|
||||
import javax.swing.table.DefaultTableModel;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class mqtt {
|
||||
|
||||
private ArrayList<String> mylist=new ArrayList<>();
|
||||
private int index=0;
|
||||
private ArrayList<String> mylist = new ArrayList<>();
|
||||
private int index = 0;
|
||||
|
||||
public mqtt(){
|
||||
public mqtt() {
|
||||
|
||||
}
|
||||
|
||||
public void notifymessage(){
|
||||
public void notifymessage() {
|
||||
|
||||
mqttreceiver mr=new mqttreceiver();
|
||||
mqttreceiver mr = new mqttreceiver();
|
||||
|
||||
mr.addMessageReceivedListener(new ActionListener() {
|
||||
@Override
|
||||
@ -29,30 +32,38 @@ public class mqtt {
|
||||
});
|
||||
}
|
||||
|
||||
public void getDatabasedata() throws SQLException {
|
||||
jdcb database=new jdcb("placeuser","eaL956R6yFItQVBl","wasteinformation");
|
||||
ResultSet result = database.executeQuery("SELECT*FROM place");
|
||||
public void getDatabasedata() {
|
||||
int n=0;
|
||||
|
||||
while(result.next())
|
||||
{
|
||||
String temp= String.valueOf(result.getStatement());
|
||||
filllist(temp);
|
||||
jdcb Database = new jdcb("placeuser", "eaL956R6yFItQVBl", "wasteinformation");
|
||||
ResultSet result = Database.executeQuery("SELECT*FROM place WHERE Zone=1");
|
||||
try {
|
||||
while (result.next()) {
|
||||
String temp = String.valueOf(result.getString("Abholtag"));
|
||||
System.out.println(temp);
|
||||
filllist(temp);
|
||||
n++;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
//transmitmessagetoESP();
|
||||
transmitmessagetoESP();
|
||||
}
|
||||
|
||||
private void transmitmessagetoESP()
|
||||
{
|
||||
|
||||
mqtttransmitter mt=new mqtttransmitter();
|
||||
private void transmitmessagetoESP() {
|
||||
mqtttransmitter mt = new mqtttransmitter(mylist);
|
||||
}
|
||||
|
||||
private void filllist(String temp)
|
||||
{
|
||||
mylist.add(index,temp);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -47,13 +47,13 @@ public class mqttreceiver {
|
||||
|
||||
}
|
||||
|
||||
private void notifylisteners(String message){
|
||||
for (ActionListener ac:mylisteners) {
|
||||
new ActionEvent(this,0,message);
|
||||
private void notifylisteners(String message) {
|
||||
for (ActionListener ac : mylisteners) {
|
||||
new ActionEvent(this, 0, message);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMessageReceivedListener(ActionListener l){
|
||||
public void addMessageReceivedListener(ActionListener l) {
|
||||
mylisteners.add(l);
|
||||
}
|
||||
}
|
||||
|
@ -6,25 +6,30 @@ import org.eclipse.paho.client.mqttv3.MqttException;
|
||||
import org.eclipse.paho.client.mqttv3.MqttMessage;
|
||||
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class mqtttransmitter {
|
||||
|
||||
public mqtttransmitter() {
|
||||
public mqtttransmitter(ArrayList<String> mylist) {
|
||||
|
||||
String topic = "kk";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://192.168.65.15:1883";
|
||||
String clientId = "JavaSample";
|
||||
}
|
||||
|
||||
public void sendmessage(ArrayList mylist) {
|
||||
String topic = "kk";
|
||||
String content = "Message from MqttPublishSample";
|
||||
int qos = 2;
|
||||
String broker = "tcp://192.168.65.15:1883";
|
||||
String clientId = "JavaSample";
|
||||
MemoryPersistence persistence = new MemoryPersistence();
|
||||
|
||||
try {
|
||||
MqttClient sampleClient = new MqttClient(broker, clientId, persistence);
|
||||
MqttConnectOptions connOpts = new MqttConnectOptions();
|
||||
connOpts.setCleanSession(true);
|
||||
System.out.println("Connecting to broker: "+broker);
|
||||
System.out.println("Connecting to broker: " + broker);
|
||||
sampleClient.connect(connOpts);
|
||||
System.out.println("Connected");
|
||||
System.out.println("Publishing message: "+content);
|
||||
System.out.println("Publishing message: " + content);
|
||||
MqttMessage message = new MqttMessage(content.getBytes());
|
||||
message.setQos(qos);
|
||||
sampleClient.publish(topic, message);
|
||||
@ -32,13 +37,14 @@ public class mqtttransmitter {
|
||||
sampleClient.disconnect();
|
||||
System.out.println("Disconnected");
|
||||
System.exit(0);
|
||||
} catch(MqttException me) {
|
||||
System.out.println("reason "+me.getReasonCode());
|
||||
System.out.println("msg "+me.getMessage());
|
||||
System.out.println("loc "+me.getLocalizedMessage());
|
||||
System.out.println("cause "+me.getCause());
|
||||
System.out.println("excep "+me);
|
||||
} catch (MqttException me) {
|
||||
System.out.println("reason " + me.getReasonCode());
|
||||
System.out.println("msg " + me.getMessage());
|
||||
System.out.println("loc " + me.getLocalizedMessage());
|
||||
System.out.println("cause " + me.getCause());
|
||||
System.out.println("excep " + me);
|
||||
me.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user