@@ -9,7 +9,7 @@
|
||||
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
|
||||
<meta http-equiv="pragma" content="no-cache" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
|
||||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
|
||||
<style>
|
||||
body {
|
||||
background-color: white;
|
||||
@@ -140,7 +140,6 @@ var brewtext = "";
|
||||
|
||||
$(document).ready(function(){
|
||||
$('#text').bind("DOMSubtreeModified", resize);
|
||||
fetchdata();
|
||||
updateTime();
|
||||
setInterval(updateTime,1000);
|
||||
formatBrewTime();
|
||||
@@ -151,27 +150,31 @@ $(window).resize(resize);
|
||||
|
||||
var defaultBackoffTime = 1000;
|
||||
var modified = 0;
|
||||
function fetchdata(hxr, status){
|
||||
|
||||
|
||||
|
||||
function fetchdata(data, status){
|
||||
var backoffTime = defaultBackoffTime;
|
||||
modified = 1;
|
||||
if(typeof status !== 'undefined'){
|
||||
if(status == "success"){
|
||||
if (typeof status !== 'undefined'){
|
||||
if (status == "success"){
|
||||
backoffTime = defaultBackoffTime;
|
||||
parseData(hxr.responseText);
|
||||
parseData(data);
|
||||
}
|
||||
else if(status == "error"){
|
||||
else if (status == "error"){
|
||||
backoffTime *= 2;
|
||||
modified = 0
|
||||
setTimeout(fetchdata, backoffTime);
|
||||
handleError();
|
||||
return;
|
||||
}
|
||||
}
|
||||
setTimeout(function() {
|
||||
$.ajax({cache: false, ifModified: modified, url: '/coffee/cups', complete: fetchdata, timeout:120000});
|
||||
}, 2000);
|
||||
}
|
||||
|
||||
$.getJSON("/coffee/cups", fetchdata);
|
||||
setInterval(function() {
|
||||
$.getJSON("/coffee/cups", fetchdata);
|
||||
}, 2000);
|
||||
|
||||
function formatBrewTime(){
|
||||
if(!brewtext && lastBrew instanceof Date){
|
||||
var now = new Date();
|
||||
@@ -189,8 +192,7 @@ function handleError(){
|
||||
setData("?",0,0,Number.MAX_VALUE,Number.MAX_VALUE);
|
||||
}
|
||||
|
||||
function parseData(string) {
|
||||
var data = JSON.parse(string);
|
||||
function parseData(data) {
|
||||
if (data) {
|
||||
var date = new Date(data.date);
|
||||
lastBrew = new Date(data.last_brew);
|
||||
|
||||
@@ -4,6 +4,8 @@ from django.http import JsonResponse
|
||||
import datetime
|
||||
from .mqtt import get_latest
|
||||
|
||||
import coffee_scale.mqtt # somehow this is needed
|
||||
|
||||
|
||||
def get_cups_from_weight(weight):
|
||||
if not weight:
|
||||
@@ -19,6 +21,7 @@ def get_cups_from_weight(weight):
|
||||
if cups > 10:
|
||||
cups = 10
|
||||
|
||||
print("cups: ", cups, "weight: ", weight)
|
||||
return cups
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user