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

modifiche necessarie per la corretta configurazione del microservizio antifurto

parent fb66e915
No related branches found
No related tags found
No related merge requests found
/bin/
<?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>
/code/
{"IN5":32,"IN2":4,"IN1":33}
\ No newline at end of file
{"IN2":4,"IN1":33,"IN3":10}
\ No newline at end of file
{"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
{"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
......@@ -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.
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment