@@ -240,7 +241,7 @@
},
getDomeConfig(){
- fetch('http://172.20.10.5/api/dome-getconfig')
+ fetch('/api/dome-getconfig')
.then(response => response.json())
.then(response => {
this.dome = response.dome;
@@ -248,7 +249,8 @@
},
getSwitchConfig(){
- fetch('http://172.20.10.5/api/switch-getconfig')
+ this.switches = []
+ fetch('/api/switch-getconfig')
.then(response => response.json())
.then(response => {
response.switches.forEach((element,index) => (
@@ -258,7 +260,7 @@
},
getCoverCConfig(){
- fetch('http://172.20.10.5/api/coverc-getconfig')
+ fetch('/api/coverc-getconfig')
.then(response => response.json())
.then(response => {
this.cover = response.cover;
@@ -266,11 +268,10 @@
},
updateData(){
- fetch('http://172.20.10.5/get-config')
+ fetch('/get-config')
.then(response => response.json())
.then(response => {
- this.board.remotePort = response.alpRemPort;
- this.board.alpacaPort = response.alpPort;
+ this.board = response.board;
if (response.dome) { this.exist.dome = true,this.getDomeConfig()}
if (response.switch) {this.exist.switch = true,this.getSwitchConfig()}
if (response.cover) {this.exist.coverc = true,this.getCoverCConfig()}
@@ -282,11 +283,12 @@
validatePinNumber(event){
let ionumber = parseInt(event.target.value);
if (this.unusablePinForInput.includes(ionumber)){
- this.addToast({type:"error", text:"PIN " + ionumber + " NON UTILIZZABILE"})
+ this.addToast({type:"error", text:"PIN " + ionumber + " UNUSABLE"})
} else if (this.unusablePinForOutput.includes(ionumber)){
- this.addToast({type:"info", text:"Il pin: " + ionumber + " non può essere utilizzato come uscita (solo avvertimento)"})
+ this.addToast({type:"info", text:"The pin: " + ionumber + " cannot be used as output (warning)"})
}
},
+
saveDomeSetting(){
this.dome.autoclose = parseInt(this.dome.autoclose);
this.dome.tout = parseInt(this.dome.tout);
@@ -295,77 +297,118 @@
this.dome.pinclose = parseInt(this.dome.pinclose);
this.dome.pinopen = parseInt(this.dome.pinopen);
if(this.unusablePinForInput.includes(this.dome.pinopen)){
- this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinopen + " NON UTILIZZABILE come Input"});
+ this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinopen + "cannot be used as input"});
return;
}
if(this.unusablePinForInput.includes(this.dome.pinclose)){
- this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinclose + " NON UTILIZZABILE come Input"});
+ this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinclose + " cannot be used as input"});
return;
}
if(this.unusablePinForOutput.includes(this.dome.pinstart)){
- this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinstart + " NON UTILIZZABILE come Output"});
+ this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinstart + " cannot be used as output"});
return;
}
if(this.unusablePinForOutput.includes(this.dome.pinhalt)){
- this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinhalt + " NON UTILIZZABILE come Output"});
+ this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinhalt + " cannot be used as output"});
return;
}
- fetch('http://172.20.10.5/api/dome-saveconfig',{
+ fetch('/api/dome-saveconfig',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.dome)
})
.then(response => response.json())
- .then(response => { if (response.reboot){this.pageRefresh();}});
+ .then(response => { if (response.reboot){this.pageRefresh();} else { this.getDomeConfig();this.addToast({type:"success", text:"Dome Saved."})}});
},
+
saveCoverSetting(){
this.cover.pin = parseInt(this.cover.pin);
if(this.unusablePinForOutput.includes(this.cover.pin)){
- this.addToast({type:"error", text:"CoverCalib Validation Error, PIN " + this.cover.pin + " NON UTILIZZABILE come Output"});
+ this.addToast({type:"error", text:"CoverCalib Validation Error, PIN " + this.cover.pin + " cannot be used as output"});
return;
}
- fetch('http://172.20.10.5/api/coverc-setconfig',{
+ fetch('/api/coverc-setconfig',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.cover)
})
.then(response => response.json())
- .then(response => { if (response.reboot){this.pageRefresh();}});
+ .then(response => {
+ if (response.reboot){
+ this.pageRefresh();
+ return
+ }
+ if (response.accept){
+ this.addToast({type:"success", text:"Cover Saved."})
+ }
+ });
},
+
savePinSetting(){
- fetch('http://172.20.10.5/api/switch-saveconfig',{
+ let error;
+
+ this.switches.forEach((element,index) => {
+
+ if(element.type===0 || element.type > 4){
+ setTimeout(() => {this.addToast({type:"error", text:"SWITCH " + index + " - WRONG TYPE"})}, 1);
+ error = true;
+ return
+ }
+
+ if((element.type===1 || element.type===3) && this.unusablePinForOutput.includes(parseInt(element.pin)) ){
+ error = true;
+ setTimeout(() => {this.addToast({type:"error", text:"SWITCH " + index + " - pin "+ element.pin +" cannot be used as output"})}, 1);
+ return
+ }
+
+ if (element.type === 2 && this.unusablePinForInput.includes(parseInt(element.pin)) ){
+ error = true;
+ setTimeout(() => {this.addToast({type:"error", text:"SWITCH " + index + " - pin "+ element.pin +" cannot be used as input"})}, 1);
+ return
+ }
+ })
+
+ if(error){
+ setTimeout(() => {this.addToast({type:"error", text:"SWITCH Validation Error"})}, 1);
+ return;
+ }
+ fetch('/api/switch-saveconfig',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.switches)
})
.then(response => response.json())
- .then(response => { if (response.reboot){this.pageRefresh();}});
+ .then(response => {
+ if (response.reboot){
+ this.pageRefresh();
+ }
+ if (response.accept){
+ this.getSwitchConfig();
+ this.addToast({type:"success", text:"Switch Saved."})
+ }
+ if (response.error){
+ this.getSwitchConfig();
+ this.addToast({type:"error", text:"Data not valid."})
+ }
+ });
},
-
saveBoardSetting(){
- fetch('http://172.20.10.5/api/switch-saveconfig',{
+
+ fetch('/save-config',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.board)
})
.then(response => response.json())
- .then(response => { if (response.reboot){this.pageRefresh();}});
+ .then(response => { if (response.reboot){this.pageRefresh();} else this.addToast({type:"info", text:"Saved."})});
},
- addPin(){if(this.switches.length < 16){ this.switches.push({name: '',desc: '',type: 0,pin: 0});} else { console.error("Limite Raggiunto")}},
+ addPin(){if(this.switches.length < 16){ this.switches.push({name: '',desc: '',type: 0,pin: 0});} else { this.addToast({type:"error", text:"CANNOT ADD MORE SWITCH"})}},
removePin(index) {this.switches.splice(index, 1);},
- ioPinError(io){
- pinError = 1;
- pinIdError = io;
- setTimeout(function(){
- pinError = 0;
- pinIdError = 0;
- }, 2000);
- },
pageRefresh(){
this.relodRequest = 1;
setTimeout(function(){
diff --git a/html_pages/style.css b/html_pages/style.css
index 672fe48..c26531f 100644
--- a/html_pages/style.css
+++ b/html_pages/style.css
@@ -29,6 +29,14 @@ h3,h4,h5,h6
@apply pt-10 pb-4 text-2xl font-bold;
}
+p{
+ @apply my-2
+}
+
+input{
+ @apply bg-gray-100 px-2 py-4 text-gray-800 h-5 rounded-sm focus:bg-slate-300 focus:border-blue-500
+}
+
.main-tab
{
@apply flex mx-auto mx-4 my-4 py-4 px-4 flex-col
@@ -51,9 +59,8 @@ h3,h4,h5,h6
}
.button{
- @apply px-5 py-2 rounded-sm
+ @apply px-5 py-2
}
-
.button_green
{
@apply bg-green-600
diff --git a/src/Alpaca/config.h b/src/Alpaca/config.h
new file mode 100644
index 0000000..542ce0e
--- /dev/null
+++ b/src/Alpaca/config.h
@@ -0,0 +1,26 @@
+#ifndef ALPACA_CONFIG
+#define ALPACA_CONFIG
+
+
+void initBoardConfig(){
+ JsonDocument doc;
+ File file = SPIFFS.open("/config.txt", FILE_READ);
+ if (!file) {
+ Serial.println("Reading Board config error");
+ return;
+ }
+ DeserializationError error = deserializeJson(doc, file);
+ if(error){
+ Serial.print(F("deserializeJson() failed: "));
+ Serial.println(error.c_str());
+ return;
+ }
+ Config.alpacaPort.remotePort = doc["alpRemPort"];
+ Config.alpacaPort.alpacaPort = doc["alpPort"];
+ Serial.println(Config.alpacaPort.remotePort);
+ Serial.println(Config.alpacaPort.alpacaPort);
+ file.close();
+ Config.read.dome.isValid = true;
+}
+
+#endif
\ No newline at end of file
diff --git a/src/CoverC/webserver.h b/src/CoverC/webserver.h
index fa07dc4..1b5404e 100644
--- a/src/CoverC/webserver.h
+++ b/src/CoverC/webserver.h
@@ -27,7 +27,7 @@ void coverCWebServer(){
JsonDocument doc;
doc = json.as();
if (Config.coverC.pin == doc["pin"]){
- request->send(200, "application/json", "{\"accept\": \"ok\"}");
+ request->send(200, "application/json", "{\"accept\": \"1\"}");
} else {
Config.coverC.pin = doc["pin"];
Config.save.coverC.execute = true;
diff --git a/src/Switches/webserver.h b/src/Switches/webserver.h
index d9a61d9..84b81ad 100644
--- a/src/Switches/webserver.h
+++ b/src/Switches/webserver.h
@@ -79,7 +79,7 @@ void switchWebServer(){
Config.save.switches.restartNeeded = true;
request->send(200, "application/json", "{\"reboot\": \"1\"}");
} else {
- request->send(200, "application/json", "{\"accept\": \"ok\"}");
+ request->send(200, "application/json", "{\"accept\": \"1\"}");
}
});
diff --git a/src/browserServer.h b/src/browserServer.h
index c20bc09..4372bab 100644
--- a/src/browserServer.h
+++ b/src/browserServer.h
@@ -18,10 +18,6 @@ void browserServer(){
request->send(SPIFFS, "/setup.html", "text/html");
});
- server.on("/setup.txt", HTTP_GET, [](AsyncWebServerRequest * request) {
- request->send(SPIFFS, "/setup.txt", "text/plain");
- });
-
server.on("/status", HTTP_GET, [](AsyncWebServerRequest *request) {
AsyncResponseStream *response = request->beginResponseStream("application/json");
response->printf("{");
@@ -78,23 +74,44 @@ void browserServer(){
#else
response->printf("0");
#endif
- response->printf(",\"alpRemPort\":");
+ response->printf(",\"board\":{\"alpRemPort\":");
response->print(Config.alpacaPort.remotePort);
response->printf(",\"alpPort\":");
response->print(Config.alpacaPort.alpacaPort);
- response->print("}");
+ response->print("}}");
request->send(response);
});
- AsyncCallbackJsonWebHandler *boardcfg = new AsyncCallbackJsonWebHandler("/set-config", [](AsyncWebServerRequest * request, JsonVariant & json) {
+ AsyncCallbackJsonWebHandler *boardcfg = new AsyncCallbackJsonWebHandler("/save-config", [](AsyncWebServerRequest * request, JsonVariant & json) {
+ bool reboot = false;
JsonDocument doc;
doc = json.as();
-
- request->send(200, "application/json", "{\"reboot\": \"1\"}");
-
+ int remPort = doc["alpRemPort"].as();
+ int alpacaPort = doc["alpPort"].as();
+
+ if (remPort > 500 && alpacaPort> 500){
+ if(Config.alpacaPort.remotePort != remPort){
+ reboot = true;
+ }
+ Config.alpacaPort.remotePort = remPort;
+ if(Config.alpacaPort.alpacaPort != alpacaPort){
+ reboot = true;
+ }
+ Config.alpacaPort.alpacaPort = alpacaPort;
+
+ Config.save.board.execute = true;
+ if (reboot){
+ request->send(200, "application/json", "{\"reboot\": \"1\"}");
+ } else {
+ request->send(200, "application/json", "{\"accept\": \"1\"}");
+ }
+ return;
+ }
+ request->send(200, "application/json", "{\"error\": \"1\"}");
});
server.addHandler(boardcfg);
-
+
+ server.serveStatic("/config.txt", SPIFFS, "/config.txt");
server.serveStatic("/favicon.ico", SPIFFS, "/favicon.ico").setCacheControl("max-age=31536000");
server.serveStatic("/assets/", SPIFFS, "/assets/").setCacheControl("max-age=31536000");
diff --git a/src/configuration.h b/src/configuration.h
index 60c168d..8262adf 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -1,31 +1,14 @@
#ifndef CONFIGURATION
#define CONFIGURATION
-void initBoardConfig(){
- JsonDocument doc;
- File file = SPIFFS.open("/config.txt", FILE_READ);
- if (!file) {
- Serial.println("Reading Board config error");
- return;
- }
- DeserializationError error = deserializeJson(doc, file);
- if(error){
- Serial.print(F("deserializeJson() failed: "));
- Serial.println(error.c_str());
- return;
- }
- Config.alpacaPort.remotePort = doc["alpacaremport"];
- Config.alpacaPort.alpacaPort = doc["alpacaboardport"];
- file.close();
- Config.read.dome.isValid = true;
-}
+
void saveBoardConfig(){
String datasetup;
JsonDocument doc;
- doc["alpacaremport"] = Config.alpacaPort.remotePort;
- doc["alpacaboardport"] = Config.alpacaPort.alpacaPort;
+ doc["alpRemPort"] = Config.alpacaPort.remotePort;
+ doc["alpPort"] = Config.alpacaPort.alpacaPort;
serializeJson(doc, datasetup);
File file = SPIFFS.open("/config.txt", FILE_WRITE);