Skip to content
Snippets Groups Projects
Commit b0633eeb authored by Elisa Giglio's avatar Elisa Giglio
Browse files

tls fine

parent 3f363742
Branches
No related tags found
No related merge requests found
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
{"soglia":32,"stato":0,"valore":0,"tempoAllarme":"2022-09-08T20:02:59.643106"}
\ No newline at end of file
{"soglia":32,"stato":0,"valore":0,"tempoAllarme":"2022-09-12T17:55:30.663368"}
\ No newline at end of file
......@@ -114,11 +114,7 @@ public class Antifurto {
options.setUserName("gruppo2");
options.setPassword("funziona".toCharArray());
}
else if(brokerUrl.contains("localhost")) { // DA FARE: il microservizio girerà sulla beaglebone. Quindi qui voglio l'url del broker connesso in bridge con il mosquitto della beaglebone. Non potrà essere localhost!
caFilePath = "../certificates/localhost/ca.crt";
clientCrtFilePath = "../certificates/localhost/client.crt";
clientKeyFilePath = "../certificates/localhost/client.key";
} else {
else {
System.out.println("Unknown broken url " + brokerUrl);
System.exit(1);
}
......@@ -223,9 +219,9 @@ public class Antifurto {
* di conseguenza!
*/
public static void main(String args[]) throws JSONException, IOException, MqttException {
public static void main(String args[]) {
// while(true) {
while(true) {
try {
startSystem();
}
......@@ -233,7 +229,7 @@ public class Antifurto {
System.out.println("Error: "+ e.getMessage() + "\nRestarting system...");
e.printStackTrace();
}
// }
}
}
......
......@@ -19,7 +19,6 @@ public class Esecutore extends Thread {
private Automa automa;
private String outputSuono; // nome logico dell'interruttore che fa scattare il suono dell'allarme
private LocalDateTime tempoAllarme; //valorizzato solo quando l'allarme sta suonando. Contiene l'ora in cui l'allarme ha iniziato a suonare
private static long allarmeTimeout;
public Esecutore(Publisher publisher, MyQueue<Integer> codaVal, Automa automa, String outputSuono) throws JSONException, IOException {
this.codaVal = codaVal;
......@@ -111,9 +110,6 @@ public class Esecutore extends Thread {
return valore;
}
public static long getAllarmeTimeout() {
return allarmeTimeout;
}
public static void setSoglia(int newValue) throws JSONException, IOException {
JSONObject js = new JSONObject(Helper.leggiFile(Automa.FILE_STATO));
......
......@@ -70,32 +70,36 @@ public class SubscribeCallback implements MqttCallback {
if (topic.equals("to/all")) {
System.out.println("MESSAGGIO MQTT = " + message.toString());
if (message.toString().equals("{request:description}"))
sendDescription("from/"+Antifurto.getMqttTree()+"/antifurto/description");
sendMyState("from/" + Antifurto.getMqttTree() + "/antifurto/description");
if (message.toString().equals("{request:status}"))
sendMyStateToAll("from/"+Antifurto.getMqttTree()+"/antifurto"); // DA FARE: vedi cosa pubblicano gli altri microservizi e implementa di conseguenza questa funzione
sendMyStateToAll("from/" + Antifurto.getMqttTree() + "/antifurto");
return;
}
else {
JSONObject msgJson = new JSONObject(message.toString());
if (topic.equals("conf/" + Antifurto.getMqttTree() + "/antifurto/sensore")) {
if (msgJson.has("in") && msgJson.has("delta"))
handleConfSensoreMovimento(msgJson);
return;
}
if (topic.equals("conf/" + Antifurto.getMqttTree() + "/antifurto")) {
// DA FARE
return;
}
else {
if (topic.equals("to/" + Antifurto.getMqttTree() + "/antifurto/luceAntifurto")) {
if (msgJson.has("request"))
sendOutAntifurto();
return;
}
else {
if (topic.equals("to/" + Antifurto.getMqttTree() + "/antifurto/soglia")) {
if (msgJson.has("soglia"))
handleSetSoglia(msgJson);
return;
}
else {
if (topic.equals("rpc/" + Antifurto.getMqttTree() + "/antifurto")) {
if (message.toString().equals("{\"request\":\"description\"}"))
sendMyState("from/" + Antifurto.getMqttTree() + "/antifurto");
return;
}
else {
if (topic.equals("from/" + Antifurto.getMqttTree() + "/gpio/" + nomeOutputSuono)) {
int newStatus = -1;
if (msgJson.has("status"))
......@@ -105,35 +109,29 @@ public class SubscribeCallback implements MqttCallback {
newStatus = msgJson.getInt("event");
}
handleStateMsgFromOutputSuono(newStatus);
return;
}
else {
if (topic.equals("from/" + Antifurto.getMqttTree() + "/gpio/" + nomeOutputAntifurto)) {
if (msgJson.has("event"))
handleLuceAntifurto();
if (msgJson.has("status"))
setConsistentStatus(msgJson);
return;
}
else {
int event = msgJson.getInt("event");
if (event == 1) {
// e' stato premuto l'interruttore / il sensore di movimento ha rilevato qualcuno
if(topic.equals("from/"+Antifurto.getMqttTree()+"/gpio/"+nomeInterruttore))
// e' stato premuto l'interruttore / il sensore di movimento ha rilevato
// qualcuno
if (topic.equals("from/" + Antifurto.getMqttTree() + "/gpio/" + nomeInterruttore)) {
handleStateMsgFromInterruttore();
else {
return;
}
// il topic sara' from/gruppo2/luci/gpio/IN2 dove IN2 e' un sensore di movimento
if (topic.startsWith("from/" + Antifurto.getMqttTree() + "/gpio/IN")) {
String[] t = topic.split("/");
handleMovimento(t[4]);
}
}
}
}
}
}
}
}
}
}
}
......@@ -284,9 +282,6 @@ public class SubscribeCallback implements MqttCallback {
json.put("allarme", automa.getStatoSuonoTrueFalse());
json.put("valore-attuale", esec.getValore());
json.put("antifurto", automa.getStatoInterrutoreTrueFalse());
long allarmeTimeout = Esecutore.getAllarmeTimeout();
if (automa.getStatoAutoma() == 2 && allarmeTimeout > 0)
json.put("allarme-timeout", allarmeTimeout);
publisher.aggiungiComando(topic, json.toString());
}
......@@ -310,34 +305,16 @@ public class SubscribeCallback implements MqttCallback {
Helper.scriviFile(statoJson, Automa.FILE_STATO);
}
private void sendOutAntifurto() throws JSONException {
JSONObject js = new JSONObject();
js.put("attiva-scenari", nomeOutputAntifurto);
publisher.aggiungiComando("to/" + Antifurto.getMqttTree() + "/scenari/luceAntifurto", js.toString());
}
private void sendDescription(String topic) {
// DA FARE: guardare quale descrizione manda netmon, archiver, meter,... e
// confrontare l'implementazione di questo metodo
String key = topic.replaceFirst("/description", "");
String msg = "{\"" + key + "\":[\"statoAntifurto\":\"" + automa.getStatoInterruttore() + "]" + "}";
//
// //DA FARE quali IN uso, quali Out uso, statoSuono, valore, soglia, statoInterruttore
// [{"statoAntifurto":"on"},
// {"allarme":"on"},
// {"valore":5},
// {"soglia":1000},
// {"interruttore":"IN0"},
// {"sensoreDiMovimento":"IN1"},
// {"sensoreDiMovimento":"IN2"},
// {"sensoreDiMovimento":"IN3"},
// {"sensoreSuono":"OUT3"},]
// publisher.aggiungiComando(topic, msg);
}
private void sendMyStateToAll(String topic) {
// DA FARE
private void sendMyStateToAll(String topic) throws JSONException {
JSONObject js = new JSONObject();
js.put("status", automa.getStatoAutoma());
publisher.aggiungiComando(topic, js.toString());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment