-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemparature.js
30 lines (24 loc) · 1.23 KB
/
temparature.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Function to fetch data from the API
async function fetchData() {
try {
const response = await fetch("https://api.apispreadsheets.com/data/rF6K2wi7RT2S2Yql/");
const data = await response.json();
return data.data; // Assuming the JSON data is in data.data
} catch (error) {
console.error("Error fetching data:", error);
return [];
}
}
// Function to update the temperature gauge with the latest temperature
async function updateTemperature() {
const data = await fetchData();
const latestEntry = data[data.length - 1];
// Extract temperature from the latest entry
const temperature = latestEntry.Temperature;
// Display the temperature in the gauge
const temperatureGauge = document.getElementById('temperatureGauge');
temperatureGauge.textContent = temperature + "°C"; // Modify this to display in desired format
}
// Call the updateTemperature function initially and every 10 seconds
updateTemperature();
setInterval(updateTemperature, 60000); // Update every 10 seconds