Skip to content

Commit

Permalink
working on the webserver
Browse files Browse the repository at this point in the history
f****ing alpinejs
  • Loading branch information
StefanoTesla committed May 7, 2024
1 parent 6aa7f31 commit b0c14f1
Show file tree
Hide file tree
Showing 22 changed files with 212 additions and 103 deletions.
Binary file modified data/assets/style.0c6554fa.js.gz
Binary file not shown.
Binary file removed data/assets/style.b277fe7d.css.gz
Binary file not shown.
Binary file added data/assets/style.c7102921.css.gz
Binary file not shown.
Binary file removed data/assets/style.d068d487.css.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion data/ccalibconfig.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{"pin":2}
Binary file modified data/index.html.gz
Binary file not shown.
Binary file modified data/setup.html.gz
Binary file not shown.
44 changes: 16 additions & 28 deletions html_pages/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ <h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1>
x-data="globalData()"
>
<!--DOME-->
<template x-if="exist.dome">
<div class="main-tab bg-slate-600"
x-data="{open:false}"
>
Expand All @@ -76,9 +77,9 @@ <h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1>
<template x-if="dome.lastCommand === 3"><p>HALT</p></template>
</div>
<div class="grid grid-flow-row grid-rows-3 mx-auto gap-10 pt-6">
<button @click="openShutter" class="px-12 py-2 bg-green-600 w-full" >Apri</button>
<button @click="closeShutter" class="px-12 py-2 bg-red-600 w-full">Chiudi</button>
<button @click="haltShutter" class="text-black font-bold px-12 py-2 bg-yellow-300 w-full">HALT</button>
<button @click="shutterCmd(1)" class="px-12 py-2 bg-green-600 w-full" >Apri</button>
<button @click="shutterCmd(2)" class="px-12 py-2 bg-red-600 w-full">Chiudi</button>
<button @click="shutterCmd(3)" class="text-black font-bold px-12 py-2 bg-yellow-300 w-full">HALT</button>
</div>
<template x-if="dome.error == 1">
<div class="message message-ok">Command Send Succesfully!!</div>
Expand All @@ -90,6 +91,7 @@ <h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1>
</div>

</div>
</template>

<!-- COVER CALIBRATOR -->
<div class="main-tab bg-slate-600"
Expand Down Expand Up @@ -154,20 +156,19 @@ <h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1>
</div>

<p>Valore Attuale:</p>
<template x-if="swi.type == 1">
<template x-if="swi.type >= 2">
<div class="flex w-full flex-col justify-around ">
<p class="font-semibold" x-text="swi.actualValue"></p>
<p>Min: <span x-text="swi.actualValue"></span> Max: <span x-text="swi.max"></span></p>
</div>

</template>

<template x-if="swi.type == 0">
<template x-if="swi.type <= 1">
<div class="w-full">
<div x-show="swi.actualValue" class="card_actual_value bg-green-600">ON</div>
<div x-show="!swi.actualValue" class="card_actual_value bg-red-600">OFF</div>
</div>

</template>


Expand Down Expand Up @@ -299,47 +300,34 @@ <h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1>
if(this.exist.dome || this.exist.switch || this.exist.coverc){ this.getDomeData() }
})
.catch(error => console.log(error))
.finally(() => setInterval(() => this.updateData(), 10000));
.finally(() => setInterval(() => this.updateData(), 30000));
},

init() {
this.initData();
},

openShutter(){
fetch('/api/dome/cmd?cmd=1',{ method: 'PUT'})
.then(response => response.json())
.then(response => {
this.dome.error = response.error;
});
},

closeShutter(){
fetch('/api/dome/cmd?cmd=2',{ method: 'PUT'})
.then(response => response.json())
.then(response => {
this.dome.error = response.error;
});
},

haltShutter(){
fetch('/api/dome/cmd?cmd=3',{ method: 'PUT'})
shutterCmd(cmd){
//1 apertura
//2 chiusura
//3 halt
fetch('/api/dome-cmd?cmd='+cmd,{ method: 'PUT'})
.then(response => response.json())
.then(response => {
this.dome.error = response.error;
});
},

coverCmd(value){
fetch('http://172.20.10.5/api/coverc/cmd?value='+value,{ method: 'PUT'})
fetch('/api/coverc-cmd?value='+value,{ method: 'PUT'})
.then(response => response.json())
.then(response => {
this.cover.error = response.error;
});
},

setDigitalSwValue(id,value){
fetch('http://172.20.10.5/api/switch/cmd?id='+id+'&value='+value,{ method: 'PUT'})
fetch('/api/switch-cmd?id='+id+'&value='+value,{ method: 'PUT'})
.then(response => response.json())
.then(response => {
if (response.done){
Expand All @@ -351,7 +339,7 @@ <h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1>
});
},
setAnalogSwValue(id,event){
fetch('/api/switch/cmd?id='+id+'&value='+event.target.value,{ method: 'PUT'})
fetch('/api/switch-cmd?id='+id+'&value='+event.target.value,{ method: 'PUT'})
.then(response => response.json())
.then(response => {
if (response.done){
Expand Down
129 changes: 84 additions & 45 deletions html_pages/setup.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<div class=""><h1 class="text-center text-xl">StefanoTesla Dome&Switch</h1></div>
<div x-data="globalData()">
<!--DOME-->
<template x-if="exist.dome">
<div class="main-tab bg-slate-600"
x-data="{open:false}"
>
Expand Down Expand Up @@ -75,32 +76,36 @@
</div>

</div>

</template>
<!--DOME-->
<div class="main-tab bg-slate-600"
x-data="{open:false}"
>

<div class="tab-header" >
<div class="grow">Cover Calibration</div>
<div><button @click="open = ! open"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" stroke="#fff" fill="#fff"><path d="M12 3v2h5.586L5 17.586V12H3v9h9v-2H6.414L19 6.414V12h2V3h-9z"/></svg></button></div>
</div>
<!-- COVER CALIBRATOR -->
<template x-if="exist.coverc">
<div class="main-tab bg-slate-600"
x-data="{open:false}"
>

<div class="tab-content" x-show="open" x-transition>
<div>
<p>Pin: <input x-on:change="validatePinNumber($event)" type="number" id="coverpin" class="bg-gray-100 p-2 text-gray-800 h-5" x-model="cover.pin"/></p>
</div>
<div class="tab-header" >
<div class="grow">Cover Calibration</div>
<div><button @click="open = ! open"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" stroke="#fff" fill="#fff"><path d="M12 3v2h5.586L5 17.586V12H3v9h9v-2H6.414L19 6.414V12h2V3h-9z"/></svg></button></div>
</div>

<div class="pt-2">
<button @click="saveCoverSetting()" class="button button_green">Salva</button>
<a href="/ccalibconfig.txt" download class="button button_green">Scarica Configurazione</a>
<div class="tab-content" x-show="open" x-transition>
<div>
<p>Pin: <input x-on:change="validatePinNumber($event)" type="number" id="coverpin" class="bg-gray-100 p-2 text-gray-800 h-5" x-model="cover.pin"/></p>
</div>

</div>
<div class="pt-2">
<button @click="saveCoverSetting()" class="button button_green">Salva</button>
<a href="/ccalibconfig.txt" download class="button button_green">Scarica Configurazione</a>
</div>

</div>
</div>

</div>
</template>
<!--SWITCH-->
<template x-if="exist.switch">
<div class="main-tab bg-slate-600"
x-data="{open:false}">

Expand Down Expand Up @@ -141,6 +146,33 @@
</div>
</div>
</div>
</template>
<!-- Ascom-->

<div class="main-tab bg-slate-600"
x-data="{open:false}"
>

<div class="tab-header" >
<div class="grow">Ascom Alpaca</div>
<div><button @click="open = ! open"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" stroke="#fff" fill="#fff"><path d="M12 3v2h5.586L5 17.586V12H3v9h9v-2H6.414L19 6.414V12h2V3h-9z"/></svg></button></div>
</div>

<div class="tab-content" x-show="open" x-transition>
<div>
<p>Remote port is usually 32227! if you changed from Ascom software, you know the port you need!<br> Alpaca port is the port from the request will arrived and sended from this borad to the remote port.<br>Change this setting only if you really need it.<br></p>
<p>Remote Port: <input type="number" id="ascomremotePort" class="bg-gray-100 p-2 text-gray-800 h-5" x-model="board.remotePort"/></p>
<p>Alpaca Port: <input type="number" id="ascomboardPort" class="bg-gray-100 p-2 text-gray-800 h-5" x-model="board.alpacaPort"/></p>
</div>

<div class="pt-2">
<button @click="saveBoardSetting()" class="button button_green">Salva</button>
<a href="/config.txt" download class="button button_green">Scarica Configurazione</a>
</div>

</div>
</div>


<template x-if="relodRequest">
<div class="fixed top-0 left-0 h-full w-full backdrop-blur-sm flex align-middle items-center">
Expand Down Expand Up @@ -184,16 +216,20 @@
<script>
function globalData() {
return {
exist: {switch:false,dome:false,coverc:false},
board: [],
dome: [],
cover: [],
switches : [],
relodRequest : 0,
pinIdError:0,
notices: [],
visible: [],
unusablePinForInput: [6,7,8,9,10,11,20,21,24,28,29,30,31,37,38],
unusablePinForOutput: [6,7,8,9,10,11,20,21,24,28,29,30,31,34,35,36,37,38,39],
unusablePinForInput: [0,6,7,8,9,10,11,20,21,24,28,29,30,31,37,38],
unusablePinForOutput: [0,6,7,8,9,10,11,20,21,24,28,29,30,31,34,35,36,37,38,39],
ports: [80,443,43,3389,21,22],
reload() {
this.board = [],
this.dome = [];
this.switches = [];
this.cover = [];
Expand All @@ -204,15 +240,15 @@
},

getDomeConfig(){
fetch('http://172.20.10.5/api/dome/getconfig')
fetch('http://172.20.10.5/api/dome-getconfig')
.then(response => response.json())
.then(response => {
this.dome = response.dome;
});
},

getSwitchConfig(){
fetch('http://172.20.10.5/api/switch/getconfig')
fetch('http://172.20.10.5/api/switch-getconfig')
.then(response => response.json())
.then(response => {
response.switches.forEach((element,index) => (
Expand All @@ -222,17 +258,23 @@
},

getCoverCConfig(){
fetch('http://172.20.10.5/api/coverc/getconfig')
fetch('http://172.20.10.5/api/coverc-getconfig')
.then(response => response.json())
.then(response => {
this.cover = response.cover;
});
},

updateData(){
this.getDomeConfig();
this.getSwitchConfig();
this.getCoverCConfig();
fetch('http://172.20.10.5/get-config')
.then(response => response.json())
.then(response => {
this.board.remotePort = response.alpRemPort;
this.board.alpacaPort = response.alpPort;
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()}
});
},

init() {this.updateData()},
Expand Down Expand Up @@ -268,7 +310,7 @@
this.addToast({type:"error", text:"Dome Validation Error, PIN " + this.dome.pinhalt + " NON UTILIZZABILE come Output"});
return;
}
fetch('http://172.20.10.5/api/dome/saveconfig',{
fetch('http://172.20.10.5/api/dome-saveconfig',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.dome)
Expand All @@ -282,7 +324,7 @@
this.addToast({type:"error", text:"CoverCalib Validation Error, PIN " + this.cover.pin + " NON UTILIZZABILE come Output"});
return;
}
fetch('/coverconfig',{
fetch('http://172.20.10.5/api/coverc-setconfig',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.cover)
Expand All @@ -291,31 +333,28 @@
.then(response => { if (response.reboot){this.pageRefresh();}});
},
savePinSetting(){
let error;
let validation = JSON.parse(JSON.stringify(this.switches));
for(let i=0; i < validation.length; i++){
let y;
y = i+1;
if(validation[i].type==0 || validation[i].type>4){
this.addToast({type:"error", text:"SWITCH " + y + " - TIPO ERRATO"})
}
if(validation[i].type==1 || validation[i].type==3 && this.unusablePinForOutput.includes(validation[i].pin) ){
this.addToast({type:"error", text:"SWITCH " + y + " - pin non utilizzabile come uscita"})
}
if(validation[i].type==2 && this.unusablePinForInput.includes(validation[i].pin) ){
this.addToast({type:"error", text:"SWITCH " + y + " - pin non utilizzabile come ingresso"})
}
}

if(error){ this.addToast({type:"error", text:"Errore di Validazione"}); return; }
fetch('http://172.20.10.5/api/switch/saveconfig',{
fetch('http://172.20.10.5/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();}});
},


saveBoardSetting(){
fetch('http://172.20.10.5/api/switch-saveconfig',{
method: 'POST',
headers: {"Content-Type": "application/json",},
body: JSON.stringify(this.board)
})
.then(response => response.json())
.then(response => { if (response.reboot){this.pageRefresh();}});
},



addPin(){if(this.switches.length < 16){ this.switches.push({name: '',desc: '',type: 0,pin: 0});} else { console.error("Limite Raggiunto")}},
removePin(index) {this.switches.splice(index, 1);},

Expand Down
4 changes: 3 additions & 1 deletion src/Alpaca/alpacamanagefunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ void GetAlpArguments(AsyncWebServerRequest *request ) {
AlpacaData.switches.state = false;
AlpacaData.switches.intValue = -1;
AlpacaData.coverC.brightness = -1;
AlpacaData.LastServerRequest = millis();
#ifdef DOME
Dome.lastCommunicationMillis = millis();
#endif
int paramsNr = request->params();
String parameter;
AlpacaData.serverTransactionID++;
Expand Down
5 changes: 4 additions & 1 deletion src/CoverC/cover.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@ void saveCoverCConfig(){
void coverCLoop(){

coverC.actualValue = ledcRead(0);
if (coverC.actualValue != coverC.cmdValue){
if (coverC.cmdValue >= 0){
Serial.print("cover new value ");
Serial.println(coverC.cmdValue);
ledcWrite(0 ,coverC.cmdValue);
coverC.cmdValue = -1;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/CoverC/coverVariable.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

struct coverCStruct{
unsigned int actualValue;
unsigned int cmdValue;
int cmdValue = -1;
};

coverCStruct coverC;
Expand Down
Loading

0 comments on commit b0c14f1

Please sign in to comment.