Skip to content

Commit

Permalink
Add MET (UK) WOW Destination
Browse files Browse the repository at this point in the history
Closes #27
  • Loading branch information
leoherzog committed Sep 16, 2024
1 parent b39404d commit 374b0e3
Showing 1 changed file with 34 additions and 1 deletion.
35 changes: 34 additions & 1 deletion code.gs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ const updateWindGuru = false;
const windGuruStationUID = 'xxxxxxxxxx';
const windGuruStationPassword = 'xxxxxxxxxxxxxxxx';
///
const updateWOW = false;
const wowSiteID = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx';
const wowAuthKey = 'xxxxxx';
///
const updateCWOP = false;
const cwopStationIDOrHamCallsign = 'CW0001';
const cwopValidationCode = null;
Expand All @@ -75,7 +79,7 @@ const cwopValidationCode = null;
*/

let version = 'v2.7.1';
let version = 'v2.8.0';

function Schedule() {
ScriptApp.getProjectTriggers().forEach(trigger => ScriptApp.deleteTrigger(trigger));
Expand Down Expand Up @@ -115,6 +119,7 @@ function Schedule() {
if (updateWeatherCloud) ScriptApp.newTrigger('updateWeatherCloud_').timeBased().everyMinutes(hasWeatherCloudPro ? 1 : 10).create();
if (updateOpenWeatherMap) ScriptApp.newTrigger('updateOpenWeatherMap_').timeBased().everyMinutes(1).create();
if (updateWindGuru) ScriptApp.newTrigger('updateWindGuru_').timeBased().everyMinutes(1).create();
if (updateWOW) ScriptApp.newTrigger('updateWOW_').timeBased().everyMinutes(5).create();
if (updateCWOP) ScriptApp.newTrigger('updateCWOP_').timeBased().everyMinutes(5).create();
console.log('Scheduled! Check Executions ☰▶ tab for status.');
checkGithubReleaseVersion_();
Expand Down Expand Up @@ -1025,6 +1030,34 @@ function updateWindGuru_() {

}

// https://wow.metoffice.gov.uk/support/dataformats#automatic
function updateWOW_() {

let conditions = JSON.parse(CacheService.getScriptCache().get('conditions'));

let request = 'http://wow.metoffice.gov.uk/automaticreading?';
request += 'siteid=' + wowSiteID;
request += '&siteAuthenticationKey=' + wowAuthKey;
request += '&dateutc=' + encodeURIComponent(Utilities.formatDate(new Date(conditions.time), 'UTC', 'yyyy-MM-dd HH:mm:ss'));
if (conditions.temp != null) request += '&tempf=' + conditions.temp.f;
if (conditions.dewpoint != null) request += '&dewptf=' + conditions.dewpoint.f;
if (conditions.windSpeed != null) request += '&windspeedmph=' + conditions.windSpeed.mph;
if (conditions.windGust != null) request += '&windgustmph=' + conditions.windGust.mph;
if (conditions.winddir != null) request += '&winddir=' + conditions.winddir;
if (conditions.pressure != null) request += '&baromin=' + conditions.pressure.inHg;
if (conditions.humidity != null) request += '&humidity=' + conditions.humidity;
if (conditions.precipRate != null) request += '&rainin=' + conditions.precipRate.in;
if (conditions.precipSinceMidnight != null) request += '&dailyrainin=' + conditions.precipSinceMidnight.in;
request += '&softwaretype=appsscriptforwarder' + version;

let response = UrlFetchApp.fetch(request).getContentText();

console.log(response);

return response;

}

// Apps Script has no ability to open a TCP socket directly,
// so we're using https://cwop.rest/ as an intermediary
function updateCWOP_() {
Expand Down

0 comments on commit 374b0e3

Please sign in to comment.