-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
80 lines (63 loc) · 2.54 KB
/
index.js
File metadata and controls
80 lines (63 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// set your channel id here
var channel_id = 98643;
// set your channel's read api key here if necessary
var api_key = '';
// maximum value for the gauge
var max_gauge_value = 1023;
// name of the gauge
var gauge_name = 'Temp(ºC)';
// global variables
var chart, charts, data;
// load the google gauge visualization
google.load('visualization', '1', {packages:['gauge']});
google.setOnLoadCallback(initChart);
// display the data
function displayData(point) {
data.setValue(0, 0, gauge_name);
data.setValue(0, 1, point);
chart.draw(data, options);
}
// load the data
function loadData() {
// variable for the data point
var p;
// get the data from thingspeak
$.getJSON('https://api.thingspeak.com/channels/' + channel_id + '/feed/last.json?api_key=' + api_key, function(data) {
// get the data point
p = data.field1;
if (data.field1 < 8)
document.getElementById("yeastState").innerHTML = "Brrr, its freeezing in here you blithering fool!";
else if(data.field1 < 12)
document.getElementById("yeastState").innerHTML = "It is a tad bit nippy here!"
else if(data.field1 < 14)
document.getElementById("yeastState").innerHTML = "A little warmer and you'll be brewing a lager";
else if(data.field1 < 18)
document.getElementById("yeastState").innerHTML = "It is lager temp! <3";
else if(data.field1 < 24)
document.getElementById("yeastState").innerHTML = "Wheeee <3 ";
else if(data.field1 < 26)
document.getElementById("yeastState").innerHTML = "Did someone say global warming? :O";
else if(data.field1 < 30)
document.getElementById("yeastState").innerHTML = "Global Warming is real! Nuuuuu :(";
else if(data.field1 > 30)
document.getElementById("yeastState").innerHTML = "I'm a Saison!";
// if there is a data point display it
if (p) {
p = p.substring(0, 4);
//p = Math.round((p / max_gauge_value) * 100);
displayData(p);
}
});
}
// initialize the chart
function initChart() {
data = new google.visualization.DataTable();
data.addColumn('string', 'Label');
data.addColumn('number', 'Value');
data.addRows(1);
chart = new google.visualization.Gauge(document.getElementById('gauge_div'));
options = {width: 500, height: 500, greenFrom:14, greenTo:24 , redFrom: 28, redTo: 35, yellowFrom:24, yellowTo: 28, minorTicks: 5, max:35};
loadData();
// load new data every 15 seconds
setInterval('loadData()', 15000);
}