Fix save function to persist config to flash

- Add psave:true flag to trigger WLED config save
- Explicitly list all curve point fields instead of loop
- Better error handling in save function
This commit is contained in:
dawie 2026-01-30 19:34:26 +02:00
parent 7816ecf949
commit fdcd26b3ce

View File

@ -62,7 +62,7 @@ table input{width:50px;padding:4px;border:1px solid var(--acc);border-radius:3px
<div class="card">
<h2>Status</h2>
<div class="grid">
<div class="stat"><div class="val t-val" id="temp">--</div><div class="lbl">Temp °C</div></div>
<div class="stat"><div class="val t-val" id="temp">--</div><div class="lbl">Temp C</div></div>
<div class="stat"><div class="val s-val" id="speed">--</div><div class="lbl">Fan %</div></div>
<div class="stat"><div class="val m-val" id="mode">--</div><div class="lbl">Mode</div></div>
<div class="stat"><div class="val" id="status" style="color:var(--ok)">&#9679;</div><div class="lbl" id="stxt">OK</div></div>
@ -312,18 +312,57 @@ document.getElementById('stxt').textContent='Err';
async function save(){
pts.sort((a,b)=>a.t-b.t);
let cfg={'GPU-Fan':{enabled:true,mode:cMode,'fixed-speed':fSpd,'curve-points':pts.length}};
for(let i=0;i<5;i++){
cfg['GPU-Fan']['curve-t'+(i+1)]=i<pts.length?pts[i].t:50;
cfg['GPU-Fan']['curve-s'+(i+1)]=i<pts.length?pts[i].s:50;
}
// Build the config object
let cfg={'GPU-Fan':{
enabled:true,
mode:cMode,
'fixed-speed':fSpd,
'curve-points':pts.length,
'curve-t1':pts.length>0?pts[0].t:30,
'curve-s1':pts.length>0?pts[0].s:30,
'curve-t2':pts.length>1?pts[1].t:50,
'curve-s2':pts.length>1?pts[1].s:50,
'curve-t3':pts.length>2?pts[2].t:70,
'curve-s3':pts.length>2?pts[2].s:75,
'curve-t4':pts.length>3?pts[3].t:85,
'curve-s4':pts.length>3?pts[3].s:100,
'curve-t5':pts.length>4?pts[4].t:95,
'curve-s5':pts.length>4?pts[4].s:100
}};
try{
let r=await fetch('/cfg.json',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({um:cfg})});
if(r.ok){
// First update the config
let r1=await fetch('/cfg.json',{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({um:cfg})
});
if(!r1.ok){
toast('Config update failed',1);
return;
}
// Then trigger a config save by posting to /json with save flag
let r2=await fetch('/json/state',{
method:'POST',
headers:{'Content-Type':'application/json'},
body:JSON.stringify({
psave:true,
'GPU-Fan':{mode:cMode}
})
});
if(r2.ok){
toast('Saved!');
fetch('/json/state',{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({'GPU-Fan':{mode:cMode}})});
}else toast('Fail',1);
}catch(e){toast('Err',1)}
}else{
toast('Save failed',1);
}
}catch(e){
console.error(e);
toast('Error: '+e.message,1);
}
}
function toast(m,e){
@ -336,4 +375,4 @@ setTimeout(()=>t.classList.remove('show'),2000);
</script>
</body>
</html>
)=====";
)=====";