diff --git a/README.md b/README.md index f36fbbf..e2eff69 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[![Supports](https://img.shields.io/badge/platform-raspberry%20pi-lightgrey.svg?style=plastic)](https://www.raspberrypi.org/) [![Supports](https://img.shields.io/badge/supports-mysql%20or%20sqlite-lightgrey.svg?style=plastic)](https://github.com/1n5aN1aC/rainmeter-pi/blob/master/framework/settings.py) [![License](https://img.shields.io/badge/license-cc--by--sa-green.svg?style=plastic)](http://creativecommons.org/licenses/by-sa/4.0/) +[![Supports](https://img.shields.io/badge/platform-raspberry%20pi-lightgrey.svg?style=plastic)](https://www.raspberrypi.org/) [![Supports](https://img.shields.io/badge/supports-mysql%20or%20sqlite-lightgrey.svg?style=plastic)](https://github.com/1n5aN1aC/rainmeter-pi/blob/master/framework/settings.py#L29) [![License](https://img.shields.io/badge/license-cc--by--sa-green.svg?style=plastic)](http://creativecommons.org/licenses/by-sa/4.0/) # Rainmeter-pi Raspberry-pi powered Weather Station diff --git a/framework/http_reset_rain.py b/framework/http_reset_rain.py index f9ca3fc..31fcd85 100644 --- a/framework/http_reset_rain.py +++ b/framework/http_reset_rain.py @@ -10,6 +10,8 @@ def reset_rain(): now = Table_Now.get(1) now.sync() now.Out_Rain_Since_Reset = 0 + + return "reset!" # If file ran directly, reset the rain as well. # We use this to be able to support wsgi OR straight python. @@ -18,7 +20,5 @@ def reset_rain(): print "Content-Type: text/html;charset=utf-8" print - reset_rain() - # Print the Data - print "reset!" \ No newline at end of file + print reset_rain() \ No newline at end of file diff --git a/framework/http_reset_rain.wsgi b/framework/http_reset_rain.wsgi new file mode 100644 index 0000000..62baef0 --- /dev/null +++ b/framework/http_reset_rain.wsgi @@ -0,0 +1,16 @@ +#!python +from http_reset_rain import * + +# +# This is requested by the index page every time it needs to update the data. +# It will Return all the current weather data in a json-file, formated for web-display. +# That means this is called very often, and should be reletively effecient +def application(environ, start_response): + status = '200 OK' + output = reset_rain() + + response_headers = [('Content-type', 'application/json;charset=utf-8'), + ('Content-Length', str(len(output)))] + start_response(status, response_headers) + + return [output] \ No newline at end of file diff --git a/js/value_refresher.js b/js/value_refresher.js index 58bc0be..da99c41 100644 --- a/js/value_refresher.js +++ b/js/value_refresher.js @@ -5,7 +5,11 @@ // This requests the current data via local json request. // It then makes a callback to update() to handle the data. function getTheJSON() { - jQuery.getJSON("/status", function(data) { update(data); } ) + url = "/framework/http_status.py" + if (window.wsgi == true) { + url = "/status" + } + jQuery.getJSON(url, function(data) { update(data); } ) } // update() handles actually updating the vales on the page from the json results @@ -61,12 +65,32 @@ function update(data) { // Handles when the user clicks the button to reset the rainfall. function reset_rain() { + url = "/framework/http_reset_rain.py" + if (window.wsgi == true) { + url = "/reset_rain" + } $.ajax({ - url: "/framework/http_reset_rain.py", + url: url, + }); +} + +// If the server responds to /status, we know wgsi is supported. +function check_wsgi() { + $.ajax({ + type: "HEAD", + url: "/status", + success: function() { + window.wsgi = true; + }, + error: function() { + window.wsgi = false; + } }); } document.addEventListener("DOMContentLoaded", function(event) { + //Check if the webserver is set up to support wsgi (much faster) + check_wsgi() //Update it now! getTheJSON() // Set up a permanent call to getTheJSON() every X seconds.