From f4f07806a66cbd48d65857786de9944967f18161 Mon Sep 17 00:00:00 2001 From: Sam Sorensen <825813+sabrsorensen@users.noreply.github.com> Date: Sun, 5 Feb 2023 19:14:35 -0700 Subject: [PATCH 1/6] Added mtnclock support for reading weather.json This allows the use of owmweather or weather to provide weather updates to mtnclock. --- apps/mtnclock/app.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/mtnclock/app.js b/apps/mtnclock/app.js index 28ba25882..dedf60cfd 100644 --- a/apps/mtnclock/app.js +++ b/apps/mtnclock/app.js @@ -323,6 +323,11 @@ function setWeather() { draw(a); } +function readWeather() { + data = require("Storage").readJSON('weather.json').weather; + require("Storage").write('mtnclock.json', data); +} + const _GB = global.GB; global.GB = (event) => { if (event.t==="weather") { @@ -340,6 +345,7 @@ function queueDraw() { if (drawTimeout) clearTimeout(drawTimeout); drawTimeout = setTimeout(function() { drawTimeout = undefined; + readWeather(); setWeather(); queueDraw(); }, 60000 - (Date.now() % 60000)); From 5c3b742a4275361656b734cda6037e2d68a4be25 Mon Sep 17 00:00:00 2001 From: Sam Sorensen <825813+sabrsorensen@users.noreply.github.com> Date: Sun, 5 Feb 2023 20:18:37 -0700 Subject: [PATCH 2/6] Prevent exceptions if weather.json doesn't exist. --- apps/mtnclock/app.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/apps/mtnclock/app.js b/apps/mtnclock/app.js index dedf60cfd..82d06e03b 100644 --- a/apps/mtnclock/app.js +++ b/apps/mtnclock/app.js @@ -324,8 +324,13 @@ function setWeather() { } function readWeather() { - data = require("Storage").readJSON('weather.json').weather; - require("Storage").write('mtnclock.json', data); + var weatherData = require("Storage").readJSON('weather.json', true); + if (weatherData !== undefined) { + if (weatherData.weather.time > data.time) { + data = weatherData.weather; + require("Storage").write('mtnclock.json', data); + } + } } const _GB = global.GB; From 3371f86bb5b8335d4d312ce7ca1d8ce967fc818b Mon Sep 17 00:00:00 2001 From: Sam Sorensen <825813+sabrsorensen@users.noreply.github.com> Date: Sun, 5 Feb 2023 21:39:43 -0700 Subject: [PATCH 3/6] Save minimal weather data and limit weather update frequency --- apps/mtnclock/app.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/apps/mtnclock/app.js b/apps/mtnclock/app.js index 82d06e03b..996fe2cee 100644 --- a/apps/mtnclock/app.js +++ b/apps/mtnclock/app.js @@ -324,19 +324,26 @@ function setWeather() { } function readWeather() { - var weatherData = require("Storage").readJSON('weather.json', true); - if (weatherData !== undefined) { - if (weatherData.weather.time > data.time) { - data = weatherData.weather; - require("Storage").write('mtnclock.json', data); - } + var weatherJson = require("Storage").readJSON('weather.json', 1); + // save updated weather data if available and it has been an hour since last updated + if (weatherJson !== undefined && (data.time === undefined || (data.time + 3600000) < weatherJson.weather.time)) { + data = { + time: weatherJson.weather.time, + temp: weatherJson.weather.temp, + code: weatherJson.weather.code + }; + require("Storage").writeJSON('mtnclock.json', data); } } const _GB = global.GB; global.GB = (event) => { if (event.t==="weather") { - data = event; + data = { + temp: event.temp, + code: event.code, + time: Date.now() + }; require("Storage").write('mtnclock.json', event); setWeather(); } @@ -357,5 +364,6 @@ function queueDraw() { } queueDraw(); +readWeather(); setWeather(); Bangle.setUI("clock"); From 653756c9172976d10a8098e780db694c1a231f49 Mon Sep 17 00:00:00 2001 From: Sam Sorensen <825813+sabrsorensen@users.noreply.github.com> Date: Sun, 5 Feb 2023 21:48:53 -0700 Subject: [PATCH 4/6] Updated version and README --- apps/mtnclock/README.md | 2 +- apps/mtnclock/metadata.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/mtnclock/README.md b/apps/mtnclock/README.md index 58538509d..066230d4e 100644 --- a/apps/mtnclock/README.md +++ b/apps/mtnclock/README.md @@ -4,7 +4,7 @@ Based on the Pebble watchface Weather Land. Mountain Pass Clock changes depending on time (day/night) and weather conditions. -This clock requires Gadgetbridge and an app that Gadgetbridge can use to get the current weather from OpenWeatherMap (e.g. Weather Notification). To set up Gadgetbridge and weather, see https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather. +This clock requires Gadgetbridge and an app that Gadgetbridge can use to get the current weather from OpenWeatherMap (e.g. Weather Notification), or a Bangle app that will update weather.kson such as OWM Weather. To set up Gadgetbridge and weather, see https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather. The scene will change according to the following OpenWeatherMap conditions: clear, cloudy, overcast, lightning, drizzle, rain, fog and snow. Each weather condition has night/day scenes. diff --git a/apps/mtnclock/metadata.json b/apps/mtnclock/metadata.json index a3a173069..82a0cccab 100644 --- a/apps/mtnclock/metadata.json +++ b/apps/mtnclock/metadata.json @@ -2,7 +2,7 @@ "id": "mtnclock", "name": "Mountain Pass Clock", "shortName": "Mtn Clock", - "version": "0.01", + "version": "0.02", "description": "A clock that changes scenery based on time and weather.", "readme":"README.md", "icon": "app.png", From 959e376f099fce0dedca47b43ff97c970c2f5637 Mon Sep 17 00:00:00 2001 From: Sam Sorensen <825813+sabrsorensen@users.noreply.github.com> Date: Sun, 5 Feb 2023 21:57:52 -0700 Subject: [PATCH 5/6] Fixed typo --- apps/mtnclock/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mtnclock/README.md b/apps/mtnclock/README.md index 066230d4e..441754b83 100644 --- a/apps/mtnclock/README.md +++ b/apps/mtnclock/README.md @@ -4,7 +4,7 @@ Based on the Pebble watchface Weather Land. Mountain Pass Clock changes depending on time (day/night) and weather conditions. -This clock requires Gadgetbridge and an app that Gadgetbridge can use to get the current weather from OpenWeatherMap (e.g. Weather Notification), or a Bangle app that will update weather.kson such as OWM Weather. To set up Gadgetbridge and weather, see https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather. +This clock requires Gadgetbridge and an app that Gadgetbridge can use to get the current weather from OpenWeatherMap (e.g. Weather Notification), or a Bangle app that will update weather.json such as OWM Weather. To set up Gadgetbridge and weather, see https://codeberg.org/Freeyourgadget/Gadgetbridge/wiki/Weather. The scene will change according to the following OpenWeatherMap conditions: clear, cloudy, overcast, lightning, drizzle, rain, fog and snow. Each weather condition has night/day scenes. From b2b299efc35e80ef23e07e22df62ed3e6abc38ee Mon Sep 17 00:00:00 2001 From: Sam Sorensen <825813+sabrsorensen@users.noreply.github.com> Date: Sun, 5 Feb 2023 21:59:29 -0700 Subject: [PATCH 6/6] Updated minimal weather data save from GB --- apps/mtnclock/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/mtnclock/app.js b/apps/mtnclock/app.js index 996fe2cee..c6adc7706 100644 --- a/apps/mtnclock/app.js +++ b/apps/mtnclock/app.js @@ -344,7 +344,7 @@ global.GB = (event) => { code: event.code, time: Date.now() }; - require("Storage").write('mtnclock.json', event); + require("Storage").writeJSON('mtnclock.json', data); setWeather(); } if (_GB) setTimeout(_GB, 0, event);