diff --git a/WebServer/.gitignore b/WebServer/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..ae3c1726048cd06b9a143e0376ed46dd9b9a8d53 --- /dev/null +++ b/WebServer/.gitignore @@ -0,0 +1 @@ +/bin/ diff --git a/WebServer/.project b/WebServer/.project new file mode 100644 index 0000000000000000000000000000000000000000..193e0c6a21bba6ecbe4478b901b61bc5673ac40f --- /dev/null +++ b/WebServer/.project @@ -0,0 +1,28 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>pissirsmarthome_WebServer</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.eclipse.jdt.core.javabuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.eclipse.jdt.core.javanature</nature> + </natures> + <filteredResources> + <filter> + <id>1658153304390</id> + <name></name> + <type>30</type> + <matcher> + <id>org.eclipse.core.resources.regexFilterMatcher</id> + <arguments>node_modules|.git|__CREATED_BY_JAVA_LANGUAGE_SERVER__</arguments> + </matcher> + </filter> + </filteredResources> +</projectDescription> diff --git a/antifurtoMicroservizio/bin/.gitignore b/antifurtoMicroservizio/bin/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..3725a21cf0d34e84b9e65d9cc5494ae3433ffcbf --- /dev/null +++ b/antifurtoMicroservizio/bin/.gitignore @@ -0,0 +1 @@ +/code/ diff --git a/antifurtoMicroservizio/res/CONF/deltaSensoriMovimento.json b/antifurtoMicroservizio/res/CONF/deltaSensoriMovimento.json index ff038e53ae60acd3d078c60b088d3bded12fc530..36f1ea9727c68726caf7298146cd6f9ee6c77b60 100644 --- a/antifurtoMicroservizio/res/CONF/deltaSensoriMovimento.json +++ b/antifurtoMicroservizio/res/CONF/deltaSensoriMovimento.json @@ -1 +1 @@ -{"IN5":32,"IN2":4,"IN1":33} \ No newline at end of file +{"IN2":4,"IN1":33,"IN3":10} \ No newline at end of file diff --git a/antifurtoMicroservizio/res/CONF/zona.json b/antifurtoMicroservizio/res/CONF/zona.json index e80fbcd0b89ecd048e75029f3091c42cbfbf8d52..b3472c22c5e40d36e7d2ed57923fd720f0cbba6f 100644 --- a/antifurtoMicroservizio/res/CONF/zona.json +++ b/antifurtoMicroservizio/res/CONF/zona.json @@ -1 +1 @@ -{"nomeOutputAntifurto":"OUT0","interruttore":"IN0","sensoriMovimento":["IN1","IN2","IN5"],"outputSuono":"OUT1"} \ No newline at end of file +{"nomeOutputAntifurto":"OUT0","interruttore":"IN0","sensoriMovimento":["IN1","IN2","IN3"],"outputSuono":"OUT1"} \ No newline at end of file diff --git a/antifurtoMicroservizio/res/stato.json b/antifurtoMicroservizio/res/stato.json index e152b4e8305ac32c97f7c526253965b669cd1963..d2a6c3e24225e363012e4c397b488f46428c2768 100644 --- a/antifurtoMicroservizio/res/stato.json +++ b/antifurtoMicroservizio/res/stato.json @@ -1 +1 @@ -{"soglia":32,"stato":1,"valore":0,"tempoAllarme":"2022-09-19T17:23:27.756890"} \ No newline at end of file +{"soglia":10,"stato":0,"valore":0,"tempoAllarme":"2022-09-20T22:01:57.853743"} \ No newline at end of file diff --git a/antifurtoMicroservizio/src/code/Antifurto.java b/antifurtoMicroservizio/src/code/Antifurto.java index ce25cce83dd8e19145dfd239a091492be3d56344..c6ab2a34840ae351866f95e325df9ee3fc1e2faa 100644 --- a/antifurtoMicroservizio/src/code/Antifurto.java +++ b/antifurtoMicroservizio/src/code/Antifurto.java @@ -88,7 +88,7 @@ public class Antifurto { topicsSub.add("from/"+getMqttTree()+"/gpio/" + interruttoreOutputSuono); // Sottoscrivo i messaggi che notificano il cambiamento di stato dell'interruttore - topicsSub.add("to/"+getMqttTree()+"/antifurto/soglia"); // Su questo topic mi arrivera' un messaggio {"soglia": 30} e dovrò impostare la soglia di conseguenza + topicsSub.add("conf/"+getMqttTree()+"/antifurto/soglia"); // Su questo topic mi arrivera' un messaggio {"soglia": 30} e dovrò impostare la soglia di conseguenza topicsSub.add("conf/"+getMqttTree()+"/antifurto"); topicsSub.add("conf/"+getMqttTree()+"/antifurto/sensore"); // Su questo topic mi arrivera' un messaggio per l'aggiunta di un sensore di movimento. diff --git a/antifurtoMicroservizio/src/code/SubscribeCallback.java b/antifurtoMicroservizio/src/code/SubscribeCallback.java index 4391572c95bff0b8ab137a08b835cdf7919fab95..71c093120d37d8441a41b1ead30a09db20dad82e 100644 --- a/antifurtoMicroservizio/src/code/SubscribeCallback.java +++ b/antifurtoMicroservizio/src/code/SubscribeCallback.java @@ -90,7 +90,7 @@ public class SubscribeCallback implements MqttCallback { sendOutAntifurto(); return; } - if (topic.equals("to/" + Antifurto.getMqttTree() + "/antifurto/soglia")) { + if (topic.equals("conf/" + Antifurto.getMqttTree() + "/antifurto/soglia")) { if (msgJson.has("soglia")) handleSetSoglia(msgJson); return; @@ -166,7 +166,7 @@ public class SubscribeCallback implements MqttCallback { else // 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++; } @@ -266,24 +266,33 @@ public class SubscribeCallback implements MqttCallback { publisher.aggiungiComando(topic, json.toString()); } - private void setConsistentStatus(JSONObject msgJson) throws JSONException, IOException { //DA MODIFICARE (invio webapp) + private void setConsistentStatus(JSONObject msgJson) throws JSONException, IOException { + int statoOutGpio = msgJson.getInt("status"); + JSONObject js = new JSONObject(); + if (statoOutGpio == 0 && automa.getStatoInterruttore().equals("on")) { // devo andare nello stato 0 dell'automa automa.setStatoAutoma(0); automa.aggiornaInterruttoreESuono(); esec.reset(); + js.put("event", automa.getStatoInterrutoreTrueFalse()); } if (statoOutGpio == 1 && automa.getStatoInterruttore().equals("off")) { // devo andare nello stato 1 dell'automa automa.setStatoAutoma(1); automa.aggiornaInterruttoreESuono(); + js.put("event", automa.getStatoInterrutoreTrueFalse()); + } + if(js.has("event")) { + // aggiorno il file di persistenza + JSONObject statoJson = new JSONObject(Helper.leggiFile(Automa.FILE_STATO)); + statoJson.put("stato", automa.getStatoAutoma()); + statoJson.put("valore", esec.getValore()); + Helper.scriviFile(statoJson, Automa.FILE_STATO); + + publisher.aggiungiComando("from/" + Antifurto.getMqttTree() + "/antifurto/antifurto", js.toString()); } - // aggiorno il file di persistenza - JSONObject statoJson = new JSONObject(Helper.leggiFile(Automa.FILE_STATO)); - statoJson.put("stato", automa.getStatoAutoma()); - statoJson.put("valore", esec.getValore()); - Helper.scriviFile(statoJson, Automa.FILE_STATO); } private void sendOutAntifurto() throws JSONException { @@ -340,6 +349,12 @@ public class SubscribeCallback implements MqttCallback { client.setNomeOutputAntifurto(nomeOutputAntifurto); client.addTopicToSubscribe("from/"+Antifurto.getMqttTree()+"/gpio/" + nomeOutputAntifurto); newNomeOutputAntifurtoConf = null; + String message = null; + if(automa.getStatoAutoma() == 1 || automa.getStatoAutoma()==2) + message = "{cmd:1}"; + else + message = "{cmd:0}"; + publisher.aggiungiComando("to/"+Antifurto.getMqttTree()+"/gpio/"+client.getNomeOutputAntifurto(), message); } private void newConfigNomeOutputSuono(String outputSuono) throws MqttException, JSONException { @@ -347,6 +362,12 @@ public class SubscribeCallback implements MqttCallback { client.setNomeOutputSuono(outputSuono); client.addTopicToSubscribe("from/"+Antifurto.getMqttTree()+"/gpio/" + outputSuono); newSuonoConf = null; + String message = null; + if(automa.getStatoAutoma()==2) + message = "{cmd:1}"; + else + message = "{cmd:0}"; + publisher.aggiungiComando("to/"+Antifurto.getMqttTree()+"/gpio/"+client.getNomeOutputSuono(), message); } // pubblica la risposta (per la webApp) solo se newNomeOutputAntifurtoConf = null e newSuonoConf = null