diff --git a/antifurto/bin/autenticazione/Autenticazione.class b/antifurto/bin/autenticazione/Autenticazione.class new file mode 100644 index 0000000000000000000000000000000000000000..4ec5560819f02277b7e7c40f933261d950799060 Binary files /dev/null and b/antifurto/bin/autenticazione/Autenticazione.class differ diff --git a/antifurto/bin/code/Antifurto.class b/antifurto/bin/code/Antifurto.class new file mode 100644 index 0000000000000000000000000000000000000000..ca1dd13494814336b98a8bd0b99c3b1b10bdfd4b Binary files /dev/null and b/antifurto/bin/code/Antifurto.class differ diff --git a/antifurto/bin/code/Automa.class b/antifurto/bin/code/Automa.class new file mode 100644 index 0000000000000000000000000000000000000000..0762c305f16b1e302428bac39f94f6b331abb694 Binary files /dev/null and b/antifurto/bin/code/Automa.class differ diff --git a/antifurto/bin/code/Esecutore.class b/antifurto/bin/code/Esecutore.class new file mode 100644 index 0000000000000000000000000000000000000000..7afc26e33caf7dd0516e7e38c50c9b7a1f45479a Binary files /dev/null and b/antifurto/bin/code/Esecutore.class differ diff --git a/antifurto/bin/code/Helper.class b/antifurto/bin/code/Helper.class new file mode 100644 index 0000000000000000000000000000000000000000..f7837f33f2e069d637ee8e4960de41fbd7a900c8 Binary files /dev/null and b/antifurto/bin/code/Helper.class differ diff --git a/antifurto/bin/code/MyQueue.class b/antifurto/bin/code/MyQueue.class new file mode 100644 index 0000000000000000000000000000000000000000..ed2e5723fce7851871a4a9af7d4f0488a9fd9085 Binary files /dev/null and b/antifurto/bin/code/MyQueue.class differ diff --git a/antifurto/bin/code/Pair.class b/antifurto/bin/code/Pair.class new file mode 100644 index 0000000000000000000000000000000000000000..bc35695cbabdef40977fd46aa1e90872db7492b9 Binary files /dev/null and b/antifurto/bin/code/Pair.class differ diff --git a/antifurto/bin/code/Publisher.class b/antifurto/bin/code/Publisher.class new file mode 100644 index 0000000000000000000000000000000000000000..8de9acadd209f5f38899e2483f883717d2e272e2 Binary files /dev/null and b/antifurto/bin/code/Publisher.class differ diff --git a/antifurto/bin/code/SubscribeCallback.class b/antifurto/bin/code/SubscribeCallback.class new file mode 100644 index 0000000000000000000000000000000000000000..3df55cea9fe13504754c3a5e6fda83fa991784f4 Binary files /dev/null and b/antifurto/bin/code/SubscribeCallback.class differ diff --git a/antifurto/bin/code/Timer.class b/antifurto/bin/code/Timer.class new file mode 100644 index 0000000000000000000000000000000000000000..d654725c207e22d4edc0a4be7b852efbcda43a88 Binary files /dev/null and b/antifurto/bin/code/Timer.class differ diff --git a/antifurto/res/stato.json b/antifurto/res/stato.json deleted file mode 100644 index 8a65f3b9eec44d8354d05604247486cddbccbbef..0000000000000000000000000000000000000000 --- a/antifurto/res/stato.json +++ /dev/null @@ -1 +0,0 @@ -{"soglia":32,"stato":0,"valore":0,"tempoAllarme":"2022-09-17T17:18:19.727369"} \ No newline at end of file diff --git a/antifurto/src/code/Antifurto.java b/antifurto/src/code/Antifurto.java index c63c56047c091680783ae3576f825af2d0325197..ce25cce83dd8e19145dfd239a091492be3d56344 100644 --- a/antifurto/src/code/Antifurto.java +++ b/antifurto/src/code/Antifurto.java @@ -220,22 +220,23 @@ public class Antifurto { * di conseguenza! */ - public static void main(String args[]) throws JSONException, IOException, MqttException { // DA FARE: rimetti try catch e cancella throws MqttException + + public static void main(String args[]) throws JSONException, IOException { + boolean exc = true; System.out.println("antifurto started"); -// boolean exc = true; -// while(true) { -// if(exc) { -// try { + while(true) { + if(exc) { + try { startSystem(); -// exc = false; -// } -// catch(MqttException e) { -// System.out.println("Error: "+ e.getMessage() + "\nRestarting system..."); -// e.printStackTrace(); -// exc = true; -// } -// } -// } + exc = false; + } + catch(MqttException e) { + System.out.println("Error: "+ e.getMessage() + "\nRestarting system..."); + e.printStackTrace(); + exc = true; + } + } + } } diff --git a/antifurto/src/code/Esecutore.java b/antifurto/src/code/Esecutore.java index 80ceddd61f65d6232696adcb704161253c51e61f..9d5ac4001f33ae5059db22015e32414e1a60c510 100644 --- a/antifurto/src/code/Esecutore.java +++ b/antifurto/src/code/Esecutore.java @@ -2,9 +2,6 @@ package code; import java.io.IOException; import java.time.Duration; import java.time.LocalDateTime; -import java.time.LocalTime; -import java.time.ZoneId; -import java.time.ZoneOffset; import org.json.JSONException; import org.json.JSONObject; diff --git a/antifurto/src/code/Helper.java b/antifurto/src/code/Helper.java index 9b12be4f9ad87a37b9c2d2409249896f986eb8ed..e55614d226fb4772bdb0a3697dc1be76aa48e59f 100644 --- a/antifurto/src/code/Helper.java +++ b/antifurto/src/code/Helper.java @@ -5,8 +5,6 @@ import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; -import org.json.JSONArray; -import org.json.JSONException; import org.json.JSONObject; public class Helper { diff --git a/antifurto/src/code/SubscribeCallback.java b/antifurto/src/code/SubscribeCallback.java index 5a131e2f6e897da5aadc719e803802b797eba72d..3a8e9f899d5c236bd50b9010098fca67ef1650ed 100644 --- a/antifurto/src/code/SubscribeCallback.java +++ b/antifurto/src/code/SubscribeCallback.java @@ -1,7 +1,6 @@ package code; import java.io.IOException; -import java.sql.ClientInfoStatus; import java.util.Date; import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken; @@ -36,8 +35,8 @@ public class SubscribeCallback implements MqttCallback { boolean retry = true; final Date d = new Date(); Date d2 = new Date(); - long time = Math.abs(d2.getTime() - d.getTime()); System.out.println("time = "+time); - while (retry && (time < 3000)) {//(time < 600000)) { + long time = Math.abs(d2.getTime() - d.getTime()); + while (retry && (time < 600000)) { try { client.startClient(esec, publisher); retry = false; @@ -46,7 +45,7 @@ public class SubscribeCallback implements MqttCallback { time = Math.abs(d2.getTime() - d.getTime()); } } - if (time >= 3000) {//(time >= 600000) { + if (time >= 600000) { System.out.println("Tentativo di riconnessione fallito"); System.exit(1); } @@ -131,41 +130,13 @@ public class SubscribeCallback implements MqttCallback { private synchronized void handleStateMsgFromInterruttore() { if (automa.getStatoInterruttore().equals("on")) - publisher.aggiungiComando("to/" + Antifurto.getMqttTree() + "/gpio/" + client.getNomeOutputAntifurto(), "{cmd:0}"); // voglio - // spegnere - // l'antifurto, - // quindi - // invio - // un - // messaggio - // per - // spegnere - // la - // luce - // che - // indica - // che - // l'antifurto - // e' - // acceso + // voglio spegnere l'antifurto, quindi invio un messaggio per spegnere la luce che indica che l'antifurto e' acceso + publisher.aggiungiComando("to/" + Antifurto.getMqttTree() + "/gpio/" + client.getNomeOutputAntifurto(), "{cmd:0}"); + // else - publisher.aggiungiComando("to/" + Antifurto.getMqttTree() + "/gpio/" + client.getNomeOutputAntifurto(), "{cmd:1}"); // voglio - // accendere - // l'antifurto, - // quindi - // invio - // un - // messaggio - // per - // accendere - // la - // luce - // che - // indica - // che - // l'antifurto - // e' - // acceso + // voglio accendere l'antifurto, quindi invio un messaggio per accendere la luce che indica che l'antifurto e' acceso + publisher.aggiungiComando("to/" + Antifurto.getMqttTree() + "/gpio/" + client.getNomeOutputAntifurto(), "{cmd:1}"); + // contatore++; }