Skip to content
Snippets Groups Projects
Commit 3f363742 authored by Alfredo Chissotti's avatar Alfredo Chissotti
Browse files

inizio prova admin scenari

parent 4814ad18
Branches
No related tags found
No related merge requests found
Showing
with 64 additions and 29 deletions
{"attiva-scenari":"IN0",
{"attiva-scenari":"IN7",
"learn-trigger":"IN4",
"luce-antifurto":"OUT1"}
"luce-antifurto":"OUT5"}
......@@ -118,8 +118,7 @@ public class Scenari {
if(!attivaScenari.matches("(IN|in)[0-7]"))
throw new IllegalArgumentException("attivaScenari non corretto");
// write attivaScenari to the file zona
JSONObject config = new JSONObject();
config = new JSONObject(Helper.leggiFile(FILE_ZONA));
JSONObject config = new JSONObject(Helper.leggiFile(FILE_ZONA));
config.put("attiva-scenari", attivaScenari);
Helper.scriviFile(config, FILE_ZONA);
this.attivaScenari = attivaScenari;
......@@ -133,10 +132,19 @@ public class Scenari {
if(!luceAntifurto.matches("(OUT|out)[0-7]"))
throw new IllegalArgumentException("luceAntifurto non corretta");
// write luceAntifurto to the file zona
JSONObject config = new JSONObject();
config = new JSONObject(Helper.leggiFile(FILE_ZONA));
JSONObject config = new JSONObject(Helper.leggiFile(FILE_ZONA));
config.put("luce-antifurto", luceAntifurto);
Helper.scriviFile(config, FILE_ZONA);
this.luceAntifurto = luceAntifurto;
}
public void setLearnTrigger(String learnTrigger) throws JSONException, IOException{
if(!learnTrigger.matches("(IN|in)[0-7]"))
throw new IllegalArgumentException("learnTrigger non corretto");
// write learnTrigger to the file zona
JSONObject config = new JSONObject(Helper.leggiFile(FILE_ZONA));
config.put("learn-trigger", learnTrigger);
Helper.scriviFile(config, FILE_ZONA);
this.learnTrigger = learnTrigger;
}
}
......@@ -143,33 +143,40 @@ public class SubscribeCallback implements MqttCallback{
return;
}
if(topic.equals(Scenari.getMqttTree("to/","scenari"))) {
Helper.print("Cambio quale scenario e' attivo, se antifurto attivo\t"+automa.getAntifurto());
if(!automa.getAntifurto() || !msgJson.has("evento") || !msgJson.has("nome"))
if(topic.startsWith(Scenari.getMqttTree("to", "scenari"))){
if(topic.equals(Scenari.getMqttTree("to/","scenari"))) {
Helper.print("Cambio quale scenario e' attivo, se antifurto attivo\t"+automa.getAntifurto());
if(!automa.getAntifurto() || !msgJson.has("evento") || !msgJson.has("nome"))
return;
changeActiveScenario(msgJson);
return;
changeActiveScenario(msgJson);
return;
}
if(topic.equals(Scenari.getMqttTree("to/","scenari/salva"))) {
Helper.print("rinomino l'ultimo scenario salvato");
if(!msgJson.has("nome"))//se non sono appena stato nello stato di registrazione, non serve andare avanti
}
if(topic.equals(Scenari.getMqttTree("to/","scenari/salva"))) {
Helper.print("rinomino l'ultimo scenario salvato");
if(!msgJson.has("nome"))//se non sono appena stato nello stato di registrazione, non serve andare avanti
return;
renameLastScenario(msgJson);
return;
renameLastScenario(msgJson);
return;
}
if(topic.equals(Scenari.getMqttTree("to","scenari/sensoreAntifurto"))){
Helper.print("messaggio per cambiare il sensore che imposta l'antifurto");//serve se l'antifurto cambia sensore
if(!msgJson.has("attiva-scenari"))
}
if(topic.equals(Scenari.getMqttTree("to","scenari/sensoreAntifurto"))){
Helper.print("messaggio per cambiare il sensore che imposta l'antifurto");//serve se l'antifurto cambia sensore
if(!msgJson.has("attiva-scenari"))
return;
changeSensor(msgJson.getString("attiva-scenari"));
return;
changeSensor(msgJson.getString("attiva-scenari"));
return;
}
if(topic.equals(Scenari.getMqttTree("to","scenari/luceAntifurto"))) {
Helper.print("messaggio per cambiare la luce che indica lo stato dell'antifurto");//serve se l'antifurto cambia sensore
if(!msgJson.has("attiva-scenari"))
}
if(topic.equals(Scenari.getMqttTree("to","scenari/luceAntifurto"))) {
Helper.print("messaggio per cambiare la luce che indica lo stato dell'antifurto");//serve se l'antifurto cambia sensore
if(!msgJson.has("attiva-scenari"))
return;
changeLight(msgJson.getString("attiva-scenari"));
return;
}
if(topic.equals(Scenari.getMqttTree("to", "scenari/conf"))){
Helper.print("messaggio per cambiare la configurazione");
changeConf(msgJson);
return;
changeLight(msgJson.getString("attiva-scenari"));
}
return;
}
......@@ -387,4 +394,24 @@ public class SubscribeCallback implements MqttCallback{
esec.setLoopCondition(automa.getAntifurto());
sendRequested(Scenari.getMqttTree("from/","scenari/description"),false);
}
private void changeConf(JSONObject json) throws JSONException, IOException, MqttException {
// json = { "learn-trigger" : IN4, "attiva-scenari" : in1, "luce-antifurto" : OUT3 }
System.out.println(json.toString());
if(json.has("learn-trigger"))
scenari.setLearnTrigger(json.getString("learn-trigger"));
if(json.has("attiva-scenari"))
scenari.setAttivaScenari(json.getString("attiva-scenari"));
if(json.has("luce-antifurto"))
scenari.setLuceAntifurto(json.getString("luce-antifurto"));
// get all these values from scenari and send back
String learnTrigger = scenari.getLearnTrigger();
String attivaScenari = scenari.getAttivaScenari();
String luceAntifurto = scenari.getLuceAntifurto();
JSONObject j = new JSONObject();
j.put("learnINbtn", learnTrigger)
.put("antifurtoINbtn", attivaScenari)
.put("outputAntifurtoStato", luceAntifurto);
scenari.sendMqttMessage(Scenari.getMqttTree("from/","scenari/conf"), j.toString());
}
}
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment