|
18 | 18 | var moment_locale = "$system_locale".substring(0, 2);
|
19 | 19 | moment.locale(moment_locale); // "en" or "de", etc.
|
20 | 20 |
|
| 21 | + ajaxweewx(); // Initial call. Load from weewx (date, daily high, low, etc) |
| 22 | + |
21 | 23 | #if $Extras.has_key("forecast_enabled") and $Extras.forecast_enabled == '1'
|
22 | 24 | // Load forecast
|
23 | 25 | ajaxforecast(); // Initial call. Load forecast data like 8 day outlook, weather icon and observation text
|
|
41 | 43 | #end if
|
42 | 44 |
|
43 | 45 | #if $Extras.has_key("mqtt_enabled") and $Extras.mqtt_enabled == '1'
|
44 |
| - ajaxweewx(); // Initial call. Load from weewx (daily high, low, etc) |
45 | 46 | connect(); // Begin mqtt after weewx initial load
|
46 | 47 | // If the Restart button is clicked, reconnect to mqtt and update weewx and forecast data
|
47 | 48 | jQuery(document).on('click', '.restart-interval', function() {
|
|
194 | 195 | cache:false
|
195 | 196 | });
|
196 | 197 |
|
| 198 | + function ajaxweewx() { |
| 199 | + jQuery.getJSON("$belchertown_root_url/json/weewx_data.json", update_weewx_data); |
| 200 | + }; |
| 201 | + |
| 202 | + // Update weewx data elements |
| 203 | + function update_weewx_data( data ) { |
| 204 | + console.log("Updating weewx data"); |
| 205 | + // Daily High Low |
| 206 | + high = data["day"]["outTemp"]["max"]; |
| 207 | + low = data["day"]["outTemp"]["min"]; |
| 208 | + jQuery(".high").html( high ); |
| 209 | + jQuery(".low").html( low ); |
| 210 | + |
| 211 | + // Barometer trending by finding a negative number |
| 212 | + count = ( data["current"]["barometer_trend"].match(/-/g) || [] ).length |
| 213 | + |
| 214 | + if ( count >= 1 ) { |
| 215 | + jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-down barometer-down"></i>' ); |
| 216 | + } else { |
| 217 | + jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-up barometer-up"></i>' ); |
| 218 | + } |
| 219 | + |
| 220 | + // Current wind gust |
| 221 | + jQuery(".curwindgust").text( parseFloat( data["current"]["windGust"] ).toFixed(1) ); |
| 222 | + |
| 223 | + // Daily max gust span |
| 224 | + jQuery(".dailymaxgust").html( parseFloat( data["day"]["wind"]["max"] ).toFixed(1) ); |
| 225 | + |
| 226 | + // Daily stats section |
| 227 | + jQuery(".snapshot-records-today-header").html( moment.unix( data["current"]["epoch"] ).format( 'dddd, LL' ) ); |
| 228 | + jQuery(".snapshot-records-month-header").html( moment.unix( data["current"]["epoch"] ).format( 'MMMM YYYY' ) ); |
| 229 | + jQuery(".dailystatshigh").html( data["day"]["outTemp"]["max"] ); |
| 230 | + jQuery(".dailystatslow").html( data["day"]["outTemp"]["min"] ); |
| 231 | + jQuery(".dailystatswind").html( data["day"]["wind"]["max"] ); |
| 232 | + jQuery(".dailystatsuv").html( data["day"]["uv"]["max"] ); |
| 233 | + jQuery(".dailystatsrain").html( data["day"]["rain"]["sum"] ); |
| 234 | + jQuery(".dailystatsrainrate").html( data["day"]["rain"]["max"] ); |
| 235 | + |
| 236 | + // Sunrise and Sunset |
| 237 | + jQuery(".sunrise-value").html( data["almanac"]["sunrise"] ); |
| 238 | + jQuery(".sunset-value").html( data["almanac"]["sunset"] ); |
| 239 | + |
| 240 | + // Moon icon, phase and illumination percent |
| 241 | + switch ( data["almanac"]["moon"]["moon_phase"] ) { |
| 242 | + case "New Moon": |
| 243 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-new'></div>" ); |
| 244 | + break; |
| 245 | + case "Waxing Crescent": |
| 246 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-crescent-1'></div>" ); |
| 247 | + break; |
| 248 | + case "First Quarter": |
| 249 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" ); |
| 250 | + break; |
| 251 | + case "Waxing Gibbous": |
| 252 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-gibbous-3'></div>" ); |
| 253 | + break; |
| 254 | + case "Full Moon": |
| 255 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-full'></div>" ); |
| 256 | + break; |
| 257 | + case "Waning Gibbous": |
| 258 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-gibbous-3'></div>" ); |
| 259 | + break; |
| 260 | + case "Last Quarter": |
| 261 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" ); |
| 262 | + break; |
| 263 | + case "Waning Crescent": |
| 264 | + jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-crescent-4'></div>" ); |
| 265 | + break; |
| 266 | + } |
| 267 | + jQuery(".moon-phase").html( titleCase( data["almanac"]["moon"]["moon_phase"] ) ); // Javascript function above |
| 268 | + jQuery(".moon-visible").html( "<strong>" + data["almanac"]["moon"]["moon_fullness"] + "%</strong> visible" ); |
| 269 | + } |
| 270 | + |
197 | 271 | #if $Extras.has_key("forecast_enabled") and $Extras.forecast_enabled == '1'
|
198 | 272 | function ajaxforecast() {
|
199 | 273 | jQuery.getJSON("$forecast_json_url", update_forecast_data);
|
|
332 | 406 | }
|
333 | 407 | }
|
334 | 408 |
|
335 |
| - function ajaxweewx() { |
336 |
| - jQuery.getJSON("$belchertown_root_url/json/weewx_data.json", update_weewx_data); |
337 |
| - }; |
338 |
| - |
339 |
| - // Update weewx data elements |
340 |
| - function update_weewx_data( data ) { |
341 |
| - console.log("Updating weewx data"); |
342 |
| - // Daily High Low |
343 |
| - high = data["day"]["outTemp"]["max"]; |
344 |
| - low = data["day"]["outTemp"]["min"]; |
345 |
| - jQuery(".high").html( high ); |
346 |
| - jQuery(".low").html( low ); |
347 |
| - |
348 |
| - // Barometer trending by finding a negative number |
349 |
| - count = ( data["current"]["barometer_trend"].match(/-/g) || [] ).length |
350 |
| - |
351 |
| - if ( count >= 1 ) { |
352 |
| - jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-down barometer-down"></i>' ); |
353 |
| - } else { |
354 |
| - jQuery(".wx-barometer-trend").html( '<i class="fa fa-arrow-up barometer-up"></i>' ); |
355 |
| - } |
356 |
| - |
357 |
| - // Current wind gust |
358 |
| - jQuery(".curwindgust").text( parseFloat( data["current"]["windGust"] ).toFixed(1) ); |
359 |
| - |
360 |
| - // Daily max gust span |
361 |
| - jQuery(".dailymaxgust").html( parseFloat( data["day"]["wind"]["max"] ).toFixed(1) ); |
362 |
| - |
363 |
| - // Daily stats section |
364 |
| - jQuery(".snapshot-records-today-header").html( moment.unix( data["current"]["epoch"] ).format( 'dddd, MMMM D, YYYY' ) ); // e.g. Tuesday, January 15, 2019 |
365 |
| - jQuery(".snapshot-records-month-header").html( moment.unix( data["current"]["epoch"] ).format( 'MMMM, YYYY' ) ); // e.g. January, 2019 |
366 |
| - jQuery(".dailystatshigh").html( data["day"]["outTemp"]["max"] ); |
367 |
| - jQuery(".dailystatslow").html( data["day"]["outTemp"]["min"] ); |
368 |
| - jQuery(".dailystatswind").html( data["day"]["wind"]["max"] ); |
369 |
| - jQuery(".dailystatsuv").html( data["day"]["uv"]["max"] ); |
370 |
| - jQuery(".dailystatsrain").html( data["day"]["rain"]["sum"] ); |
371 |
| - jQuery(".dailystatsrainrate").html( data["day"]["rain"]["max"] ); |
372 |
| - |
373 |
| - // Sunrise and Sunset |
374 |
| - jQuery(".sunrise-value").html( data["almanac"]["sunrise"] ); |
375 |
| - jQuery(".sunset-value").html( data["almanac"]["sunset"] ); |
376 |
| - |
377 |
| - // Moon icon, phase and illumination percent |
378 |
| - switch ( data["almanac"]["moon"]["moon_phase"] ) { |
379 |
| - case "New Moon": |
380 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-new'></div>" ); |
381 |
| - break; |
382 |
| - case "Waxing Crescent": |
383 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-crescent-1'></div>" ); |
384 |
| - break; |
385 |
| - case "First Quarter": |
386 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" ); |
387 |
| - break; |
388 |
| - case "Waxing Gibbous": |
389 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waxing-gibbous-3'></div>" ); |
390 |
| - break; |
391 |
| - case "Full Moon": |
392 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-full'></div>" ); |
393 |
| - break; |
394 |
| - case "Waning Gibbous": |
395 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-gibbous-3'></div>" ); |
396 |
| - break; |
397 |
| - case "Last Quarter": |
398 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-first-quarter'></div>" ); |
399 |
| - break; |
400 |
| - case "Waning Crescent": |
401 |
| - jQuery(".moon-icon").html( "<div class='wi wi-moon-alt-waning-crescent-4'></div>" ); |
402 |
| - break; |
403 |
| - } |
404 |
| - jQuery(".moon-phase").html( titleCase( data["almanac"]["moon"]["moon_phase"] ) ); // Javascript function above |
405 |
| - jQuery(".moon-visible").html( "<strong>" + data["almanac"]["moon"]["moon_fullness"] + "%</strong> visible" ); |
406 |
| - } |
407 |
| - |
408 | 409 | // mqtt connect
|
409 | 410 | function connect(){
|
410 | 411 | console.log("Connecting to MQTT");
|
|
993 | 994 |
|
994 | 995 | <div class="col-sm-6 stn-quick-stats">
|
995 | 996 | <div class="stats-title">
|
996 |
| - Today, <span class="snapshot-records-today-header">$current.dateTime.format("%A, %B %d, %Y")</span><!-- AJAX --> |
| 997 | + <span class="snapshot-records-today-header"></span><!-- JS and AJAX --> |
997 | 998 | </div>
|
998 | 999 | <table>
|
999 | 1000 | <tr>
|
|
1015 | 1016 | <!-- Quick this month stats -->
|
1016 | 1017 | <div class="col-sm-6 stn-quick-stats border-left">
|
1017 | 1018 | <div class="stats-title">
|
1018 |
| - Month of <span class="snapshot-records-month-header">$current.dateTime.format("%B, %Y")</span><!-- AJAX --> |
| 1019 | + <span class="snapshot-records-month-header">$current.dateTime.format("%B %Y")</span><!-- AJAX --> |
1019 | 1020 | </div>
|
1020 | 1021 | <table>
|
1021 | 1022 | <tr>
|
|
0 commit comments