Initial proof of concept

pull/1969/head
Martin Boonk 2022-06-16 17:23:02 +02:00
parent 72f5769486
commit 8e788a608a
5 changed files with 100 additions and 0 deletions

View File

@ -0,0 +1 @@
0.01: New App!

25
apps/owmweather/README.md Normal file
View File

@ -0,0 +1,25 @@
# App Name
Describe the app...
Add screen shots (if possible) to the app folder and link then into this file with ![](<name>.png)
## Usage
Describe how to use it
## Features
Name the function
## Controls
Name the buttons and what they are used for
## Requests
Name who should be contacted for support/update requests
## Creator
Your name

BIN
apps/owmweather/app.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

60
apps/owmweather/boot.js Normal file
View File

@ -0,0 +1,60 @@
(function() {
let settings = require("Storage").readJSON("owmweather.json",1)||{enabled:false};
console.log("Settings", settings);
if (settings.enabled && settings.apikey){
let location = require("Storage").readJSON("mylocation.json",1)||{"lat":51.50,"lon":0.12,"location":"London"};
function pullWeather() {
console.log("pull weather");
Bluetooth.println(JSON.stringify({
t: "http",
url: "https://api.openweathermap.org/data/2.5/weather?lat=" + location.lat.toFixed(2) + "&lon=" + location.lon.toFixed(2) + "&exclude=hourly,daily&appid=" + settings.apikey
}));
}
function parseWeather(event) {
let owmData = JSON.parse(event.resp);
console.log("OWM Data", owmData);
let isOwmData = owmData.coord && owmData.weather && owmData.main;
if (isOwmData) {
console.log("Converting data");
let json = require("Storage").readJSON('weather.json') || {};
let weather = {};
weather.time = Date.now();
weather.hum = owmData.main.humidity;
weather.temp = owmData.main.temp;
weather.code = owmData.weather[0].id;
weather.wdir = owmData.wind.deg;
weather.wind = owmData.wind.speed;
weather.loc = owmData.name;
weather.txt = owmData.weather[0].main;
if (weather.wdir != null) {
let deg = weather.wdir;
while (deg < 0 || deg > 360) {
deg = (deg + 360) % 360;
}
weather.wrose = ['n', 'ne', 'e', 'se', 's', 'sw', 'w', 'nw', 'n'][Math.floor((deg + 22.5) / 45)];
}
json.weather = weather;
require("Storage").writeJSON('weather.json', json);
require("weather").emit("update", json.weather);
}
}
const _GB = global.GB;
global.GB = (event) => {
if (event.t==="http") parseWeather(event);
if (_GB) setTimeout(_GB, 0, event);
};
console.log("Setting interval");
setInterval(()=>{
pullWeather();
}, settings.refresh * 1000 * 60);
pullWeather();
}
})();

View File

@ -0,0 +1,14 @@
{ "id": "owmweather",
"name": "openweathermap weather provider",
"shortName":"OWM Weather",
"version":"0.01",
"description": "A detailed description of my great app",
"icon": "app.png",
"type": "bootloader",
"tags": "boot,tool,weather",
"supports" : ["BANGLEJS2"],
"readme": "README.md",
"storage": [
{"name":"owmweather.boot.js","url":"boot.js"}
]
}