Save minimal weather data and limit weather update frequency

master
Sam Sorensen 2023-02-05 21:39:43 -07:00
parent 5c3b742a42
commit 3371f86bb5
1 changed files with 15 additions and 7 deletions

View File

@ -324,19 +324,26 @@ function setWeather() {
} }
function readWeather() { function readWeather() {
var weatherData = require("Storage").readJSON('weather.json', true); var weatherJson = require("Storage").readJSON('weather.json', 1);
if (weatherData !== undefined) { // save updated weather data if available and it has been an hour since last updated
if (weatherData.weather.time > data.time) { if (weatherJson !== undefined && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) {
data = weatherData.weather; data = {
require("Storage").write('mtnclock.json', data); time: weatherJson.weather.time,
} temp: weatherJson.weather.temp,
code: weatherJson.weather.code
};
require("Storage").writeJSON('mtnclock.json', data);
} }
} }
const _GB = global.GB; const _GB = global.GB;
global.GB = (event) => { global.GB = (event) => {
if (event.t==="weather") { if (event.t==="weather") {
data = event; data = {
temp: event.temp,
code: event.code,
time: Date.now()
};
require("Storage").write('mtnclock.json', event); require("Storage").write('mtnclock.json', event);
setWeather(); setWeather();
} }
@ -357,5 +364,6 @@ function queueDraw() {
} }
queueDraw(); queueDraw();
readWeather();
setWeather(); setWeather();
Bangle.setUI("clock"); Bangle.setUI("clock");