From c3690c5590990005d74ecb082e9d17004a717357 Mon Sep 17 00:00:00 2001 From: Leo <5376265+leoherzog@users.noreply.github.com> Date: Wed, 13 May 2020 14:35:03 -0400 Subject: [PATCH] Fix Bug When Readings are Zero --- code.gs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/code.gs b/code.gs index c69ea67..d7ec647 100644 --- a/code.gs +++ b/code.gs @@ -57,13 +57,13 @@ function updateWindy_() { request += '?stationId=' + windyStationId; request += '&time=' + new Date(station.obsTimeUtc).toISOString(); request += '&tempf=' + station.imperial.temp; - if (station.imperial.windSpeed) request += '&windspeedmph=' + station.imperial.windSpeed; - if (station.imperial.windGust) request += '&windgustmph=' + station.imperial.windGust; - if (station.winddir) request += '&winddir=' + station.winddir; - if (station.imperial.pressure) request += '&baromin=' + station.imperial.pressure; - if (station.imperial.dewpt) request += '&dewptf=' + station.imperial.dewpt; - if (station.humidity) request += '&humidity=' + station.humidity; - if (station.uv) request += '&uv=' + station.uv; + if (station.imperial.windSpeed != null) request += '&windspeedmph=' + station.imperial.windSpeed; + if (station.imperial.windGust != null) request += '&windgustmph=' + station.imperial.windGust; + if (station.winddir != null) request += '&winddir=' + station.winddir; + if (station.imperial.pressure != null) request += '&baromin=' + station.imperial.pressure; + if (station.imperial.dewpt != null) request += '&dewptf=' + station.imperial.dewpt; + if (station.humidity != null) request += '&humidity=' + station.humidity; + if (station.uv != null) request += '&uv=' + station.uv; let response = UrlFetchApp.fetch(request).getContentText(); @@ -84,12 +84,12 @@ function updatePWSWeather_() { request += '&PASSWORD=' + pwsWeatherPassword; request += '&dateutc=' + Utilities.formatDate(new Date(station.obsTimeUtc), 'UTC', 'yyyy-MM-dd hh:mm:ss'); request += '&tempf=' + station.imperial.temp; - if (station.imperial.windSpeed) request += '&windspeedmph=' + station.imperial.windSpeed; - if (station.winddir) request += '&winddir=' + station.winddir; - if (station.imperial.pressure) request += '&baromin=' + station.imperial.pressure; - if (station.imperial.dewpt) request += '&dewptf=' + station.imperial.dewpt; - if (station.humidity) request += '&humidity=' + station.humidity; - if (station.uv) request += '&uv=' + station.uv; + if (station.imperial.windSpeed != null) request += '&windspeedmph=' + station.imperial.windSpeed; + if (station.winddir != null) request += '&winddir=' + station.winddir; + if (station.imperial.pressure != null) request += '&baromin=' + station.imperial.pressure; + if (station.imperial.dewpt != null) request += '&dewptf=' + station.imperial.dewpt; + if (station.humidity != null) request += '&humidity=' + station.humidity; + if (station.uv != null) request += '&uv=' + station.uv; let response = UrlFetchApp.fetch(request).getContentText(); @@ -109,12 +109,12 @@ function updateWeathercloud_() { request += '?wid=' + weathercloudID; request += '&key=' + weathercloudAPIKey; request += '&temp=' + (new Number(station.imperial.temp).fToC() * 10).toFixed(0); - if (station.imperial.windSpeed) request += '&wspd=' + (new Number(station.imperial.windSpeed).mphToMPS() * 10).toFixed(0); - if (station.winddir) request += '&wdir=' + station.winddir; - if (station.imperial.pressure) request += '&baromin=' + (new Number(station.imperial.pressure).inhgTohPa() * 10).toFixed(0); - if (station.humidity) request += '&hum=' + station.humidity; - if (station.imperial.precipRate) request += '&rainrate=' + (new Number(station.imperial.precipRate).inTomm() * 10).toFixed(0); - if (station.uv) request += '&uvi=' + (station.uv * 10); + if (station.imperial.windSpeed != null) request += '&wspd=' + (new Number(station.imperial.windSpeed).mphToMPS() * 10).toFixed(0); + if (station.winddir != null) request += '&wdir=' + station.winddir; + if (station.imperial.pressure != null) request += '&baromin=' + (new Number(station.imperial.pressure).inhgTohPa() * 10).toFixed(0); + if (station.humidity != null) request += '&hum=' + station.humidity; + if (station.imperial.precipRate != null) request += '&rainrate=' + (new Number(station.imperial.precipRate).inTomm() * 10).toFixed(0); + if (station.uv != null) request += '&uvi=' + (station.uv * 10); let response = UrlFetchApp.fetch(request).getContentText(); @@ -160,4 +160,4 @@ function fetchJSON_(url, headers) { Number.prototype.fToC = function() { return (this - 32) * (5 / 9); } Number.prototype.mphToMPS = function() { return this * 0.44704; } Number.prototype.inhgTohPa = function() { return this * 33.863886666667; } -Number.prototype.inTohmm = function() { return this * 25.4; } \ No newline at end of file +Number.prototype.inTohmm = function() { return this * 25.4; }