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

ancora da mettere il domain in https

parent 751d7b69
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 44 deletions
......@@ -68,16 +68,16 @@ public class Subscriber implements MqttCallback {
@Override
public void messageArrived(String topic, MqttMessage message) throws MqttException, JSONException, IOException {
Helper.print("new message: " + topic + " " + message.toString());
// Helper.print("new message: " + topic + " " + message.toString());
if (topic.equals(Luci.getMqttTree("rpc/", "luci"))) {
Helper.print("invio la mia configurazione");
// Helper.print("invio la mia configurazione");
sendFile(Luci.getMqttTree("from/", "luci"));
return;
}
if (topic.equals("to/all")) {
Helper.print("invio il mio stato");
// Helper.print("invio il mio stato");
sendStatus(Luci.getMqttTree("from/", "luci"));
return;
}
......@@ -93,7 +93,7 @@ public class Subscriber implements MqttCallback {
String nome = msgJson.getString("nome");
for (Luce k : Luci.luciList) {
if (k.getNome().equalsIgnoreCase(nome)) {
System.out.println("Nome gia' presente, inserimento annullato\n");
// System.out.println("Nome gia' presente, inserimento annullato\n");
return;
}
......@@ -125,9 +125,9 @@ public class Subscriber implements MqttCallback {
// sensM tempo
if (topic.equals(Luci.getMqttTree("from", "gpio/" + sensM))) {
System.out.println(giorno);
// System.out.println(giorno);
if(giorno)return;
if (msgJson.has("event") && msgJson.getInt("event") == 1) {
if (runningEsec) {
Esecutore.timer.cancel();
......@@ -140,7 +140,7 @@ public class Subscriber implements MqttCallback {
}
runningEsec = true;
esec.run(runningEsec);
//
//
}
return;
}
......@@ -150,7 +150,7 @@ public class Subscriber implements MqttCallback {
// prendo l'ultimo pezzo del topic, diventa il mio nome
String pezzo = topic.substring(23);// seleziono solo il nome della lamp
System.out.println("nome lamp\t" + pezzo);
// System.out.println("nome lamp\t" + pezzo);
for (int i = 0; i < Luci.luciList.size(); i++) {
if (Luci.luciList.get(i).getIN().equalsIgnoreCase(pezzo) && msgJson.has("event")
......@@ -167,7 +167,7 @@ public class Subscriber implements MqttCallback {
if (msgJson.has("status"))
return;
String pezzo = topic.substring(23);// seleziono solo il nome della lamp
System.out.println("nome lamp\t" + pezzo);
// System.out.println("nome lamp\t" + pezzo);
for (int i = 0; i < Luci.luciList.size(); i++) {
if (Luci.luciList.get(i).getOUT().equalsIgnoreCase(pezzo) && msgJson.has("event")) {
......@@ -197,18 +197,18 @@ public class Subscriber implements MqttCallback {
}
return;
}
if (topic.startsWith(Luci.getMqttTree("from", "arduino/AN0"))) {
if (msgJson.has("event")){
//
//
// if(msgJson.getInt("event")<200)giorno=false;
// else giorno=true;
giorno=(msgJson.getInt("event")>=200);
}
return;
}
Helper.print("Impossibile");
}
......
{"attiva-scenari":"IN7",
"learn-trigger":"IN4",
"luce-antifurto":"OUT5"}
"luce-antifurto":"OUT1"}
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
File added
No preview for this file type
File mode changed from 100644 to 100755
......@@ -7,19 +7,20 @@ import java.io.OutputStream;
import org.json.JSONException;
import org.json.JSONObject;
import com.sun.net.httpserver.HttpExchange;
// import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpsExchange;
public class Helper {
public static void sendResponse(String response, HttpExchange exchange) throws IOException {
public static void sendResponse(String response, HttpsExchange exchange) throws IOException {
System.out.println(response);
exchange.sendResponseHeaders(200, response.getBytes().length);
OutputStream os = exchange.getResponseBody();
os.write(response.getBytes());
os.close();
}
public static void badRequest(HttpExchange exchange) throws IOException {
public static void badRequest(HttpsExchange exchange) throws IOException {
System.out.println("Errors in the request!");
// exchange.getResponseHeaders().remove("content-type");
String response = "{\"message\":\"Errors in the request!\"}";
......@@ -28,8 +29,8 @@ public class Helper {
os.write(response.getBytes());
os.close();
}
public static void pageNotFound(HttpExchange exchange) throws IOException {
public static void pageNotFound(HttpsExchange exchange) throws IOException {
System.out.println("Page not found!");
// exchange.getResponseHeaders().remove("content-type");
String response = "{\"message\":\"Page not found!\"}";
......@@ -38,8 +39,8 @@ public class Helper {
os.write(response.getBytes());
os.close();
}
public static void methodNotAllowed(HttpExchange exchange) throws IOException {
public static void methodNotAllowed(HttpsExchange exchange) throws IOException {
System.out.println("Method not allowed!");
// exchange.getResponseHeaders().remove("content-type");
String response = "{\"message\":\"Method not allowed!\"}";
......@@ -48,7 +49,7 @@ public class Helper {
os.write(response.getBytes());
os.close();
}
public static boolean compareText(String a, String b){
return a.compareToIgnoreCase(b) == 0;
}
......@@ -64,7 +65,7 @@ public class Helper {
}
return sb.toString();
}
public static boolean checkJSON(String body) {
try {
new JSONObject(body);
......
......@@ -5,7 +5,6 @@ import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
......@@ -14,11 +13,13 @@ import org.json.JSONObject;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpsExchange;
public class Home implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
public void handle(HttpExchange ex) throws IOException {
HttpsExchange exchange = (HttpsExchange) ex;
String requestMethod = exchange.getRequestMethod();
if (Helper.compareText(requestMethod, "GET")) {
List<String> strlist = new ArrayList<>();
......
......@@ -5,19 +5,20 @@ import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.ArrayList;
import java.util.List;
import javax.imageio.ImageIO;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpsExchange;
import com.sun.net.httpserver.HttpHandler;
public class ImageRes implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
public void handle(HttpExchange ex) throws IOException {
HttpsExchange exchange = (HttpsExchange) ex;
String requestURI = exchange.getRequestURI().toASCIIString().replace("/secured/home/", "/");
String requestMethod = exchange.getRequestMethod();
......
package code;
import java.io.IOException;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
public class MissingPage implements HttpHandler {
@Override
public void handle(HttpExchange exchange) throws IOException {
Helper.pageNotFound(exchange);
}
}
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