Get initial archive data on connect

This commit is contained in:
2025-02-24 12:07:19 +00:00
parent d49c2f3472
commit b3c49d4116
2 changed files with 64 additions and 15 deletions

View File

@@ -71,8 +71,6 @@ line-height:140%;
}
#windSpeed {
# background-color: #f1f1f1;
# border-radius: 15px;
font-family: 'andale mono', monospace;
font-size: 48pt;
width: 300px;
@@ -82,8 +80,6 @@ line-height:140%;
}
#avgWindSpeed {
# background-color: #f1f1f1;
# border-radius: 15px;
font-family: 'andale mono', monospace;
font-size: 48pt;
width: 300px;
@@ -136,8 +132,6 @@ line-height:140%;
console.log("AVG Speed " + loopObj.windSpeed_knot);
console.log("AVG Dir " + loopObj.windDir);
console.log(loopObj);
//var audio = new Audio('BPCBeep.mp3');
//audio.play();
lastAvgWind = Date.now();
avgWindValid = 1;
avgWindSpeed = Number(loopObj.windSpeed_knot).toFixed(0);
@@ -153,8 +147,6 @@ line-height:140%;
if (loopObj.windSpeed_knot) {
lastWind = Date.now();
windValid = 1;
console.log("LOOP Speed " + loopObj.windSpeed_knot);
console.log("LOOP Dir " + loopObj.windDir);
instantWindSpeed = Number(loopObj.windSpeed_knot).toFixed(0);
roundedWind = (Math.round(loopObj.windDir / 10) * 10).toFixed(0);
zeroFilledDir = ('000' + roundedWind).substr(-3);
@@ -169,6 +161,27 @@ line-height:140%;
}
function getInitialArchive() {
fetch(`archive.php`)
.then(response => response.json())
.then(archive => {
let now = Math.floor(Date.now() / 1000);
if (now - archive.dateTime > 300) {
console.log("Archive record too old");
} else {
document.getElementById("OAT").innerHTML = Number((archive.outTemp - 32) * 5 / 9).toFixed(0) + " °C";
avgWindSpeed = (archive.windSpeed * 0.868976).toFixed(0);
avgWindGustSpeed = (archive.windGust * 0.868976).toFixed(0);
roundedWind = (Math.round(archive.windDir / 10) * 10).toFixed(0);
avgWindDir = ('000' + roundedWind).substr(-3);
roundedWind = (Math.round(archive.windGustDir / 10) * 10).toFixed(0);
avgWindGustDir = ('000' + roundedWind).substr(-3);
avgWindValid = 1;
updateAvgWind();
}
})
}
function updateStatus() {
if (avgWindValid == 1 && windValid == 1) {
document.getElementById("status").style.backgroundColor = '#00AA00';
@@ -262,11 +275,6 @@ line-height:140%;
return false;
}
// TODO: This is all a bit rough and ready. The station ID is hardcoded and so are the sensor IDs
// It should really look these up each time
//
// Also what I thought was QNH is actually QFE
async function getPressure() {
const response = await fetch('/wlproxy.php?api=current/195562');
@@ -496,11 +504,10 @@ let windDirection = 0; // Initial wind direction in degrees
invalidateDisplay();
MQTTconnect();
getPressure();
getInitialArchive();
updateClock();
// Initial draw
drawCompass();
// Example: Update wind direction dynamically every 2 seconds
</script>