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